E2BE2B SDK 2.50 · Code Interpreter 2.10 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
10 small wins to finish your pathNext lesson

Installation and setup

Sandbox.create starts a sandbox in E2B's cloud. It needs E2B_API_KEY, and without one the SDK stops before sending any request.

pip install e2b-code-interpreter 2.10.0

The code interpreter package brings the core e2b SDK with it.

pip install "e2b-code-interpreter==2.10.0" pytest

Sandboxes run on E2B's servers, so starting one needs E2B_API_KEY, created under e2b.dev/dashboard?tab=keys. The course checks every call without starting a sandbox, and you can follow it without an account.

The SDK's key check

Example
from e2b_code_interpreter import Sandbox

sandbox = Sandbox.create()

AuthenticationException comes from the SDK's own check: no key in the environment and none passed as api_key. The message says where to get one. With a key, the same line creates a sandbox from the default template.

Example.env
E2B_API_KEY=e2b_...
Examplefirst_sandbox.py, with a key
from e2b_code_interpreter import Sandbox

with Sandbox.create() as sandbox:
    execution = sandbox.run_code("print('hello from the sandbox')")
    print(execution.logs.stdout)

with kills the sandbox when the block ends, even after an exception, so you do not pay for an idle machine. run_code sends the code and waits for it to finish; lesson 3 opens up what comes back.

Keys are for your server
An E2B key can start machines billed to your account. Keep it in the server's environment, never in a browser app or in the sandbox's own environment variables.
Try it yourself
  • Pass api_key="e2b_test" to Sandbox.create without a network connection and read the error.
  • Find AuthenticationException in e2b/exceptions.py.
  • Import AsyncSandbox from e2b_code_interpreter and print its create signature.
PreviousE2B overview

Little by little, you're building something great.