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

  1. Install the SDK in the active environment: pip install e2b-code-interpreter
  2. Create a .env file with your E2B_API_KEY (e.g. E2B_API_KEY=...) in the working directory of the run
  3. Verify with `python -c "import e2b_code_interpreter"` in the same interpreter that runs the training script
  4. 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

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


AI-assisted analysis of huggingface/open-r1@1416fa0cf2 (2026-08-30). Data as JSON: /api/errors/5dbaed60f183f554. Report an issue: GitHub.