E2B Code Interpreter
raw JSON → 2.4.1 verified Mon May 11 auth: yes python install: verified quickstart: stale
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-interpreter Common errors
error ImportError: cannot import name 'CodeInterpreter' from 'e2b_code_interpreter' ↓
cause The `CodeInterpreter` class has been deprecated or removed in recent versions of the `e2b-code-interpreter` SDK, with `Sandbox` becoming the primary entry point for code execution.
fix
Replace
from e2b_code_interpreter import CodeInterpreter with from e2b_code_interpreter import Sandbox and use Sandbox.create() to initialize the sandbox. error ImportError: Unable to import e2b, please install with `pip install e2b`. ↓
cause This error occurs when a component of your application (often an older dependency or an integration with another library) expects the core `e2b` package to be installed, but it's either missing or a newer project primarily uses `e2b-code-interpreter` without explicitly installing `e2b`.
fix
Ensure both the core
e2b package and the e2b-code-interpreter package are installed by running pip install e2b e2b-code-interpreter. error AuthenticationError: Unauthorized, please check your credentials. - Invalid API key ↓
cause The E2B SDK could not authenticate due to a missing, incorrect, or expired API key. The API key must be provided either as an environment variable or directly in the code.
fix
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'). error Peer closed connection without sending complete message body ↓
cause This error indicates an unexpected termination of the connection between your application and the E2B sandbox. It can be caused by internal sandbox issues, such as a process crashing, resource exhaustion, or problems during library installation within the sandbox environment.
fix
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.
error {"sandboxId":"...","message":"The sandbox is running but port is not open","port":49999,"code":502} ↓
cause This error typically occurs when using custom sandbox templates where the default start command for the code interpreter is not correctly specified, or a non-code-interpreter base image is used without the necessary setup. It can also signify a sandbox timeout.
fix
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. Warnings
breaking CodeInterpreter class removed in v1.0. All v0.x code using CodeInterpreter() or from e2b_code_interpreter import CodeInterpreter fails with ImportError. ↓
fix Replace CodeInterpreter() with Sandbox(). Use context manager: with Sandbox() as sandbox:
breaking Global cwd option removed from Sandbox constructor in v1.0. Setting cwd at sandbox creation no longer works. ↓
fix Pass cwd per command call instead of at sandbox instantiation.
breaking Sandbox.list() output structure changed in v1.0. Code parsing the old list format breaks silently or raises KeyError. ↓
fix Review and rewrite any code consuming Sandbox.list() output against v1.x docs.
deprecated e2b package (core SDK) v0.x is fully deprecated. All PyPI releases below 1.0 display deprecation warnings at import time. ↓
fix pip install e2b-code-interpreter>=1.0.0 and follow migration guide at e2b.dev/docs/quickstart/migrating-from-v0
gotcha Sandboxes are billed by runtime duration, not by number of calls. Long-running agents with persistent sandboxes accumulate cost even when idle. ↓
fix Use context managers (with Sandbox() as sb:) to ensure sandboxes are closed after use. Explicitly call sandbox.close() in non-context-manager usage.
gotcha execution.text is None if the code produces no output. Accessing .text without checking causes NoneType errors downstream. ↓
fix Check execution.text is not None before use. Also check execution.error for runtime errors in executed code.
Install
pip install e2b npm install @e2b/code-interpreter Install compatibility verified last tested: 2026-05-11
python os / libc variant status wheel install import disk
3.10 alpine (musl) e2b - - - -
3.10 alpine (musl) e2b-code-interpreter - - 4.63s 41.7M
3.10 slim (glibc) e2b - - - -
3.10 slim (glibc) e2b-code-interpreter - - 6.08s 43M
3.11 alpine (musl) e2b - - - -
3.11 alpine (musl) e2b-code-interpreter - - 5.57s 46.5M
3.11 slim (glibc) e2b - - - -
3.11 slim (glibc) e2b-code-interpreter - - 5.00s 47M
3.12 alpine (musl) e2b - - - -
3.12 alpine (musl) e2b-code-interpreter - - 5.63s 37.8M
3.12 slim (glibc) e2b - - - -
3.12 slim (glibc) e2b-code-interpreter - - 5.89s 39M
3.13 alpine (musl) e2b - - - -
3.13 alpine (musl) e2b-code-interpreter - - 5.75s 37.5M
3.13 slim (glibc) e2b - - - -
3.13 slim (glibc) e2b-code-interpreter - - 5.30s 38M
3.9 alpine (musl) e2b - - - -
3.9 alpine (musl) e2b-code-interpreter - - 1.80s 39.8M
3.9 slim (glibc) e2b - - - -
3.9 slim (glibc) e2b-code-interpreter - - 2.54s 41M
Imports
- Sandbox wrong
from e2b_code_interpreter import CodeInterpretercorrectfrom e2b_code_interpreter import Sandbox - Sandbox (core) wrong
from e2b_code_interpreter import Sandboxcorrectfrom e2b import Sandbox
Quickstart stale last tested: 2026-05-11
from e2b_code_interpreter import Sandbox
with Sandbox() as sandbox:
sandbox.run_code("x = 1")
execution = sandbox.run_code("x += 1; x")
print(execution.text) # outputs 2