E2B Documentation

Open-source, secure environment with real-world tools for enterprise-grade agents.

13,186 stars Python Python 1 file ยท ~2,678 tokens #agent#ai#ai-agent#ai-agents#code-interpreter#copilot#development#devtools
RAW Doc

Docker & Self-Hosted Deployment Verified OCI

Deploy E2B on any server, homelab, or cloud container platform.

1-Click Terminal Command
bash (docker run)
docker run -d --name e2b --restart always e2b-dev/e2b:latest

File: README.md

What is E2B?

E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.

Run your first Sandbox

1. Install SDK

JavaScript / TypeScript

text
npm i e2b

Python

text
pip install e2b

2. Get your E2B API key

  1. Sign up to E2B here.
  2. Get your API key here.
  3. Set environment variable with your API key
text
E2B_API_KEY=e2b_***

3. Start a sandbox and run commands

JavaScript / TypeScript

ts
import Sandbox from 'e2b'

const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('echo "Hello from E2B!"')
console.log(result.stdout) // Hello from E2B!

Python

py
from e2b import Sandbox

with Sandbox.create() as sandbox:
    result = sandbox.commands.run('echo "Hello from E2B!"')
    print(result.stdout)  # Hello from E2B!

4. Code execution with Code Interpreter

If you need to execute code with runCode()/run_code(), install the Code Interpreter SDK (JavaScript / Python):

text
npm i @e2b/code-interpreter  # JavaScript/TypeScript
pip install e2b-code-interpreter  # Python
ts
import { Sandbox } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create()
const execution = await sandbox.runCode('x = 1; x += 1; x')
console.log(execution.text)  // outputs 2

5. Computer use with Desktop

For mouse, keyboard, screenshot, application, and desktop streaming APIs, install the Desktop SDK (JavaScript / Python):

text
npm i @e2b/desktop  # JavaScript/TypeScript
pip install e2b-desktop  # Python
ts
import { Sandbox } from '@e2b/desktop'

const desktop = await Sandbox.create()
await desktop.launch('google-chrome')
const screenshot = await desktop.screenshot()

6. Check docs

Visit E2B documentation.

7. E2B cookbook

Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.

Self-hosting

Read the self-hosting guide to learn how to set up the E2B infrastructure on your own. The infrastructure is deployed using Terraform.

Supported cloud providers:

  • ๐ŸŸข AWS
  • ๐ŸŸข Google Cloud (GCP)
  • Azure
  • General Linux machine

File: packages/python-sdk/README.md

What is E2B?

E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.

Run your first Sandbox

1. Install SDK

text
pip install e2b

2. Get your E2B API key

  1. Sign up to E2B here.
  2. Get your API key here.
  3. Set environment variable with your API key
text
E2B_API_KEY=e2b_***

3. Start a sandbox and run commands

py
from e2b import Sandbox

with Sandbox.create() as sandbox:
    result = sandbox.commands.run('echo "Hello from E2B!"')
    print(result.stdout)  # Hello from E2B!

4. Bind the configuration to a client

The top-level Sandbox, AsyncSandbox, Volume, AsyncVolume, Template, AsyncTemplate and Secret exports read their configuration from the environment variables. To use an explicit configuration โ€” e.g. several API keys or domains in one process โ€” create an E2B client and use the resource classes it exposes:

py
from e2b import E2B

client = E2B(api_key="e2b_***", domain="e2b.dev")

sandbox = client.Sandbox.create()
volume = client.Volume.create("my-volume")
exists = client.Template.exists("my-template")
secret = client.Secret.create("openai-api-key", "sk-***")

# The async variants are exposed as well.
async_sandbox = await client.AsyncSandbox.create()

# The classes can be assigned and used like the top-level ones.
Sandbox = client.Sandbox
paginator = Sandbox.list()

Per-call params still take precedence over the client's params, and clients are isolated from each other and from the env-configured top-level exports.

High-concurrency sandbox streams

The Python SDK spreads sandbox commands and files traffic across four HTTP/2 connection pools by default. This prevents long-running streams in one process from all contending for a single connection's concurrent-stream limit.

If one process needs more capacity, set E2B_ENVD_POOL_SHARDS before importing e2b. Each additional shard can open another connection to the sandbox host, so increase it only as needed:

sh
E2B_ENVD_POOL_SHARDS=8 python eval.py

5. Code execution with Code Interpreter

If you need run_code(), install the Code Interpreter SDK:

text
pip install e2b-code-interpreter
py
from e2b_code_interpreter import Sandbox

with Sandbox.create() as sandbox:
    execution = sandbox.run_code("x = 1; x += 1; x")
    print(execution.text)  # outputs 2

6. Check docs

Visit E2B documentation.

7. E2B cookbook

Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.


File: packages/js-sdk/README.md

What is E2B?

E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.

Run your first Sandbox

1. Install SDK

bash
npm i e2b

2. Get your E2B API key

  1. Sign up to E2B here.
  2. Get your API key here.
  3. Set environment variable with your API key
text
E2B_API_KEY=e2b_***

3. Start a sandbox and run commands

ts
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('echo "Hello from E2B!"')
console.log(result.stdout) // Hello from E2B!

4. Bind the configuration to a client

The top-level Sandbox, Volume, Template and Secret exports read their configuration from the environment variables. To use an explicit configuration โ€” e.g. several API keys or domains in one process โ€” create an E2B client and use the resources it exposes:

ts
import { E2B } from 'e2b'

const client = new E2B({ apiKey: 'e2b_***', domain: 'e2b.dev' })

const sandbox = await client.Sandbox.create()
const volume = await client.Volume.create('my-volume')
const exists = await client.Template.exists('my-template')
await client.Secret.create('openai-api-key', 'sk-***')

// The classes can be destructured and used like the top-level ones.
const { Sandbox } = client
const paginator = Sandbox.list()

Per-call options still take precedence over the client's options, and clients are isolated from each other and from the env-configured top-level exports.

5. Code execution with Code Interpreter

If you need runCode(), install the Code Interpreter SDK:

bash
npm i @e2b/code-interpreter
ts
import { Sandbox } from '@e2b/code-interpreter'

const sandbox = await Sandbox.create()
const execution = await sandbox.runCode('x = 1; x += 1; x')
console.log(execution.text)  // outputs 2

6. Check docs

Visit E2B documentation.

7. E2B cookbook

Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.


File: packages/cli/README.md

E2B CLI

This CLI tool allows you to build manager your running E2B sandbox and sandbox templates. Learn more in our documentation.

1. Install the CLI

Using Homebrew (on macOS)

bash
brew install e2b

Using NPM

bash
npm install @e2b/cli

2. Authenticate

bash
e2b auth login

[!NOTE]
To authenticate without the ability to open the browser (e.g. in CI/CD),
provide E2B_API_KEY as an environment variable. You can find your API key
in the API Keys tab in the E2B dashboard.
Then use the CLI like this: E2B_API_KEY=e2b_... e2b template create.

3. Check out docs

Visit our CLI documentation to learn more.