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" pytestSandboxes 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
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.
E2B_API_KEY=e2b_...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.
- Pass
api_key="e2b_test"toSandbox.createwithout a network connection and read the error. - Find
AuthenticationExceptionine2b/exceptions.py. - Import
AsyncSandboxfrome2b_code_interpreterand print itscreatesignature.
Little by little, you're building something great.