Secure cloud sandboxes for executing AI-generated code. Two packages: e2b-code-interpreter (Jupyter/stateful code execution) and e2b (core sandbox SDK). v0.x is fully deprecated — all versions below 1.0 show deprecation warnings and the API is incompatible with v1.x.
pip install e2b-code-interpreterVerified import paths — ran on the pinned version, not inferred.
Stateful code execution in a secure cloud sandbox. Requires E2B_API_KEY environment variable.
Replace CodeInterpreter() with Sandbox(). Use context manager: with Sandbox() as sandbox:
Pass cwd per command call instead of at sandbox instantiation.
Review and rewrite any code consuming Sandbox.list() output against v1.x docs.
pip install e2b-code-interpreter>=1.0.0 and follow migration guide at e2b.dev/docs/quickstart/migrating-from-v0
Use context managers (with Sandbox() as sb:) to ensure sandboxes are closed after use. Explicitly call sandbox.close() in non-context-manager usage.
Check execution.text is not None before use. Also check execution.error for runtime errors in executed code.
Replace `from e2b_code_interpreter import CodeInterpreter` with `from e2b_code_interpreter import Sandbox` and use `Sandbox.create()` to initialize the sandbox.
Ensure both the core `e2b` package and the `e2b-code-interpreter` package are installed by running `pip install e2b e2b-code-interpreter`.
Obtain a valid E2B API key from e2b.dev and set it as an environment variable named `E2B_API_KEY` (e.g., `export E2B_API_KEY=e2b_YOUR_KEY`). Alternatively, pass it directly when creating the sandbox, like `Sandbox.create(api_key='e2b_YOUR_KEY')`.
Check the E2B sandbox logs for more specific internal errors. If the issue occurs during package installation (e.g., Pandas), ensure your custom template or Dockerfile is correctly configured and that the sandbox has sufficient resources. If the problem persists with standard templates, contact E2B support.
When creating custom templates, ensure you inherit from `code-interpreter-v1` or, if building from a Docker image, explicitly set the start command: `.setStartCmd('sudo /root/.jupyter/start-up.sh')` with `e2bdev/code-interpreter:latest` as the base image. Additionally, consider increasing the sandbox's timeout parameter.