{"record":{"id":"5dbaed60f183f554","repo":"huggingface/open-r1","slug":"e2b-is-not-available-and-required-for-this-provide","errorCode":null,"errorMessage":"E2B is not available and required for this provider. Please install E2B with `pip install e2b-code-interpreter` and add an API key to a `.env` file.","messagePattern":"E2B is not available and required for this provider\\. Please install E2B with `pip install e2b-code-interpreter` and add an API key to a `\\.env` file\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/open_r1/utils/code_providers.py","lineNumber":74,"sourceCode":"\n        Returns:\n            List of float rewards (one per script)\n        \"\"\"\n        pass\n\n\nclass E2BProvider(CodeExecutionProvider):\n    \"\"\"Provider that executes code using E2B sandboxes.\"\"\"\n\n    def __init__(self, num_parallel: int = 2, e2b_router_url: Optional[str] = None):\n        \"\"\"Initialize the E2B provider.\n\n        Args:\n            num_parallel: Number of parallel sandboxes to use\n            e2b_router_url: URL for the E2B router (if using router mode)\n        \"\"\"\n        if not is_e2b_available():\n            raise ImportError(\n                \"E2B is not available and required for this provider. Please install E2B with \"\n                \"`pip install e2b-code-interpreter` and add an API key to a `.env` file.\"\n            )\n\n        self.num_parallel = num_parallel\n        self.e2b_router_url = e2b_router_url\n\n    def execute_scripts(self, scripts: List[str], languages: List[str]) -> List[float]:\n        \"\"\"Execute scripts using E2B sandboxes.\n\n        If e2b_router_url is provided, uses the RoutedSandbox for batch processing.\n        Otherwise, uses direct AsyncSandbox with parallelization.\n        \"\"\"\n        if self.e2b_router_url is not None:\n            routed_sandbox = RoutedSandbox(router_url=self.e2b_router_url)\n\n            executions = routed_sandbox.run_code(\n                scripts=scripts,","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/huggingface/open-r1/blob/1416fa0cf21595d2083b399a2a0bbddd7f6e9563/src/open_r1/utils/code_providers.py#L56-L92","documentation":"E2BProvider's __init__ raises ImportError when the e2b-code-interpreter package is not importable in the environment. The provider cannot create remote code-execution sandboxes without the E2B SDK, so it fails fast at construction time instead of later at reward-computation time. Fixing it requires both installing the package and providing API credentials in a .env file.","triggerScenarios":"Instantiating E2BProvider (via get_provider with an e2b provider_type or directly) while is_e2b_available() returns False, i.e. `import e2b_code_interpreter` fails in the current Python environment.","commonSituations":"Running a SLURM/HF Trainer job in a fresh venv or container where optional code-execution deps were never installed; switching to a provider-based code reward without installing the e2b extra; the package installed in a different interpreter than the one launching the job.","solutions":["Install the SDK in the active environment: pip install e2b-code-interpreter","Create a .env file with your E2B_API_KEY (e.g. E2B_API_KEY=...) in the working directory of the run","Verify with `python -c \"import e2b_code_interpreter\"` in the same interpreter that runs the training script","If you don't need the e2b provider, select a different provider_type in get_provider"],"exampleFix":"// before\nprovider = get_provider(code_provider=\"e2b\")  # ImportError\n// after\n# shell: pip install e2b-code-interpreter && echo 'E2B_API_KEY=...' >> .env\nprovider = get_provider(code_provider=\"e2b\")","handlingStrategy":"validation","validationCode":"def require_e2b():\n    try:\n        import e2b_code_interpreter  # noqa: F401\n    except ImportError as e:\n        raise SystemExit(\"Install e2b: pip install e2b-code-interpreter\") from e\n    import os\n    if not (os.getenv(\"E2B_API_KEY\") or _dotenv_has(\"E2B_API_KEY\")):\n        raise SystemExit(\"Set E2B_API_KEY in your .env\")\n\ndef _dotenv_has(key):\n    try:\n        with open(\".env\") as f:\n            return any(line.startswith(key + \"=\") for line in f)\n    except FileNotFoundError:\n        return False","typeGuard":"def is_e2b_ready() -> bool:\n    try:\n        import e2b_code_interpreter  # noqa: F401\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    provider = E2BProvider(num_parallel=4)\nexcept ImportError as e:\n    logger.error(\"E2B missing: %s — run pip install e2b-code-interpreter\", e)\n    raise SystemExit(1) from e","preventionTips":["Pin optional sandbox deps in an extras group (e.g. requirements-sandbox.txt) and install it in training images","Smoke-test `import e2b_code_interpreter` in CI before launching long training jobs","Keep the .env with E2B_API_KEY next to the launch script and document it in the README","Check for the package at job startup, not at reward time"],"tags":["python","missing-dependency","import-error","sandbox"],"backgroundTag":"missing-optional-dependency","analyzedSha":"1416fa0cf21595d2083b399a2a0bbddd7f6e9563","analyzedAt":"2026-08-30T08:56:53.400Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}