crewAIInc/crewAI · error · ImportError
The 'e2b' package is required for E2B sandbox tools. Install
Error message
The 'e2b' package is required for E2B sandbox tools. Install it with: uv add e2b (or) pip install e2b
What it means
E2B sandbox tools resolve their SDK class lazily via _import_sandbox_class; the first call imports e2b.Sandbox and on ImportError raises a guidance message telling you to install the e2b package. A module-level cache (_sdk_cache) means the import is attempted once per class, after which either the class is reused or the error is re-raised on every call. This fires only when e2b is missing from the environment — not on API or network problems.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/e2b_sandbox_tool/e2b_base_tool.py:120
_lock: threading.Lock = PrivateAttr(default_factory=threading.Lock)
_cleanup_registered: bool = PrivateAttr(default=False)
_sdk_cache: ClassVar[dict[str, Any]] = {}
@classmethod
def _import_sandbox_class(cls) -> Any:
"""Return the Sandbox class used by this tool.
Subclasses override this to swap in a different SDK (e.g. the code
interpreter sandbox). The default uses plain `e2b.Sandbox`.
"""
cached = cls._sdk_cache.get("e2b.Sandbox")
if cached is not None:
return cached
try:
from e2b import Sandbox # type: ignore[import-untyped]
except ImportError as exc:
raise ImportError(
"The 'e2b' package is required for E2B sandbox tools. "
"Install it with: uv add e2b (or) pip install e2b"
) from exc
cls._sdk_cache["e2b.Sandbox"] = Sandbox
return Sandbox
def _connect_kwargs(self) -> dict[str, Any]:
kwargs: dict[str, Any] = {}
if self.api_key is not None:
kwargs["api_key"] = self.api_key.get_secret_value()
if self.domain:
kwargs["domain"] = self.domain
if self.sandbox_timeout is not None:
kwargs["timeout"] = self.sandbox_timeout
return kwargs
def _create_kwargs(self) -> dict[str, Any]:
kwargs: dict[str, Any] = self._connect_kwargs()View on GitHub (pinned to 754d7323be)
Solutions
- Install the SDK: pip install e2b (or uv add e2b), matching the message.
- Confirm it landed in the running interpreter: python -c "import e2b; print(e2b.__version__)" using the same python that runs your app.
- Add e2b (or crewai-tools[e2b] if provided) to your lockfile/requirements so deployments keep it.
- If using a code-interpreter variant, make sure the right e2b extra (e.g. e2b-code-interpreter) is installed per the subclass docs.
Example fix
# before pip install crewai-tools E2BSandboxTool(...) # ImportError: 'e2b' package required # after pip install crewai-tools e2b E2BSandboxTool(...) # SDK class resolves and caches
Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
if importlib.util.find_spec('e2b') is None:
raise ImportError("The 'e2b' package is required for E2B sandbox tools. Install it with: pip install e2b")
sandbox_tool = E2BSandboxTool(...) Type guard
def e2b_available() -> bool:
return importlib.util.find_spec('e2b') is not None Try / catch
try:
result = tool._run(code=src)
except ImportError as e:
if "'e2b' package is required" in str(e):
raise DeploymentError('e2b missing in runtime image — add it to requirements') from e
raise Prevention
- Add e2b to requirements.txt/pyproject and rebuild deployment images.
- Run a startup capability check (find_spec) and report missing optional deps clearly.
- Verify with the same interpreter that runs the app: python -c 'import e2b'.
When it happens
Trigger: Instantiating/first-running any E2B sandbox tool (E2BSandboxTool and subclasses) in an environment where pip show e2b fails; crewai-tools installed without the e2b extra; a venv mismatch where the tool runs under a different interpreter than the one where e2b was installed.
Common situations: Fresh clones that installed crewai-tools core only; deploying to containers that prune 'dev' dependencies; multiple virtualenvs or system/pip confusion so e2b exists for one interpreter but not the runtime one.
Related errors
- The 'daytona' package is required for Daytona sandbox tools.
- Could not import daytona.CodeRunParams while building argv/e
- The 'e2b_code_interpreter' package is required for the E2B P
- `scrapfly-sdk` package not found, please run `uv add scrapfl
- `selenium` and `webdriver-manager` package not found, please
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/96a5a97a2403f32e.
Report an issue: GitHub.