huggingface/open-r1 · error
E2B is not available and required for this provider. Please
Error message
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.
What it means
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.
Source
Thrown at src/open_r1/utils/code_providers.py:74
Returns:
List of float rewards (one per script)
"""
pass
class E2BProvider(CodeExecutionProvider):
"""Provider that executes code using E2B sandboxes."""
def __init__(self, num_parallel: int = 2, e2b_router_url: Optional[str] = None):
"""Initialize the E2B provider.
Args:
num_parallel: Number of parallel sandboxes to use
e2b_router_url: URL for the E2B router (if using router mode)
"""
if not is_e2b_available():
raise ImportError(
"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."
)
self.num_parallel = num_parallel
self.e2b_router_url = e2b_router_url
def execute_scripts(self, scripts: List[str], languages: List[str]) -> List[float]:
"""Execute scripts using E2B sandboxes.
If e2b_router_url is provided, uses the RoutedSandbox for batch processing.
Otherwise, uses direct AsyncSandbox with parallelization.
"""
if self.e2b_router_url is not None:
routed_sandbox = RoutedSandbox(router_url=self.e2b_router_url)
executions = routed_sandbox.run_code(
scripts=scripts,View on GitHub (pinned to 1416fa0cf2)
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
Example fix
// before provider = get_provider(code_provider="e2b") # ImportError // after # shell: pip install e2b-code-interpreter && echo 'E2B_API_KEY=...' >> .env provider = get_provider(code_provider="e2b")
Defensive patterns
Strategy: validation
Validate before calling
def require_e2b():
try:
import e2b_code_interpreter # noqa: F401
except ImportError as e:
raise SystemExit("Install e2b: pip install e2b-code-interpreter") from e
import os
if not (os.getenv("E2B_API_KEY") or _dotenv_has("E2B_API_KEY")):
raise SystemExit("Set E2B_API_KEY in your .env")
def _dotenv_has(key):
try:
with open(".env") as f:
return any(line.startswith(key + "=") for line in f)
except FileNotFoundError:
return False Type guard
def is_e2b_ready() -> bool:
try:
import e2b_code_interpreter # noqa: F401
return True
except ImportError:
return False Try / catch
try:
provider = E2BProvider(num_parallel=4)
except ImportError as e:
logger.error("E2B missing: %s — run pip install e2b-code-interpreter", e)
raise SystemExit(1) from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- MorphCloud is not available and required for this provider.
- Required MorphCloud dependencies not installed: {e}
- Either `dataset_name` or `dataset_mixture` must be provided
- dataset_mixture must be a dictionary with a 'datasets' key.
- 'datasets' must be a list of dataset configurations
AI-assisted analysis of huggingface/open-r1@1416fa0cf2 (2026-08-30).
Data as JSON: /api/errors/5dbaed60f183f554.
Report an issue: GitHub.