Registry / devops / e2b-code-interpreter

e2b-code-interpreter

JSON →
library2.9.2pypypi✓ verified 31d ago

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
INSTALL
IMPORT
SIG · E2B-CODE-INTERPRET
E
e2b-code-interpreter
devopspythonv2.9.2
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.9.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
10/12 runs
10/12 runs
py 3.11
10/12 runs
10/12 runs
py 3.12
10/12 runs
10/12 runs
py 3.13
10/12 runs
10/12 runs
py 3.9
10/12 runs
10/12 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Sandbox
✓ from e2b_code_interpreter import Sandbox
✗ from e2b_code_interpreter import CodeInterpreter
CodeInterpreter class was the v0.x entry point. Removed in v1.0. All v0.x code using CodeInterpreter() breaks.
Sandbox (core)
✓ from e2b import Sandbox
✗ from e2b_code_interpreter import Sandbox
Use e2b.Sandbox for general-purpose sandboxes without Jupyter kernel. Use e2b_code_interpreter.Sandbox for stateful code execution with output capture.

Stateful code execution in a secure cloud sandbox. Requires E2B_API_KEY environment variable.

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
e2b --version
Debug
Known issues
breakingCodeInterpreter 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:
affects: < 1.0.0
breakingGlobal 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.
affects: < 1.0.0
breakingSandbox.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.
affects: < 1.0.0
deprecatede2b 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
affects: e2b < 1.0.0
gotchaSandboxes 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.
affects: all
gotchaexecution.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.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'CodeInterpreter' from 'e2b_code_interpreter'
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.
ImportError: Unable to import e2b, please install with `pip install e2b`.
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`.
AuthenticationError: Unauthorized, please check your credentials. - Invalid API key
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')`.
Peer closed connection without sending complete message body
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.
{"sandboxId":"...","message":"The sandbox is running but port is not open","port":49999,"code":502}
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.
Upgrade
Version history
2.9.2latest on PyPI · released Aug 26, 2026
Audit
Dependencies
e2brequiredCore sandbox SDK. e2b-code-interpreter depends on it.
httpxrequiredHTTP client used internally by the SDK.
Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources
e2b-code-interpreter — pip install e2b-code-interpreter · libregistry