{"record":{"id":"bb64b0fa6b035066","repo":"crewAIInc/crewAI","slug":"the-e2b-code-interpreter-package-is-required-for","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/e2b_sandbox_tool/e2b_python_tool.py","lineNumber":64,"sourceCode":"        \"quick scripts, or analysis that should run in an isolated environment.\"\n    )\n    args_schema: type_[BaseModel] = E2BPythonToolSchema\n\n    package_dependencies: list[str] = Field(\n        default_factory=lambda: [\"e2b_code_interpreter\"],\n    )\n\n    _ci_cache: ClassVar[dict[str, Any]] = {}\n\n    @classmethod\n    def _import_sandbox_class(cls) -> Any:\n        cached = cls._ci_cache.get(\"Sandbox\")\n        if cached is not None:\n            return cached\n        try:\n            from e2b_code_interpreter import Sandbox  # type: ignore[import-untyped]\n        except ImportError as exc:\n            raise ImportError(\n                \"The 'e2b_code_interpreter' package is required for the E2B \"\n                \"Python tool. Install it with: \"\n                \"uv add e2b-code-interpreter  (or) \"\n                \"pip install e2b-code-interpreter\"\n            ) from exc\n        cls._ci_cache[\"Sandbox\"] = Sandbox\n        return Sandbox\n\n    def _run(\n        self,\n        code: str,\n        language: str | None = None,\n        envs: dict[str, str] | None = None,\n        timeout: float | None = None,\n    ) -> Any:\n        sandbox, should_kill = self._acquire_sandbox()\n        try:\n            run_kwargs: dict[str, Any] = {}","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/e2b_sandbox_tool/e2b_python_tool.py#L46-L82","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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\"."],"exampleFix":"# before (ImportError at tool init)\ntool = E2BPythonTool()\n\n# after\n# uv add e2b-code-interpreter\ntool = E2BPythonTool()","handlingStrategy":"try-catch","validationCode":"def e2b_interpreter_available() -> bool:\n    try:\n        import e2b_code_interpreter  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif not e2b_interpreter_available():\n    raise SystemExit('Install first: uv add e2b-code-interpreter')","typeGuard":null,"tryCatchPattern":"try:\n    tool = E2BPythonTool()\nexcept ImportError as e:\n    if 'e2b-code-interpreter' in str(e):\n        subprocess.run([sys.executable, '-m', 'pip', 'install', 'e2b-code-interpreter'], check=True)\n        tool = E2BPythonTool()\n    else:\n        raise","preventionTips":["Declare e2b-code-interpreter in pyproject/requirements alongside crewai-tools.","Fail fast at startup with an availability probe before building the crew."],"tags":["e2b","import-error","dependency","optional-deps"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}