Overview

Run your first sandbox

1
Create an E2B account

Every new E2B account gets $100 in credits. Sign up here.

2
Set your API key

Open the E2B Console, copy your API key and put it in a .env file:

E2B_API_KEY=e2b_***
3
Install the SDK

Install the Code Interpreter SDK — it includes everything from the base e2b SDK plus runCode().

4
Write the code

Create a sandbox, run Python in it, list files.

5
Run it

npx tsx ./index.ts for JavaScript, python main.py for Python.

Install#

npm i @e2b/code-interpreter dotenv
pip install e2b-code-interpreter python-dotenv

Start the sandbox#

// index.ts
import 'dotenv/config'
import { Sandbox } from '@e2b/code-interpreter'
 
const sbx = await Sandbox.create() // Creates a persistent sandbox session
const execution = await sbx.runCode('print("hello world")') // Execute Python inside the sandbox
console.log(execution.logs)
 
const files = await sbx.files.list('/')
console.log(files)
# main.py
from dotenv import load_dotenv
load_dotenv()
from e2b_code_interpreter import Sandbox
 
sbx = Sandbox.create() # Creates a persistent sandbox session
execution = sbx.run_code("print('hello world')") # Execute Python inside the sandbox
print(execution.logs)
 
files = sbx.files.list("/")
print(files)

Only need a shell?#

If your agent runs terminal commands rather than notebook-style code, the base SDK is enough — npm i e2b or pip install e2b — and sandbox.commands.run() replaces runCode(). See Run commands.

Next#

Updated

Was this page helpful?