crewAIInc/crewAI · error · ImportError
The 'e2b_code_interpreter' package is required for the E2B P
Error message
The 'e2b_code_interpreter' package is required for the E2B Python tool. Install it with: uv add e2b-code-interpreter (or) pip install e2b-code-interpreter
What it means
Raised by E2BPythonTool._import_sandbox_class when the optional 'e2b_code_interpreter' dependency is not installed. The tool lazily imports Sandbox from e2b_code_interpreter (with a class-level cache) and converts the ImportError into an actionable message with the exact install command. The original ImportError is chained as the cause.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/e2b_sandbox_tool/e2b_python_tool.py:64
"quick scripts, or analysis that should run in an isolated environment."
)
args_schema: type_[BaseModel] = E2BPythonToolSchema
package_dependencies: list[str] = Field(
default_factory=lambda: ["e2b_code_interpreter"],
)
_ci_cache: ClassVar[dict[str, Any]] = {}
@classmethod
def _import_sandbox_class(cls) -> Any:
cached = cls._ci_cache.get("Sandbox")
if cached is not None:
return cached
try:
from e2b_code_interpreter import Sandbox # type: ignore[import-untyped]
except ImportError as exc:
raise ImportError(
"The 'e2b_code_interpreter' package is required for the E2B "
"Python tool. Install it with: "
"uv add e2b-code-interpreter (or) "
"pip install e2b-code-interpreter"
) from exc
cls._ci_cache["Sandbox"] = Sandbox
return Sandbox
def _run(
self,
code: str,
language: str | None = None,
envs: dict[str, str] | None = None,
timeout: float | None = None,
) -> Any:
sandbox, should_kill = self._acquire_sandbox()
try:
run_kwargs: dict[str, Any] = {}View on GitHub (pinned to 754d7323be)
Solutions
- Run: uv add e2b-code-interpreter (or pip install e2b-code-interpreter).
- If using requirements/pyproject, add e2b-code-interpreter as a dependency so CI and teammates get it.
- Verify with: python -c "from e2b_code_interpreter import Sandbox".
Example fix
# before (ImportError at tool init) tool = E2BPythonTool() # after # uv add e2b-code-interpreter tool = E2BPythonTool()
Defensive patterns
Strategy: try-catch
Validate before calling
def e2b_interpreter_available() -> bool:
try:
import e2b_code_interpreter # noqa: F401
return True
except ImportError:
return False
if not e2b_interpreter_available():
raise SystemExit('Install first: uv add e2b-code-interpreter') Try / catch
try:
tool = E2BPythonTool()
except ImportError as e:
if 'e2b-code-interpreter' in str(e):
subprocess.run([sys.executable, '-m', 'pip', 'install', 'e2b-code-interpreter'], check=True)
tool = E2BPythonTool()
else:
raise Prevention
- Declare e2b-code-interpreter in pyproject/requirements alongside crewai-tools.
- Fail fast at startup with an availability probe before building the crew.
When it happens
Trigger: Instantiating or running E2BPythonTool in an environment where 'e2b-code-interpreter' is not installed; the import fails on first use (after that the class is cached, so the error only fires once per process).
Common situations: Installing crewai-tools without its e2b extras; a fresh virtualenv/uv project; CI environments that only install core dependencies; version upgrades that dropped the package from a lockfile.
Related errors
- You are missing the 'exa_py' package. Please install it to u
- `firecrawl-py` package not found, please run `uv add firecra
- `firecrawl-py` package not found, please run `uv add firecra
- `firecrawl-py` package not found, please run `uv add firecra
- `hyperbrowser` package not found, please run `pip install hy
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/bb64b0fa6b035066.
Report an issue: GitHub.