---
description: Skill learned from https://e2b.dev/docs — 60 pages scraped
tags: learned, docs, e2b
source: https://e2b.dev/docs
---

# e2b

> Learned from [https://e2b.dev/docs](https://e2b.dev/docs) — 60 pages

## Documentation - E2B

> Source: https://e2b.dev/docs

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Getting started

E2B Documentation

​

What is E2B?

E2B provides isolated sandboxes that let agents safely execute code, process data, and run tools. Our SDKs make it easy to start and manage these environments.

Start a sandbox and run code in a few lines:

JavaScript & TypeScript

Python

Copy

Ask AI

npm

 i

 e2b

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

() 

// Needs E2B_API_KEY environment variable

const

 result

 =

 await

 sandbox.commands.

run

(

&#x27;echo "Hello from E2B Sandbox!"&#x27;

)

console.

log

(result.stdout)

​

E2B building blocks

A quick overview of the core building blocks you’ll interact with when using E2B.

Sandbox

 — A fast, secure Linux VM created on demand for your agent

Template

 — Defines what environment a sandbox starts with

​

How to use the docs

The documentation is split into three main sections:

Quickstart

 — Step-by-step tutorials that walk you through creating your first E2B sandboxes.

Examples

 — In-depth tutorials focused on specific use cases. Pick the topics that match what you’re building.

SDK Reference

 — A complete technical reference for every SDK method, parameter, and configuration option.

​

Quickstart

​

Examples

Computer Use

Build AI agents that see, understand, and control virtual Linux desktops using E2B Desktop sandboxes.

GitHub Actions CI/CD

Use E2B sandboxes in your GitHub Actions workflows to run testing, validation, and AI code reviews.

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Running your first Sandbox

This guide will show you how to start your first E2B Sandbox.

Next

⌘
I

On this page

What is E2B?

E2B building blocks

How to use the docs

Quickstart

Examples

Assistant

Responses are generated using AI and may contain mistakes.

---

## SDK Reference - E2B

> Source: https://e2b.dev/docs/sdk-reference

SDK Reference - E2B

Documentation

Documentation

SDK Reference

This is the SDK reference for the 
E2B CLI & Core SDK
, 
Code Interpreter SDK
, and 
Desktop Sandbox SDK
.

The reference is intended to be limited to low-level descriptions of various programmatic functionality. If you’re just getting started with E2B, we would instead recommend looking at the 
documentation
 first or to get started quickly with an example.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/api-key

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Getting started

API key

To use the API key, you can either:

Set the API key as the 
E2B_API_KEY
 environment variable
 to avoid passing it each time you create a sandbox.

Or pass it directly to the 
Sandbox
 constructor as shown below:

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

({ apiKey: 

&#x27;YOUR_API_KEY&#x27;

 })

​

Where to find API key

You can get your API key at 
dashboard
.

​

Access token

The access token is used only in the CLI and is 
not needed in the SDK
. There’s no need to set it when logging into the CLI using 
e2b auth login
.

To authenticate without the browser, you can set 
E2B_ACCESS_TOKEN
 as an environment variable. This is useful for CI/CD pipelines.

​

Where to find access token

You can get your 
Access token key
 at the 
dashboard
.

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Cookbook

Next

⌘
I

On this page

Where to find API key

Access token

Where to find access token

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/support

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Getting started

Need help?

Join our Discord community, open GitHub issues, or send us an email if you have any questions or request.

Join our Discord community

Visit our GitHub

Contact us

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Billing

Next

⌘
I

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/billing

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Getting started

Billing & pricing

E2B uses 
usage-based pricing
 - you pay only for what you use. New users receive $100 in free credits to get started.

Manage billing in dashboard

​

Plans

Feature

Hobby

Pro

Enterprise

Base price

$0/month

$150/month

Custom

Free credits

$100 (one-time)

$100 (one-time)

Custom

Max session length

1 hour

24 hours

Custom

Concurrent sandboxes

20

100 - 1,100

1,100+

Pro plan includes 100 concurrent sandboxes. Higher concurrency up to 1,100 is available as a purchasable 
add-on
.

Plans have different 
API rate limits
.

To upgrade your plan or purchase add-ons, visit the 
dashboard billing tab
. For Enterprise plans, 
contact sales
.

​

Usage-based pricing

You pay per second for compute resources while your sandbox is running.

​

Compute costs

Use the 
usage cost calculator
 on our pricing page to estimate costs for your specific configuration.

​

Customizing compute resources

You can customize allocated CPU and RAM when building custom templates by specifying 
cpuCount
 and 
memoryMB
 in the build configuration.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Template, defaultBuildLogger } 

from

 &#x27;e2b&#x27;

await

 Template.

build

(template, 

&#x27;my-template&#x27;

, {

  cpuCount: 

8

,

  memoryMB: 

4096

,

  onBuildLogs: 

defaultBuildLogger

(),

})

See 
template quickstart
 for more details on building custom templates.

Need higher CPU or RAM limits? Contact 
support@e2b.dev
 for more information.

​

Monitoring usage

Check your usage and costs in the 
dashboard usage tab
.

​

FAQ

When am I charged?

Automatically at the start of the month for the previous month’s usage.

What happens when I run out of credits?

Your account will be blocked. Add a payment method to continue using E2B.

Can I set spending limits?

Yes, you can set spending limits on the 
budget page
 in your dashboard.

How do I optimize costs?

Enable auto-pause
 - Automatically pause sandboxes after a period of inactivity to stop billing while preserving state

Pause sandboxes when idle
 - Use 
sbx.pause()
 to stop billing while keeping state available for later

Kill sandboxes you no longer need
 - Use 
sbx.kill()
 to stop billing and release resources permanently

Allocate only what you need

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/use-cases/coding-agents

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Use cases

Coding Agents

Coding agents like 
Claude Code
, 
Codex
, and 
Amp
 can write, debug, and refactor code autonomously. E2B sandboxes give each agent a full Linux environment with terminal, filesystem, and git — completely isolated from your infrastructure. Pre-built templates mean you can go from zero to a running agent in a single API call.

​

Why Use a Sandbox

Running coding agents directly on your machine or servers means giving AI-generated code unrestricted access to your environment. E2B sandboxes solve this:

Isolation
 — agent-generated code runs in a secure sandbox, never touching your production systems or local machine

Full dev environment
 — terminal, filesystem, git, and package managers are all available out of the box, so agents work like a developer would

Pre-built templates
 — ready-made templates for popular agents get you started fast, and you can 
build your own
 for any agent

Scalability
 — run many sandboxes in parallel, each with its own agent on a separate task

​

How It Works

Create a sandbox
 — use a pre-built template or 
build your own
 with any agent installed

Agent gets a full environment
 — terminal, filesystem, git access, and any tools installed in the template

Agent works autonomously
 — it reads the codebase, writes code, runs tests, and iterates until the task is done

Extract results
 — pull out the git diff, structured output, or modified files via the SDK. The sandbox stays available for follow-up work, or you can pause it to pick up later

​

Agent Examples

Since each sandbox is a full Linux environment, you can run any coding agent — just install it in a 
custom template
. E2B also provides pre-built templates for popular agents to get you started quickly.

Claude Code

Anthropic’s autonomous coding agent with structured output and MCP tool support

Codex

OpenAI’s coding agent with schema-validated output and image input

Amp

Coding agent with streaming JSON and thread management

OpenCode

Open-source multi-provider agent with a built-in web UI

​

Related Guides

Git Integration

Clone repos, manage branches, and push changes from sandboxes

Sandbox Persistence

Pause and resume sandboxes to preserve state across sessions

Custom Templates

Build your own sandbox templates with custom tool

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/use-cases/computer-use

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Use cases

Computer use

Computer use agents interact with graphical desktops the same way a human would — viewing the screen, clicking, typing, and scrolling. E2B provides the sandboxed desktop environment where these agents operate safely, with 
VNC
 streaming for real-time visual feedback.

For a complete working implementation, see 
E2B Surf
 — an open-source computer use agent you can try via the 
live demo
.

​

How it works

The computer use agent loop follows this pattern:

User sends a command
 — e.g., “Open Firefox and search for AI news”

Agent creates a desktop sandbox
 — an Ubuntu 22.04 environment with 
XFCE
 desktop and pre-installed applications

Agent takes a screenshot
 — captures the current desktop state via E2B Desktop SDK

LLM analyzes the screenshot
 — a vision model (e.g., 
OpenAI Computer Use API
) decides what action to take

Action is executed
 — click, type, scroll, or keypress via E2B Desktop SDK

Repeat
 — new screenshot is taken and sent back to the LLM until the task is complete

​

Install the E2B Desktop SDK

The 
E2B Desktop
 SDK gives your agent a full Linux desktop with mouse, keyboard, and screen capture APIs.

JavaScript & TypeScript

Python

Copy

Ask AI

npm

 i

 @e2b/desktop

​

Core implementation

The following snippets are adapted from 
E2B Surf
.

​

Setting up the sandbox

Create a desktop sandbox and start VNC streaming so you can view the desktop in a browser.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/desktop&#x27;

// Create a desktop sandbox with a 5-minute timeout

const

 sandbox

 =

 await

 Sandbox.

create

({

  resolution: [

1024

, 

720

],

  dpi: 

96

,

  timeoutMs: 

300_000

,

})

// Start VNC streaming for browser-based viewing

await

 sandbox.stream.

start

()

const

 streamUrl

 =

 sandbox.stream.

getUrl

()

console.

log

(

&#x27;View desktop at:&#x27;

, streamUrl)

​

Executing desktop actions

The E2B Desktop SDK maps directly to mouse and keyboard actions. Here’s how Surf translates LLM-returned actions into desktop interactions.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/desktop&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

({ timeoutMs: 

300_000

 })

// Mouse action

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/use-cases/ci-cd

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Use cases

GitHub Actions CI/CD

CI/CD pipelines can use AI agents to review pull requests, generate tests, and validate code changes automatically. E2B sandboxes provide the secure, isolated execution environment where these agents can safely clone repositories, run untrusted code, and report results — all triggered by 
GitHub Actions
 on every pull request. Each run uses its own isolated sandbox, so malicious or buggy PR code never touches your CI runner.

​

GitHub Actions workflow

The workflow triggers on pull request events and runs a review script. 
E2B_API_KEY
 and the LLM API key are stored as 
GitHub Actions secrets
, while the built-in 
GITHUB_TOKEN
 is available automatically. The 
permissions
 block grants write access so the script can post PR comments.

.github/workflows/ai-review.yml (JavaScript)

.github/workflows/ai-review.yml (Python)

Copy

Ask AI

name

: 

AI Code Review

on

:

  pull_request

:

    types

: [

opened

, 

synchronize

]

permissions

:

  pull-requests

: 

write

jobs

:

  ai-review

:

    runs-on

: 

ubuntu-latest

    steps

:

      - 

uses

: 

actions/checkout@v4

      - 

name

: 

Set up Node.js

        uses

: 

actions/setup-node@v4

        with

:

          node-version

: 

"20"

      - 

name

: 

Install dependencies

        run

: 

npm install e2b openai

      - 

name

: 

Run AI review

        env

:

          E2B_API_KEY

: 

${{ secrets.E2B_API_KEY }}

          OPENAI_API_KEY

: 

${{ secrets.OPENAI_API_KEY }}

          GITHUB_TOKEN

: 

${{ secrets.GITHUB_TOKEN }}

          PR_REPO

: 

${{ github.event.pull_request.head.repo.full_name }}

          PR_BRANCH

: 

${{ github.event.pull_request.head.ref }}

          PR_NUMBER

: 

${{ github.event.pull_request.number }}

          GITHUB_REPOSITORY

: 

${{ github.repository }}

        run

: 

node review.mjs

​

Review script

The workflow calls this script on every PR. It runs five steps inside an E2B sandbox, keeping all untrusted code isolated from the CI runner.

review.mjs

review.py

Copy

Ask AI

import

 { Sandbox, CommandExitError } 

from

 &#x27;e2b&#x27;

import

 OpenAI 

from

 &#x27;openai&#x27;

// --- 1. Create sandbox ---

const

 sandbox

 =

 await

 Sandbox.

create

({ timeoutMs: 

300_000

 })

conso

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/agents/amp

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Agents in sandbox

Amp

Amp
 is a coding agent with multi-model architecture and built-in code intelligence. E2B provides a pre-built 
amp
 template with Amp already installed.

​

CLI

Create a sandbox with the 
E2B CLI
.

Copy

Ask AI

e2b

 sbx

 create

 amp

Once inside the sandbox, start Amp.

Copy

Ask AI

amp

​

Run headless

Use 
-x
 for non-interactive mode and 
--dangerously-allow-all
 to auto-approve all tool calls (safe inside E2B sandboxes). Amp uses its own API key from 
ampcode.com/settings
.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;amp&#x27;

, {

  envs: { AMP_API_KEY: process.env.

AMP_API_KEY

 },

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `amp --dangerously-allow-all -x "Create a hello world HTTP server in Go"`

)

console.

log

(result.stdout)

await

 sandbox.

kill

()

​

Example: work on a cloned repository

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;amp&#x27;

, {

  envs: { AMP_API_KEY: process.env.

AMP_API_KEY

 },

  timeoutMs: 

600_000

,

})

await

 sandbox.git.

clone

(

&#x27;https://github.com/your-org/your-repo.git&#x27;

, {

  path: 

&#x27;/home/user/repo&#x27;

,

  username: 

&#x27;x-access-token&#x27;

,

  password: process.env.

GITHUB_TOKEN

,

  depth: 

1

,

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `cd /home/user/repo && amp --dangerously-allow-all -x "Add error handling to all API endpoints"`

,

  { 

onStdout

: (

data

) 

=>

 process.stdout.

write

(data) }

)

const

 diff

 =

 await

 sandbox.commands.

run

(

&#x27;cd /home/user/repo && git diff&#x27;

)

console.

log

(diff.stdout)

await

 sandbox.

kill

()

​

Streaming JSON

Use 
--stream-json
 to get a real-time JSONL event stream with rich metadata — including tool calls, token usage, thinking blocks, and permission decisions.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;amp&#x27;

, {

  envs: { AMP_API_KEY: process.env.

AMP_API_KEY

 },

})

const

 result

 =

 awa

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/agents/claude-code

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Agents in sandbox

Claude Code

Claude Code
 is Anthropic’s agentic coding tool. E2B provides a pre-built 
claude
 template with Claude Code already installed.

​

CLI

Create a sandbox with the 
E2B CLI
.

Copy

Ask AI

e2b

 sbx

 create

 claude

Once inside the sandbox, start Claude Code.

Copy

Ask AI

claude

​

Run headless

Use 
-p
 for non-interactive mode and 
--dangerously-skip-permissions
 to auto-approve all tool calls (safe inside E2B sandboxes).

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;claude&#x27;

, {

  envs: { ANTHROPIC_API_KEY: process.env.

ANTHROPIC_API_KEY

 },

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `claude --dangerously-skip-permissions -p "Create a hello world HTTP server in Go"`

)

console.

log

(result.stdout)

await

 sandbox.

kill

()

​

Example: work on a cloned repository

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;claude&#x27;

, {

  envs: { ANTHROPIC_API_KEY: process.env.

ANTHROPIC_API_KEY

 },

  timeoutMs: 

600_000

,

})

await

 sandbox.git.

clone

(

&#x27;https://github.com/your-org/your-repo.git&#x27;

, {

  path: 

&#x27;/home/user/repo&#x27;

,

  username: 

&#x27;x-access-token&#x27;

,

  password: process.env.

GITHUB_TOKEN

,

  depth: 

1

,

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `cd /home/user/repo && claude --dangerously-skip-permissions -p "Add error handling to all API endpoints"`

,

  { 

onStdout

: (

data

) 

=>

 process.stdout.

write

(data) }

)

const

 diff

 =

 await

 sandbox.commands.

run

(

&#x27;cd /home/user/repo && git diff&#x27;

)

console.

log

(diff.stdout)

await

 sandbox.

kill

()

​

Structured output

Use 
--output-format json
 to get machine-readable responses — useful for building pipelines or extracting specific results.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;claude&#x27;

, {

  envs: { ANTHROPIC_API_KEY: process.env.

ANTHROPIC_API_KEY

 },

})

const

 result

 =

 await

 sandbox.c

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/agents/codex

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Agents in sandbox

Codex

Codex
 is OpenAI’s open-source coding agent. E2B provides a pre-built 
codex
 template with Codex already installed.

​

CLI

Create a sandbox with the 
E2B CLI
.

Copy

Ask AI

e2b

 sbx

 create

 codex

Once inside the sandbox, start Codex.

Copy

Ask AI

codex

​

Run headless

Use 
codex exec
 for non-interactive mode and 
--full-auto
 to auto-approve tool calls (safe inside E2B sandboxes). Pass 
--skip-git-repo-check
 to bypass git directory ownership checks inside the sandbox. Pass 
CODEX_API_KEY
 as an environment variable.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;codex&#x27;

, {

  envs: { CODEX_API_KEY: process.env.

CODEX_API_KEY

 },

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `codex exec --full-auto --skip-git-repo-check "Create a hello world HTTP server in Go"`

)

console.

log

(result.stdout)

await

 sandbox.

kill

()

​

Example: work on a cloned repository

Use 
-C
 to set Codex’s working directory to a cloned repo.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;codex&#x27;

, {

  envs: { CODEX_API_KEY: process.env.

CODEX_API_KEY

 },

  timeoutMs: 

600_000

,

})

await

 sandbox.git.

clone

(

&#x27;https://github.com/your-org/your-repo.git&#x27;

, {

  path: 

&#x27;/home/user/repo&#x27;

,

  username: 

&#x27;x-access-token&#x27;

,

  password: process.env.

GITHUB_TOKEN

,

  depth: 

1

,

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `codex exec --full-auto --skip-git-repo-check -C /home/user/repo "Add error handling to all API endpoints"`

,

  { 

onStdout

: (

data

) 

=>

 process.stdout.

write

(data) }

)

const

 diff

 =

 await

 sandbox.commands.

run

(

&#x27;cd /home/user/repo && git diff&#x27;

)

console.

log

(diff.stdout)

await

 sandbox.

kill

()

​

Schema-validated output

Use 
--output-schema
 to constrain the agent’s final response to a JSON Schema. This ensures the output conforms to a specific structure — useful for building reliable pipelines.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

fr

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/agents/opencode

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Agents in sandbox

OpenCode

OpenCode
 is an open-source coding agent that supports multiple LLM providers. E2B provides a pre-built 
opencode
 template with OpenCode already installed.

​

CLI

Create a sandbox with the 
E2B CLI
.

Copy

Ask AI

e2b

 sbx

 create

 opencode

Once inside the sandbox, start OpenCode.

Copy

Ask AI

opencode

​

Run headless

Use 
opencode run
 for non-interactive mode. Pass your LLM provider’s API key as an environment variable — OpenCode supports 
ANTHROPIC_API_KEY
, 
OPENAI_API_KEY
, 
GEMINI_API_KEY
, and 
others
.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;opencode&#x27;

, {

  envs: { ANTHROPIC_API_KEY: process.env.

ANTHROPIC_API_KEY

 },

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `opencode run "Create a hello world HTTP server in Go"`

)

console.

log

(result.stdout)

await

 sandbox.

kill

()

​

Example: work on a cloned repository

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;opencode&#x27;

, {

  envs: { ANTHROPIC_API_KEY: process.env.

ANTHROPIC_API_KEY

 },

  timeoutMs: 

600_000

,

})

await

 sandbox.git.

clone

(

&#x27;https://github.com/your-org/your-repo.git&#x27;

, {

  path: 

&#x27;/home/user/repo&#x27;

,

  username: 

&#x27;x-access-token&#x27;

,

  password: process.env.

GITHUB_TOKEN

,

  depth: 

1

,

})

const

 result

 =

 await

 sandbox.commands.

run

(

  `cd /home/user/repo && opencode run "Add error handling to all API endpoints"`

,

  { 

onStdout

: (

data

) 

=>

 process.stdout.

write

(data) }

)

const

 diff

 =

 await

 sandbox.commands.

run

(

&#x27;cd /home/user/repo && git diff&#x27;

)

console.

log

(diff.stdout)

await

 sandbox.

kill

()

​

Connect with the OpenCode SDK

OpenCode includes a 
headless HTTP server
 that you can control programmatically using the 

@opencode-ai/sdk

 client. Start the server inside a sandbox, get the public URL with 
sandbox.getHost()
, and connect from your application.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

import

 { createOpenco

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/code-interpreting/streaming

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Code interpreting

Streaming

E2B Code Interpreter SDK allows you to stream the output, and results when executing code in the sandbox.

​

Stream 
stdout
 and 
stderr

When using the 
runCode()
 method in JavaScript or 
run_code()
 in Python you can pass 
onStdout
/
on_stdout
 and 
onStderr
/
on_stderr
 callbacks to handle the output.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 codeToRun

 =

 `

  import time

  import sys

  print("This goes first to stdout")

  time.sleep(3)

  print("This goes later to stderr", file=sys.stderr)

  time.sleep(3)

  print("This goes last")

`

const

 sandbox

 =

 await

 Sandbox.

create

()

sandbox.

runCode

(codeToRun, {

  // Use `onError` to handle runtime code errors

  onError

: 

error

 =>

 console.

error

(

&#x27;error:&#x27;

, error),

  onStdout

: 

data

 =>

 console.

log

(

&#x27;stdout:&#x27;

, data),

  onStderr

: 

data

 =>

 console.

error

(

&#x27;stderr:&#x27;

, data),

})

The code above will print the following:

JavaScript & TypeScript

Python

Copy

Ask AI

stdout

: {

  error

: 

false

,

  line

: 

"This goes first to stdout

\n

"

,

  timestamp

: 

1729049666861000

,

}

stderr

: {

  error

: 

true

,

  line

: 

"This goes later to stderr

\n

"

,

  timestamp

: 

1729049669924000

,

}

stdout

: {

  error

: 

false

,

  line

: 

"This goes last

\n

"

,

  timestamp

: 

1729049672664000

,

}

​

Stream 
results

When using the 
runCode()
 method in JavaScript or 
run_code()
 in Python you can pass 
onResults
/
on_results
 callback
to receive results from the sandbox like charts, tables, text, and more.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 codeToRun

 =

 `

import matplotlib.pyplot as plt

# Prepare data

categories = [&#x27;Category A&#x27;, &#x27;Category B&#x27;, &#x27;Category C&#x27;, &#x27;Category D&#x27;]

values = [10, 20, 15, 25]

# Create and customize the bar chart

plt.figure(figsize=(10, 6))

plt.bar(categories, values, color=&#x27;green&#x27;)

plt.xlabel(&#x27;Categories&#x27;)

plt.ylabel(&#x27;Values&#x27;)

plt.title(&#x27;Values by Category&#x27;)

# Display the chart

plt.show()

`

const

 sandbox

 =

 await

 Sandbox.

create

()


...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/code-interpreting/contexts

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Code interpreting

Code contexts

Run code in different code execution contexts with E2B Code Interpreter SDK. This allows you to parallelize code execution by running code in different contexts at the same time.

By default the code is run in the Sandbox’s default code execution context. You can change it by passing the 
context
 parameter to the 
runCode()
 method in JavaScript or 
run_code()
 in Python.

​

Create a new Code Context

You can create a new code execution context by calling the 
createCodeContext()
 method in JavaScript or 
create_code_context()
 in Python and passing the context parameters.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 context

 =

 await

 sandbox.

createCodeContext

({

  cwd: 

&#x27;/home/user&#x27;

,

  language: 

&#x27;python&#x27;

,

  requestTimeoutMs: 

60_000

,

})

const

 result

 =

 await

 sandbox.

runCode

(

&#x27;print("Hello, world!")&#x27;

, { context })

console.

log

(result)

​

List active Code Contexts

You can list active code execution contexts by calling the 
listCodeContexts()
 method in JavaScript or 
list_code_contexts()
 in Python. This will return a list of active code execution contexts.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 contexts

 =

 await

 sandbox.

listCodeContexts

()

console.

log

(contexts)

​

Restart a Code Context

You can restart an active code execution context by calling the 
restartCodeContext()
 method in JavaScript or 
restart_code_context()
 in Python and passing the context object or context ID.
Restarting a context will clear its state and start a new code execution session in the same context.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 context

 =

 await

 sandbox.

createCodeContext

({

  cwd: 

&#x27;/home/user&#x27;

,

  language: 

&#x27;python&#x27;

,

  requestTimeoutMs: 

60_000

,

})

// using context object

await

 sandbox.

restartCodeContext

(contex

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Sandbox lifecycle

Sandboxes stay running as long as you need them. When their timeout expires, they automatically pause to save resources — preserving their full state so you can resume at any time. You can also configure an explicit timeout or shut down a sandbox manually.

Sandboxes can run continuously for up to 24 hours (Pro) or 1 hour (Base). For longer workloads, use 
pause and resume
 — pausing resets the runtime window, and your sandbox’s full state is preserved indefinitely.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Create sandbox with and keep it running for 60 seconds.

// 🚨 Note: The units are milliseconds.

const

 sandbox

 =

 await

 Sandbox.

create

({

  timeoutMs: 

60_000

,

})

​

Change sandbox timeout during runtime

You can change the sandbox timeout when it’s running by calling the 
setTimeout
 method in JavaScript or 
set_timeout
 method in Python.

When you call the set timeout method, the sandbox timeout will be reset to the new value that you specified.

This can be useful if you want to extend the sandbox lifetime when it’s already running.
You can for example start with a sandbox with 1 minute timeout and then periodically call set timeout every time user interacts with it in your app.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Create sandbox with and keep it running for 60 seconds.

const

 sandbox

 =

 await

 Sandbox.

create

({ timeoutMs: 

60_000

 })

// Change the sandbox timeout to 30 seconds.

// 🚨 The new timeout will be 30 seconds from now.

await

 sandbox.

setTimeout

(

30_000

)

​

Retrieve sandbox information

You can retrieve sandbox information like sandbox ID, template, metadata, started at/end at date by calling the 
getInfo
 method in JavaScript or 
get_info
 method in Python.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Create sandbox with and keep it running for 60 seconds.

const

 sandbox

 =

 await

 Sandbox.

create

({ timeoutMs: 

60_000

 })

// Retrieve sandbox information.

const

 info

 =

 await

 sandbox.

getInfo

()

console.

log

(info)

// {

//   "

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/lifecycle-events-api

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Monitor sandbox lifecycle events

The lifecycle API provides RESTful endpoints to request the latest sandbox lifecycle events. This allows you to track when sandboxes are created, paused, resumed, updated, snapshotted, or killed, along with metadata.
All requests require authentication using your team 
API key
.

Query Parameters:

offset
 (optional): Number of events to skip (default: 0, min: 0)

limit
 (optional): Number of events to return (default: 10, min: 1, max: 100)

orderAsc
 (optional): Sort order - true for ascending, false for descending (default: false)

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sbx

 =

 await

 Sandbox.

create

()

// Get the latest events for a specific sandbox

const

 resp1

 =

 await

 fetch

(

  `https://api.e2b.app/events/sandboxes/${

sbx

.

id

}`

,

  {

    method: 

&#x27;GET&#x27;

,

    headers: {

      &#x27;X-API-Key&#x27;

: 

E2B_API_KEY

,

    },

  }

)

const

 sandboxEvents

 =

 await

 resp1.

json

()

// Get the latest 10 events for all sandboxes associated with the team

const

 resp2

 =

 await

 fetch

(

  &#x27;https://api.e2b.app/events/sandboxes?limit=10&#x27;

,

  {

    method: 

&#x27;GET&#x27;

,

    headers: {

      &#x27;X-API-Key&#x27;

: 

E2B_API_KEY

,

    },

  }

)

const

 teamSandboxEvents

 =

 await

 resp2.

json

()

console.

log

(teamSandboxEvents)

// [

//   {

//     "version": "v1",

//     "id": "f5911677-cb60-498f-afed-f68143b3cc59",

//     "type": "sandbox.lifecycle.killed",

//     "eventData": null,

//     "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",

//     "sandboxExecutionId": "1dae9e1c-9957-4ce7-a236-a99d5779aadf",

//     "sandboxId": "${SANDBOX_ID}",

//     "sandboxTeamId": "460355b3-4f64-48f9-9a16-4442817f79f5",

//     "sandboxTemplateId": "rki5dems9wqfm4r03t7g",

//     "timestamp": "2025-08-06T20:59:36Z"

//   },

//   {

//     "version": "v1",

//     "id": "30b09e11-9ba2-42db-9cf6-d21f0f43a234",

//     "type": "sandbox.lifecycle.updated",

//     "eventData": {

//       "set_timeout": "2025-08-06T20:59:59Z"

//     },

//     "sandboxBuildId": "a979a14b-bdcc-49e6-bc04-1189fc9fe7c2",

//     "sandboxExecutionId": "1dae9e1c-9957-4ce7-

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/lifecycle-events-webhooks

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Sandbox lifecycle webhooks

Webhooks provide a way for notifications to be delivered to an external web server whenever certain sandbox lifecycle events occur.
This allows you to receive real-time updates about sandbox creation, updates, and termination without having to poll the API.
All webhook requests require authentication using your team 
API key
.

​

Webhook management

​

Register webhook

Register a new webhook to receive sandbox lifecycle events.
The webhook will be registered for the team ID associated with your API key.
All events specified during webhook creation will be sent to URL provided during registration with 
following payload
.

JavaScript & TypeScript

Python

Copy

Ask AI

// Register a new webhook

const

 resp

 =

 await

 fetch

(

  &#x27;https://api.e2b.app/events/webhooks&#x27;

,

  {

    method: 

&#x27;POST&#x27;

,

    headers: {

      &#x27;X-API-Key&#x27;

: 

E2B_API_KEY

,

      &#x27;Content-Type&#x27;

: 

&#x27;application/json&#x27;

,

    },

    body: 

JSON

.

stringify

({

      name: 

&#x27;My Sandbox Webhook&#x27;

,

      url: 

&#x27;https://your-webhook-endpoint.com/webhook&#x27;

,

      enabled: 

true

,

      events: [

&#x27;sandbox.lifecycle.created&#x27;

, 

&#x27;sandbox.lifecycle.updated&#x27;

, 

&#x27;sandbox.lifecycle.killed&#x27;

],

      signatureSecret: 

&#x27;secret-for-event-signature-verification&#x27;

    }),

  }

)

if

 (resp.status 

===

 201

) {

  console.

log

(

&#x27;Webhook registered successfully&#x27;

)

}

​

List webhooks

List all registered webhooks for your team.

JavaScript & TypeScript

Python

Copy

Ask AI

// List webhooks

const

 resp

 =

 await

 fetch

(

  &#x27;https://api.e2b.app/events/webhooks&#x27;

,

  {

    method: 

&#x27;GET&#x27;

,

    headers: {

      &#x27;X-API-Key&#x27;

: 

E2B_API_KEY

    },

  },

)

if

 (resp.status 

===

 200

) {

  console.

log

(

&#x27;Webhooks listed successfully&#x27;

)

  console.

log

(

await

 resp.

json

())

}

​

Get webhook configuration

Retrieve the current webhook configuration for your team.

JavaScript & TypeScript

Python

Copy

Ask AI

// Get webhook configuration

const

 resp

 =

 await

 fetch

(

  `https://api.e2b.app/events/webhooks/${

webhookID

}`



...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/persistence

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Sandbox persistence

The sandbox persistence allows you to pause your sandbox and resume it later from the same state it was in when you paused it.

This includes not only state of the sandbox’s filesystem but also the sandbox’s memory. This means all running processes, loaded variables, data, etc.

​

Sandbox state transitions

Understanding how sandboxes transition between different states is crucial for managing their lifecycle effectively. Here’s a diagram showing the possible state transitions:

​

State descriptions

Running
: The sandbox is actively running and can execute code. This is the initial state after creation.

Paused
: The sandbox execution is suspended but its state is preserved.

Snapshotting
: The sandbox is briefly paused while a persistent snapshot is being created. It automatically returns to Running. See 
Snapshots
.

Killed
: The sandbox is terminated and all resources are released. This is a terminal state.

​

Changing sandbox’s state

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

() 

// Starts in Running state

// Pause the sandbox

await

 sandbox.

betaPause

() 

// Running → Paused

// Resume the sandbox

await

 sandbox.

connect

() 

// Running/Paused → Running

// Kill the sandbox (from any state)

await

 sandbox.

kill

() 

// Running/Paused → Killed

​

Pausing sandbox

When you pause a sandbox, both the sandbox’s filesystem and memory state will be saved. This includes all the files in the sandbox’s filesystem and all the running processes, loaded variables, data, etc.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sbx

 =

 await

 Sandbox.

create

()

console.

log

(

&#x27;Sandbox created&#x27;

, sbx.sandboxId)

// Pause the sandbox

// You can save the sandbox ID in your database to resume the sandbox later

await

 sbx.

betaPause

()

console.

log

(

&#x27;Sandbox paused&#x27;

, sbx.sandboxId)

​

Resuming sandbox

When you resume a sandbox, it will be in the same state it was in when you paused it.
This means that all the files in the sandbox’s filesystem will be restored and all the running processes, lo

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/snapshots

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Sandbox snapshots

Snapshots let you create a persistent point-in-time capture of a running sandbox, including both its filesystem and memory state.
You can then use a snapshot to spawn new sandboxes that start from the exact same state.

The original sandbox continues running after the snapshot is created, and a single snapshot can be used to create many new sandboxes.

​

Snapshots vs. Pause/Resume

Pause/Resume

Snapshots

Effect on original sandbox

Pauses (stops) the sandbox

Sandbox briefly pauses, then continues running

Relationship

One-to-one — resume restores the same sandbox

One-to-many — snapshot can spawn many new sandboxes

Use case

Suspend and resume a single sandbox

Create a reusable checkpoint

For pause/resume functionality, see 
Persistence
.

​

Snapshot flow

The sandbox is briefly paused during the snapshot process but automatically returns to running state. The sandbox ID stays the same after the snapshot completes.

During the snapshot, the sandbox is temporarily paused and resumed. This causes all active connections (e.g. WebSocket, PTY, command streams) to be dropped. Make sure your client handles reconnection properly.

​

Create a snapshot

You can create a snapshot from a running sandbox instance.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Create a snapshot from a running sandbox

const

 snapshot

 =

 await

 sandbox.

createSnapshot

()

console.

log

(

&#x27;Snapshot ID:&#x27;

, snapshot.snapshotId)

You can also create a snapshot by sandbox ID using the static method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

// Create a snapshot by sandbox ID

const

 snapshot

 =

 await

 Sandbox.

createSnapshot

(sandboxId)

console.

log

(

&#x27;Snapshot ID:&#x27;

, snapshot.snapshotId)

​

Create a sandbox from a snapshot

The snapshot ID can be used directly with 
Sandbox.create()
 to spawn a new sandbox from the snapshot. The new sandbox starts with the exact filesystem and memory state captured in the snapshot.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 snapshot

 =

 await

 sandbox.

create

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/git-integration

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Git integration

Use the 
sandbox.git
 methods to run common git operations inside a sandbox.

​

Authentication and Identity

​

Passing credentials inline

For private repositories over HTTP(S), pass 
username
 and 
password
 (token) directly to commands that need authentication. A username is required whenever you pass a password/token.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 repoPath

 =

 &#x27;/home/user/repo&#x27;

await

 sandbox.git.

push

(repoPath, {

  username: process.env.

GIT_USERNAME

,

  password: process.env.

GIT_TOKEN

,

})

await

 sandbox.git.

pull

(repoPath, {

  username: process.env.

GIT_USERNAME

,

  password: process.env.

GIT_TOKEN

,

})

​

Credential helper (authenticate once)

To avoid passing credentials on each command, store them in the git credential helper inside the sandbox using 
dangerouslyAuthenticate()
 / 
dangerously_authenticate()
.

Stores credentials on disk inside the sandbox. Any process or agent with access to the sandbox can read them. Use only when you understand the risk.

JavaScript & TypeScript

Python

Copy

Ask AI

// Default (GitHub)

await

 sandbox.git.

dangerouslyAuthenticate

({

  username: process.env.

GIT_USERNAME

,

  password: process.env.

GIT_TOKEN

,

})

// Custom host (self-hosted)

await

 sandbox.git.

dangerouslyAuthenticate

({

  username: process.env.

GIT_USERNAME

,

  password: process.env.

GIT_TOKEN

,

  host: 

&#x27;git.example.com&#x27;

,

  protocol: 

&#x27;https&#x27;

,

})

// After this, HTTPS git operations use the stored credentials

await

 sandbox.git.

clone

(

&#x27;https://git.example.com/org/repo.git&#x27;

, { path: 

&#x27;/home/user/repo&#x27;

 })

await

 sandbox.git.

push

(

&#x27;/home/user/repo&#x27;

)

​

Keep credentials in the remote URL

By default, credentials are stripped from the remote URL after cloning. To keep credentials in the remote URL (stored in 
.git/config
), set 
dangerouslyStoreCredentials
 / 
dangerously_store_credentials
.

Storing credentials in the remote URL persists them in the repo config. Any process or agent with access to the sandbox can read them. Only use this when required.

JavaScript & TypeScript

Python

Copy

Ask AI

// Default: credentials are stripped from the remote UR

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/metrics

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Sandbox metrics

The sandbox metrics allows you to get information about the sandbox’s CPU, memory and disk usage.

​

Getting sandbox metrics

Getting the metrics of a sandbox returns an array of timestamped metrics containing CPU, memory and disk usage information.
The metrics are collected every 5 seconds.

​

Getting sandbox metrics using the SDKs

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sbx

 =

 await

 Sandbox.

create

()

console.

log

(

&#x27;Sandbox created&#x27;

, sbx.sandboxId)

// Wait for a few seconds to collect some metrics

await

 new

 Promise

((

resolve

) 

=>

 setTimeout

(resolve, 

10_000

))

const

 metrics

 =

 await

 sbx.

getMetrics

()

// You can also get the metrics by sandbox ID:

// const metrics = await Sandbox.getMetrics(sbx.sandboxId)

console.

log

(

&#x27;Sandbox metrics:&#x27;

, metrics)

// Sandbox metrics:

// [

//   {

//     timestamp: 2025-07-28T08:04:05.000Z,

//     cpuUsedPct: 20.33,

//     cpuCount: 2,

//     memUsed: 32681984,

  // in bytes

//     memTotal: 507592704,

  // in bytes

//     diskUsed: 1514856448,

  // in bytes

//     diskTotal: 2573185024

  // in bytes

//   },

//   {

//     timestamp: 2025-07-28T08:04:10.000Z,

//     cpuUsedPct: 0.2,

//     cpuCount: 2,

//     memUsed: 33316864,

  // in bytes

//     memTotal: 507592704,

 // in bytes

//     diskUsed: 1514856448,

  // in bytes

//     diskTotal: 2573185024

  // in bytes

//   }

// ]

​

Getting sandbox metrics using the CLI

Terminal

Copy

Ask AI

e2b

 sandbox

 metrics

 <

sandbox_i

d

>

 

# Metrics for sandbox <sandbox_id>

# 

# [2025-07-25 14:05:55Z]  CPU:  8.27% /  2 Cores | Memory:    31 / 484   MiB | Disk:  1445 / 2453  MiB

# [2025-07-25 14:06:00Z]  CPU:   0.5% /  2 Cores | Memory:    32 / 484   MiB | Disk:  1445 / 2453  MiB

# [2025-07-25 14:06:05Z]  CPU:   0.1% /  2 Cores | Memory:    32 / 484   MiB | Disk:  1445 / 2453  MiB

# [2025-07-25 14:06:10Z]  CPU:   0.3% /  2 Cores | Memory:    32 / 484   MiB | Disk:  1445 / 2453  MiB

It may take a second or more to get the first metrics after the sandbox is created. Until the first metrics are collected from the sandbox, you will get an empty array.

Was this p

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/metadata

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Sandbox metadata

Metadata is a way to attach arbitrary key-value pairs for a sandbox.

This is useful in various scenarios, for example:

Associate a sandbox with a user session.

Store custom user data for a sandbox like API keys.

Associate a sandbox with a user ID and 
connect to it later
.

You specify metadata when creating a sandbox and can access it later through listing running sandboxes with 
Sandbox.list()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Create sandbox with metadata.

const

 sandbox

 =

 await

 Sandbox.

create

({

  metadata: {

    userId: 

&#x27;123&#x27;

,

  },

})

// List running sandboxes and access metadata.

const

 paginator

 =

 await

 Sandbox.

list

()

const

 runningSandboxes

 =

 await

 paginator.

nextItems

()

// Will print:

// {

//   &#x27;userId&#x27;: &#x27;123&#x27;,

// }

console.

log

(runningSandboxes[

0

].metadata)

​

Filtering sandboxes by metadata

You can also filter sandboxes by metadata, you can find more about it 
here
.

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Environment variables

Next

⌘
I

On this page

Filtering sandboxes by metadata

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/environment-variables

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Environment variables

This page covers how to set and use environment variables in a sandbox, and default environment variables inside the sandbox.

​

Default environment variables

​

Knowing if you are inside a sandbox

Sometimes it’s useful to know if the code is running inside a sandbox. Upon creating a sandbox, useful sandbox metadata is set as environment variables for commands:

E2B_SANDBOX
 is set to 
true
 for processes to know if they are inside our VM.

E2B_SANDBOX_ID
 to know the ID of the sandbox.

E2B_TEAM_ID
 to know the team ID that created the sandbox.

E2B_TEMPLATE_ID
 to know what template was used for the current sandbox.

You can try it out by running the following code in the sandbox:

JavaScript & TypeScript

Python

Copy

Ask AI

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 result

 =

 await

 sandbox.commands.

run

(

&#x27;echo $E2B_SANDBOX_ID&#x27;

)

These default environment variables are only accessible via the SDK, when using the CLI you can find them in the form of dot files in the 
/run/e2b/
 dir:

Copy

Ask AI

user@e2b:~$

 ls

 -a

 /run/e2b/

.E2B_SANDBOX

  .E2B_SANDBOX_ID

  .E2B_TEAM_ID

  .E2B_TEMPLATE_ID

​

Setting environment variables

There are 3 ways to set environment variables in a sandbox:

Global environment variables when creating the sandbox
.

When running code in the sandbox
.

When running commands in the sandbox
.

​

1. Global environment variables

You can set global environment variables when creating a sandbox.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 sandbox

 =

 await

 Sandbox.

create

({

  envs: {

    MY_VAR: 

&#x27;my_value&#x27;

,

  },

})

​

2. Setting environment variables when running code

You can set environment variables for specific code execution call in the sandbox.

These environment variables are scoped to the command but are not private in the OS.

If you had a global environment variable with the same name, it will be overridden only for the command.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 result

 =

 await

 sandbox.

runCode

(

&#x27;import os; print(os.environ.get("MY_VAR"))&#x27;

, {

  envs: {

    MY_VAR: 

&#x27;my_value&#x27;

,

  },

})

​

3. 

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/list

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

List sandboxes

You can list sandboxes using the 
Sandbox.list()
 method.

Once you have information about running sandbox, you can 
connect
 to it using the 
Sandbox.connect()
 method.

​

Listing sandboxes

The 
Sandbox.list()
 method supports pagination. In the 
advanced pagination
 section, you can find more information about pagination techniques using the updated method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox, SandboxInfo } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

  {

    metadata: {

      name: 

&#x27;My Sandbox&#x27;

,

    },

  },

)

const

 paginator

 =

 Sandbox.

list

()

// Get the first page of sandboxes (running and paused)

const

 firstPage

 =

 await

 paginator.

nextItems

()

const

 runningSandbox

 =

 firstPage[

0

]

console.

log

(

&#x27;Running sandbox metadata:&#x27;

, runningSandbox.metadata)

console.

log

(

&#x27;Running sandbox id:&#x27;

, runningSandbox.sandboxId)

console.

log

(

&#x27;Running sandbox started at:&#x27;

, runningSandbox.startedAt)

console.

log

(

&#x27;Running sandbox template id:&#x27;

, runningSandbox.templateId)

// Get the next page of sandboxes

const

 nextPage

 =

 await

 paginator.

nextItems

()

The code above will output something like this:

JavaScript & TypeScript

Python

Copy

Ask AI

Running

 sandbox

 metadata:

 {name:

 "My Sandbox"}

Running

 sandbox

 id:

 ixjj3iankaishgcge4jwn-b0b684e9

Running

 sandbox

 started

 at:

 2024-10-15T21:13:07.311Z

Running

 sandbox

 template

 id:

 3e4rngfa34txe0gxc1zf

​

Filtering sandboxes

Filter sandboxes by their current state. The state parameter can contain either “
running
” for running sandboxes or “
paused
” for paused sandboxes, or both.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Create a sandbox.

const

 sandbox

 =

 await

 Sandbox.

create

()

// List sandboxes that are running or paused.

const

 paginator

 =

 Sandbox.

list

({

  query: {

    state: [

&#x27;running&#x27;

, 

&#x27;paused&#x27;

],

  },

})

const

 sandboxes

 =

 await

 paginator.

nextItems

()

Filter sandboxes by the metadata key value pairs specified during Sa

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/connect

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Connect to running sandbox

If you have a running sandbox, you can connect to it using the 
Sandbox.connect()
 method and then start controlling it with our SDK.

This is useful if you want to, for example, reuse the same sandbox instance for the same user after a short period of inactivity.

​

1. Get the sandbox ID

To connect to a running sandbox, you first need to retrieve its ID. You can do this by calling the 
Sandbox.list()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sbx

 =

 await

 Sandbox.

create

()

// Get all running sandboxes

const

 paginator

 =

 await

 Sandbox.

list

({

  query: { state: [

&#x27;running&#x27;

] },

})

const

 runningSandboxes

 =

 await

 paginator.

nextItems

()

if

 (runningSandboxes.

length

 ===

 0

) {

  throw

 new

 Error

(

&#x27;No running sandboxes found&#x27;

)

}

// Get the ID of the sandbox you want to connect to

const

 sandboxId

 =

 runningSandboxes[

0

].sandboxId

​

2. Connect to the sandbox

Now that you have the sandbox ID, you can connect to the sandbox using the 
Sandbox.connect()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

connect

(sandboxId)

// Now you can use the sandbox as usual

// ...

const

 result

 =

 await

 sandbox.commands.

run

(

"whoami"

)

console.

log

(

`Running in sandbox ${

sandbox

.

sandboxId

} as "${

result

.

stdout

.

trim

()

}"`

)

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Internet access

Next

⌘
I

On this page

1. Get the sandbox ID

2. Connect to the sandbox

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/internet-access

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Internet access

Every sandbox has access to the internet and can be reached by a public URL.

​

Controlling internet access

You can control whether a sandbox has access to the internet by using the 
allowInternetAccess
 parameter when creating a sandbox. By default, internet access is enabled (
true
), but you can disable it for security-sensitive workloads.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Create sandbox with internet access enabled (default)

const

 sandbox

 =

 await

 Sandbox.

create

({ allowInternetAccess: 

true

 })

// Create sandbox without internet access

const

 isolatedSandbox

 =

 await

 Sandbox.

create

({ allowInternetAccess: 

false

 })

When internet access is disabled, the sandbox cannot make outbound network connections, which provides an additional layer of security for sensitive code execution.

Setting 
allowInternetAccess
 to 
false
 is equivalent to setting 
network.denyOut
 to 
[&#x27;0.0.0.0/0&#x27;]
 (denying all traffic).

​

Fine-grained network control

For more granular control over network access, you can use the 
network
 configuration option to specify allow and deny lists for outbound traffic.

​

Allow and deny lists

You can specify IP addresses, CIDR blocks, or domain names that the sandbox is allowed to use:

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox, ALL_TRAFFIC } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Deny all traffic except specific IPs

const

 sandbox

 =

 await

 Sandbox.

create

({

  network: {

    denyOut: [

ALL_TRAFFIC

],

    allowOut: [

&#x27;1.1.1.1&#x27;

, 

&#x27;8.8.8.0/24&#x27;

]

  }

})

// Deny specific IPs only

const

 restrictedSandbox

 =

 await

 Sandbox.

create

({

  network: {

    denyOut: [

&#x27;8.8.8.8&#x27;

]

  }

})

​

Domain-based filtering

You can allow traffic to specific domains by specifying hostnames in 
allow out
. When using domain-based filtering, you must include 
ALL_TRAFFIC
 in 
deny out
 to block all other traffic. Domains are not supported in the 
deny out
 list.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox, ALL_TRAFFIC } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Allow only traffic to google.c

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/pty

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Interactive terminal (PTY)

The PTY (pseudo-terminal) module allows you to create interactive terminal sessions in the sandbox with real-time, bidirectional communication.

Unlike 
commands.run()
 which executes a command and returns output after completion, PTY provides:

Real-time streaming
 - Output is streamed as it happens via callbacks

Bidirectional input
 - Send input while the terminal is running

Interactive shell
 - Full terminal support with ANSI colors and escape sequences

Session persistence
 - Disconnect and reconnect to running sessions

​

Create a PTY session

Use 
sandbox.pty.create()
 to start an interactive bash shell.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 terminal

 =

 await

 sandbox.pty.

create

({

  cols: 

80

,              

// Terminal width in characters

  rows: 

24

,              

// Terminal height in characters

  onData

: (

data

) 

=>

 {

    // Called whenever terminal outputs data

    process.stdout.

write

(data)

  },

  envs: { MY_VAR: 

&#x27;hello&#x27;

 },  

// Optional environment variables

  cwd: 

&#x27;/home/user&#x27;

,          

// Optional working directory

  user: 

&#x27;root&#x27;

,               

// Optional user to run as

})

// terminal.pid contains the process ID

console.

log

(

&#x27;Terminal PID:&#x27;

, terminal.pid)

The PTY runs an interactive bash shell with 
TERM=xterm-256color
, which supports ANSI colors and escape sequences.

​

Timeout

PTY sessions have a configurable timeout that controls the session duration. The default is 60 seconds. For interactive or long-running sessions, set 
timeoutMs: 0
 (JavaScript) or 
timeout=0
 (Python) to keep the session open indefinitely.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 terminal

 =

 await

 sandbox.pty.

create

({

  cols: 

80

,

  rows: 

24

,

  onData

: (

data

) 

=>

 process.stdout.

write

(data),

  timeoutMs: 

0

,  

// Keep the session open indefinitely

})

​

Send input to PTY

Use 
sendInput()
 in JavaScript or 
send_stdin(

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/ssh-access

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

SSH access

SSH access enables remote terminal sessions, SCP/SFTP file transfers, and integration with tools that expect SSH connectivity.

​

Quickstart

1

Build the SSH template

Define a template with OpenSSH server and 
websocat
:

JavaScript & TypeScript

Python

Copy

Ask AI

// template.ts

import

 { Template, waitForPort } 

from

 &#x27;e2b&#x27;

export

 const

 template

 =

 Template

()

  .

fromUbuntuImage

(

&#x27;25.04&#x27;

)

  .

aptInstall

([

&#x27;openssh-server&#x27;

])

  .

runCmd

([

    &#x27;curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl&#x27;

,

    &#x27;chmod a+x /usr/local/bin/websocat&#x27;

,

  ], { user: 

&#x27;root&#x27;

 })

  .

setStartCmd

(

&#x27;sudo websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22&#x27;

, 

waitForPort

(

8081

))

Build the template:

JavaScript & TypeScript

Python

Copy

Ask AI

// build.ts

import

 { Template, defaultBuildLogger } 

from

 &#x27;e2b&#x27;

import

 { template 

as

 sshTemplate } 

from

 &#x27;./template&#x27;

await

 Template.

build

(sshTemplate, 

&#x27;ssh-ready&#x27;

, {

  cpuCount: 

2

,

  memoryMB: 

2048

,

  onBuildLogs: 

defaultBuildLogger

(),

})

2

Create a sandbox from the template

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sbx

 =

 await

 Sandbox.

create

(

&#x27;ssh-ready&#x27;

)

console.

log

(sbx.sandboxId)

3

Connect from your machine

macOS

Linux

Copy

Ask AI

# Install websocat

brew

 install

 websocat

# Connect to your sandbox

ssh

 -o

 &#x27;ProxyCommand=websocat --binary -B 65536 - wss://8081-%h.e2b.app&#x27;

 user@

<

sandbox-i

d

>

​

How it works

This method uses 
websocat
 to proxy SSH connections over WebSocket through the sandbox’s exposed ports.

Copy

Ask AI

┌───────────────────────────────────────────────────────────┐

│  Your Machine                                             │

│  ┌──────────┐    ProxyCommand    ┌──────────────────┐     │

│  │   SSH    │ ────────────────── │    websocat      │     │

│  │  Client  │                    │   (WebSocket)    │     │

│  └──────────┘                    └─────────┬────────┘     │

└─────

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/connect-bucket

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Connecting storage bucket to the sandbox

To connect a bucket for storing data from the sandbox, we will use the FUSE file system to mount the bucket to the sandbox.

You will need to create a custom sandbox template with the FUSE file system installed. The guide for building a custom sandbox template can be found 
here
.

​

Google Cloud Storage

​

Prerequisites

To use Google Cloud Storage, you’ll need a bucket and a service account. You can create a service account 
here
 and a bucket 
here
.

If you want to write to the bucket, make sure the service account has the 
Storage Object User
 role for this bucket.

You can find a guide on creating a service account key 
here
.

​

Mounting the bucket

To use the Google Cloud Storage we need to install the 
gcsfuse
 package. There’s simple 
template
 that can be used to create a container with the 
gcsfuse
 installed.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 template

 =

 Template

()

  .

fromTemplate

(

"code-interpreter-v1"

)

  .

aptInstall

([

"gnupg"

, 

"lsb-release"

])

  .

runCmd

(

"lsb_release -c -s > /tmp/lsb_release"

)

  .

runCmd

(

    &#x27;GCSFUSE_REPO=$(cat /tmp/lsb_release) && echo "deb [signed-by=/usr/share/keyrings/cloud.google.asc] https://packages.cloud.google.com/apt gcsfuse-$GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list&#x27;

,

  )

  .

runCmd

(

    "curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo tee /usr/share/keyrings/cloud.google.asc"

,

  )

  .

aptInstall

([

"gcsfuse"

])

The bucket is mounted during the sandbox runtime using the 
gcsfuse
 command.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;<your template id>&#x27;

)

await

 sandbox.files.

makeDir

(

&#x27;/home/user/bucket&#x27;

)

await

 sandbox.files.

write

(

&#x27;key.json&#x27;

, 

&#x27;<your service account key>&#x27;

)

await

 sandbox.commands.

run

(

&#x27;sudo gcsfuse <flags> --key-file /home/user/key.json <bucket-name> /home/user/bucket&#x27;

)

​

Flags

The complete list of flags is available 
here
.

​

Allow the default user to access the files

To allow the default user to access the files, we can use t

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/rate-limits

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Rate limits

This page describes API and sandbox rate limits of the E2B platform.

​

Table of Contents

Sandbox lifecycle and management API

Sandbox operations and requests to sandboxes

Concurrent Sandboxes

Sandbox creation rate

Egress connections

Reaching limits

Increasing and avoiding rate limits

Here’s a limits breakdown table based on the plan:

Plan

Hobby

Pro

Enterprise

Sandbox lifecycle & management API

20,000 / 30s

20,000 / 30s

Custom

Sandbox operations

40,000 / 60s per IP

40,000 / 60s per IP

Custom

Concurrent sandboxes

20

100 - 1,100

*

Custom

Sandbox creation rate

1 / sec

5 / sec

Custom

Egress connections per sandbox

2,500

2,500

Custom

*

Pro plan default is 100 concurrent sandboxes. Higher concurrency of up to 1,100 is available as a separate purchasable add-on.

​

Sandbox lifecycle and management API

20,000 requests per 30 seconds

This rate limit applies to lifecycle and management operations such as sandbox create, kill, update, list, and other.

​

Sandbox operations and requests to sandboxes

40,000 requests per 60 seconds

This rate limits applies to operations to/within running sandboxes such as running code, listing files, running commands, etc.
This also includes requests made to custom ports in the sandbox.

 This limit is enforced globally across all sandbox operations from a single IP address.

​

Concurrent sandboxes

Number of concurrent sandboxes differs based on the pricing tier.

​

Hobby tier

Up to 20 concurrent sandboxes

​

Pro tier

Starts at 100 concurrent sandboxes

Can go up to 1,100 with additional 
add-ons available for purchase
.

​

Enterprise tier

Custom limit - 1,100+ concurrent sandboxes

​

Sandbox creation rate

This limit controls how quickly you can create new sandboxes.

​

Hobby tier

1 sandbox per second

​

Pro tier

5 sandboxes per second

​

Enterprise tier

Custom limit - 5+ sandboxes per second

​

Egress connections

2,500 connections per sandbox

This limit controls the maximum number of outbound (egress) network connections that can be established from a single sandbox.

​

Reaching limits

When you reach the limits of your plan, subsequent requests/function calls will be effectively dropped and return the following:

the 
429 Too Many Requests
 HTTP st

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/secured-access

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Secured access

Secure access authenticates communication between SDK and sandbox controller.

Sandbox controller runs in sandbox itself and exposes APIs for work with file system, run commands, and generally control the sandbox via our SDK.
Without secure access, anyone with a sandbox ID can access the controller APIs and control the sandbox from inside.

SDKs version 
v2.0.0
 and above are using secure access by default when creating sandbox. This may not be compatible with older custom templates and you may need to rebuild them.

​

Migration path

When using custom templates created before envd 
v0.2.0
, you need to rebuild the templates to enable secure access.
Temporarily, you can disable secure access by setting 
secure
 to 
false
 during sandbox creation, but this is not recommended for production use because it increases security risks.

You can check the template envd version using the 
e2b template list
 command or by viewing the templates list on the dashboard.

​

Supported versions

All sandboxes based on templates with envd version at least 
v0.2.0
 already support secure access without any additional changes.

The secure access flag was introduced in 
1.5.0
 for JavaScript and Python SDKs to be used optionally.
Starting with SDK version 
v2.0.0
, sandboxes are created with secure access enabled by default.

​

Access sandbox API directly

In some cases, you might want to access sandbox controller APIs directly through its URL, such as when you are not using SDKs.
When secure access is enabled, you must provide an authentication token that was returned during sandbox creation.

Each call to the sandbox controller must include an additional header 
X-Access-Token
 with the access token value returned during sandbox creation.

For sandbox 
upload
 and 
download
 URLs, you need to generate pre-signed URLs. We are advising to use SDK for generating presigned URLs.

​

Disable secure access

Disabling secured access is discouraged because it creates security vulnerabilities.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

({ secure: 

false

 }) 

// Explicitly disable

Was this page helpful?

Yes

No

Suggest edits

Raise 

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/ip-tunneling

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Proxy tunneling

​

Setting up proxy tunneling

We will set up a proxy server on a GCP VM instance running 
Shadowsocks
 and use it to tunnel the Sandbox network traffic.
This will allow you to use a dedicated IP address for outgoing requests.

​

GCP VM setup

Create a firewall rule to allow all tcp/udp traffic to port 8388.

Replace 
your-project-id
 with your actual project ID.

Copy

Ask AI

gcloud

 compute

 firewall-rules

 create

 shadowsocks

 \

    --project=your-project-id

 \

    --direction=INGRESS

 \

    --priority=1000

 \

    --network=default

 \

    --action=ALLOW

 \

    --rules=tcp:8388,udp:8388

 \

    --source-ranges=0.0.0.0/0

 \

    --target-tags=allow-shadowsocks

Create a VM instance with the following tags: 
allow-shadowsocks
.

Replace 
your-project-id
 with your actual project ID.

Copy

Ask AI

gcloud

 compute

 instances

 create

 shadowsocks-vm

 \

    --project=your-project-id

 \

    --zone=us-west1-a

 \

    --machine-type=n2-standard-2

 \

    --can-ip-forward

 \

    --tags=allow-shadowsocks

 \

    --image-project=debian-cloud

 \

    --image-family=debian-12

 \

    --boot-disk-size=20GB

After the VM is created, you can connect to it using the following command:

Replace 
your-project-id
 with your actual project ID.

Copy

Ask AI

# May take a few seconds until the instance is ready to accept SSH connections

gcloud

 compute

 ssh

 shadowsocks-vm

 \

    --project=your-project-id

 \

    --zone=us-west1-a

​

Shadowsocks server setup (VM)

SSH into the VM and follow the instructions below to install and configure Shadowsocks.

Install the necessary packages, if missing:

Copy

Ask AI

sudo

 apt

 update

sudo

 apt

 install

 -y

 wget

 tar

Download and install Shadowsocks (v1.24.0):

Copy

Ask AI

wget

 https://github.com/shadowsocks/shadowsocks-rust/releases/latest/download/shadowsocks-v1.24.0.x86_64-unknown-linux-gnu.tar.xz

tar

 -xf

 shadowsocks-

*

.tar.xz

sudo

 mv

 ssserver

 ssmanager

 ssurl

 /usr/local/bin/

Create a shadowsocks configuration file:

Replace 
STRONG_PASSWORD_HERE
 with your own password.

/etc/shadowsocks/server.json

Copy

Ask AI

{

    "server"

: 

"0.0.0.0"

,

    "server_port"

: 

8388

,

    "password"

: 

"STRONG_PASSWORD_HERE"

,



...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/sandbox/custom-domain

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Sandbox

Custom domain

How to set up a custom domain for Sandboxes hosted on E2B.

We will set up a GCP VM running Caddy server with Docker and Cloudflare DNS to proxy the requests to the Sandboxes.

Example: 
8080-sandboxid.mydomain.com
 -> 
8080-sandboxid.e2b.app

​

Prerequisites

Domain name registered and configured with Cloudflare DNS.

Cloudflare API Token that allows you to manage DNS records.

​

GCP VM setup

Create a VM instance by running the following command:

Replace 
your-project-id
 with your actual project ID.

Copy

Ask AI

gcloud

 compute

 instances

 create

 e2b-custom-domain-proxy

 \

    --project=your-project-id

 \

    --zone=us-west1-a

 \

    --machine-type=n2-standard-2

 \

    --can-ip-forward

 \

    --tags=http-server,https-server

 \

    --image-project=debian-cloud

 \

    --image-family=debian-12

 \

    --boot-disk-size=20GB

After the VM is created, you can connect to it using the following command:

Replace 
your-project-id
 with your actual project ID.

Copy

Ask AI

# May take a few seconds until the instance is ready to accept SSH connections

gcloud

 compute

 ssh

 e2b-custom-domain-proxy

 \

    --project=your-project-id

 \

    --zone=us-west1-a

​

Server setup

Install the latest stable version of Docker:

Copy

Ask AI

curl

 -fsSL

 https://get.docker.com

 |

 sudo

 sh

Create a Dockerfile that will be used to build the Caddy server image with Cloudflare DNS:

Dockerfile

Copy

Ask AI

FROM

 caddy:builder 

AS

 builder

RUN

 xcaddy build \

    --with github.com/caddy-dns/cloudflare

FROM

 caddy:latest

COPY

 --from=builder /usr/bin/caddy /usr/bin/caddy

Create a Docker Compose file that will be used to start the Caddy server:

docker-compose.yml

Copy

Ask AI

services

:

    caddy

:

        build

:

            context

: 

.

            dockerfile

: 

Dockerfile

        container_name

: 

caddy-proxy

        restart

: 

unless-stopped

        ports

:

            - 

"80:80"

            - 

"443:443"

            - 

"443:443/udp"

  # Optional: HTTP/3

        volumes

:

            - 

./Caddyfile:/etc/caddy/Caddyfile

            - 

caddy_data:/data

            - 

caddy_config:/config

        environment

:

            - 

CLOUDFLARE_API_TOKEN=${CLOUDFLARE_API

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/quickstart

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Quickstart

E2B templates allow you to define custom sandboxes.
You can define the base image, environment variables, files to copy, commands to run, and
a 
start command
 that runs during the template build and is captured in a snapshot — so the process is 
already running
 when you create a sandbox from that template.
This gives you fully configured sandboxes with running processes ready to use with zero wait time for your users.

There are two ways how you can start creating a new template:

using the CLI

manually using the SDK

​

CLI

You can use the E2B CLI to create a new template.

1

Install the E2B CLI

Install the latest version of the 
E2B CLI

2

Initialize a new template

Copy

Ask AI

e2b

 template

 init

3

Follow the prompts

Follow the prompts to create a new template.

4

Done

Check the generated 
README.md
 file to see how to build and use your new template.

​

Manual

​

Install the packages

Requires the E2B SDK version at least 2.3.0

JavaScript & TypeScript

Python

Copy

Ask AI

npm

 install

 e2b

 dotenv

Create the 
.env
 file

Copy

Ask AI

E2B_API_KEY

=

e2b_***

​

Create a new template file

Create a template file with the following name and content

JavaScript & TypeScript

Python

Copy

Ask AI

// template.ts

import

 { Template, waitForTimeout } 

from

 &#x27;e2b&#x27;

;

export

 const

 template

 =

 Template

()

  .

fromBaseImage

()

  .

setEnvs

({

    HELLO: 

"Hello, World!"

,

  })

  .

setStartCmd

(

"echo $HELLO"

, 

waitForTimeout

(

5_000

));

​

Create a development build script

JavaScript & TypeScript

Python

Copy

Ask AI

// build.dev.ts

import

 &#x27;dotenv/config&#x27;

;

import

 { Template, defaultBuildLogger } 

from

 &#x27;e2b&#x27;

;

import

 { template } 

from

 &#x27;./template&#x27;

;

async

 function

 main

() {

  await

 Template.

build

(template, 

&#x27;template-tag-dev&#x27;

, {

    cpuCount: 

1

,

    memoryMB: 

1024

,

    onBuildLogs: 

defaultBuildLogger

(),

  });

}

main

().

catch

(console.error);

​

Create a production build script

JavaScript & TypeScript

Python

Copy

Ask AI

// build.prod.ts

import

 &#x27;dotenv/config&#x27;

;

import

 { Template, defaultBuildLogger } 

from

 &#x27;e2b&#x27;

;

import

 { template 

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/how-it-works

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

How it works

​

General overview

Every time you are building a sandbox template, we create a container based on the definition.
We extract the container’s filesystem, do provisioning and configuration (e.g. installing required dependencies), run layers commands and start a sandbox.

Then, these steps happen:

We take the running sandbox.

(Only if you specified the 
start command
, otherwise this step is skipped) Execute the start command.

Wait for readiness (by default 20 seconds if start command is specified, otherwise immediately ready). Readiness check can be configured using 
ready command
.

Snapshot the sandbox and make it ready for you to spawn it with the SDK.

We call this sandbox snapshot a 
sandbox template
.

Snapshots are saved running sandboxes. We serialize and save the whole sandbox’s filesystem together with all the
running processes in a way that can be loaded later.

This allows us to load the sandbox in ~80ms any time later with all the processes already running
and the filesystem exactly as it was.

​

Default user and workdir

To learn more about default user and workdir, please refer to the 
User and workdir
 section.

​

Caching

To learn more about caching, please refer to the 
Caching
 section.

​

Kernel

E2B sandboxes run on an 
LTS 6.1 Linux kernel
.

The exact kernel version available in your sandbox depends on 
when your template was built
:

Template build date (DD.MM.YYYY)

Kernel version

≥ 27.11.2025

6.1.158 (current)

< 27.11.2025

6.1.102

Note:

Kernel versions are fixed at 
template build time
.

If your template was created on an older kernel, 
the kernel cannot be upgraded or changed
 for that template.

To use a newer kernel, you must 
rebuild the template
 or create a new one.

You can find the kernel configuration files for each version 
here
.

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

User and workdir

Default user and working directory in the sandbox and template

Next

⌘
I

On this page

General overview

Default user and workdir

Caching

Kernel

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/user-and-workdir

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

User and workdir

The default user in the template is 
user
 with the 
/home/user
 (home directory) as the working directory.
This is different from the Docker defaults, where the default user is 
root
 with 
/
 as the working directory. This is to help with tools installation, and to improve default security.

The last set user and workdir in the template is then persisted as a default to the sandbox execution.
Example of setting user and workdir in the template definition are below.

Requires the E2B SDK version at least 2.3.0

​

Default user and workdir in sandbox

JavaScript & TypeScript

Python

Copy

Ask AI

const

 sbx

 =

 await

 Sandbox.

create

()

await

 sbx.commands.

run

(

"whoami"

) 

// user

await

 sbx.commands.

run

(

"pwd"

) 

// /home/user

​

Custom user and workdir template

JavaScript & TypeScript

Python

Copy

Ask AI

// template.ts

const

 template

 =

 Template

()

  .

fromBaseImage

()

  .

runCmd

(

"whoami"

) 

// user

  .

runCmd

(

"pwd"

) 

// /home/user

  .

setUser

(

"guest"

)

  .

runCmd

(

"whoami"

) 

// guest

  .

runCmd

(

"pwd"

) 

// /home/guest

// build_dev.ts

await

 Template.

build

(template, 

&#x27;custom-user-template&#x27;

, {

  onBuildLogs: 

defaultBuildLogger

()

})

// index.ts

const

 sbx

 =

 await

 Sandbox.

create

(

"custom-user-template"

)

await

 sbx.commands.

run

(

"whoami"

) 

// guest

await

 sbx.commands.

run

(

"pwd"

) 

// /home/guest

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Caching

How the caching process works

Next

⌘
I

On this page

Default user and workdir in sandbox

Custom user and workdir template

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/caching

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Caching

The caching concept is similar to 
Docker’s layer caching
. For each layer command (
.copy()
, 
.runCmd()
, 
.setEnvs()
, etc.), we create a new layer on top of the existing.
Each layer is cached based on the command and its inputs (e.g., files copied, command executed, environment variables set).
If a layer command is unchanged and its inputs are the same as in any previous build, we reuse the cached layer instead of rebuilding it.

This significantly speeds up the build process, especially for large templates with many layers.
The cache is scoped to the team, so even if you have multiple templates, they can share the same cache if they have identical layers.

​

Invalidation

You can invalidate the caches only partially, or for the whole template.

​

Partial

Force rebuild from the next instruction, use the method:

JavaScript & TypeScript

Python

Copy

Ask AI

const

 template

 =

 Template

()

  .

fromBaseImage

()

  .

skipCache

()

  .

runCmd

(

"echo &#x27;Hello, World!&#x27;"

)

This will force rebuild from the next instruction, invalidating the cache for all subsequent instructions in the template.

​

Whole template

To force rebuild the whole template, you can use also 
skipCache
/
skip_cache
 parameter in the 
Template.build
 method:

JavaScript & TypeScript

Python

Copy

Ask AI

Template.

build

(template, 

&#x27;my-template&#x27;

, {

  skipCache: 

true

, 

// Configure cache skip (except for files)

})

This will skip the cache usage for the whole template build.

​

Files caching

When using the 
.copy()
 command, we cache the files based on their content. If the files haven’t changed since the last build, we reuse them from the files cache.

We differ from Docker here. Because we build the template on our infrastructure, we use improved caching on files level.
Even if you invalidate the layer before 
.copy()
 (e.g., by changing ENV variables), we’ll reuse the already uploaded files.
The 
copy()
 command will still be re-executed, but the files for the layer will be reused from the files cache, no need to upload them from your computer again.

To invalidate the cache for all subsequent instructions in the template 
AND
 the layer files cache, use the 
forceUpload
/
force_upload
 parameter.

JavaScript 

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/base-image

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Base image

​

Creating template

When creating a template, you can specify options:

JavaScript & TypeScript

Python

Copy

Ask AI

const

 template

 =

 Template

({

  fileContextPath: 

"."

, 

// Custom file context path

  fileIgnorePatterns: [

".git"

, 

"node_modules"

], 

// File patterns to ignore

});

File ignoring
: The SDK automatically reads 
.dockerignore
 files and combines them with your 
fileIgnorePatterns
 (TypeScript) or 
file_ignore_patterns
 (Python). Files matching these patterns are excluded from uploads and hash calculations.

​

Defining base image

Every template starts with a base image that provides the foundation for your sandbox environment.

​

Predefined base images

Use convenience methods for common base images with Ubuntu, Debian, Python, Node.js, or Bun:

JavaScript & TypeScript

Python

Copy

Ask AI

template.

fromUbuntuImage

(

"22.04"

); 

// ubuntu:22.04

template.

fromDebianImage

(

"stable-slim"

); 

// debian:stable-slim

template.

fromPythonImage

(

"3.13"

); 

// python:3.13

template.

fromNodeImage

(

"lts"

); 

// node:lts

template.

fromBunImage

(

"1.3"

); 

// oven/bun:1.3

​

Custom base image

Use any Docker image from Docker Hub or other registries:

JavaScript & TypeScript

Python

Copy

Ask AI

template.

fromImage

(

"custom-image:latest"

);

​

Default E2B base image

Use the default E2B base image, which comes pre-configured for sandbox environments:

JavaScript & TypeScript

Python

Copy

Ask AI

template.

fromBaseImage

(); 

// e2bdev/base

​

Build from existing template

Extend an existing template from your team or organization:

JavaScript & TypeScript

Python

Copy

Ask AI

template.

fromTemplate

(

"my-template"

); 

// Your team&#x27;s template

template.

fromTemplate

(

"acme/other-template"

); 

// Full namespaced reference

You can only call base image methods once per template. Subsequent calls will throw an error.

​

Parsing existing Dockerfiles

Convert existing Dockerfiles to template format using 
fromDockerfile()
:

JavaScript & TypeScript

Python

Copy

Ask AI

const

 dockerfileContent

 =

 `

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y curl

WORKDIR /app

COPY . .

ENV NODE_ENV=production

ENV PORT=3000

USER appuse

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/private-registries

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Private registries

If your base image is hosted in a private registry, you can provide credentials using the following helpers:

General registry

GCP Artifact Registry

AWS ECR

​

General registry

JavaScript & TypeScript

Python

Copy

Ask AI

Template

().

fromImage

(

&#x27;ubuntu:22.04&#x27;

, {

  username: 

&#x27;user&#x27;

,

  password: 

&#x27;pass&#x27;

,

})

​

GCP Artifact Registry

JavaScript & TypeScript

Python

Copy

Ask AI

// From file path

Template

().

fromGCPRegistry

(

&#x27;ubuntu:22.04&#x27;

, {

  serviceAccountJSON: 

&#x27;./service_account.json&#x27;

,

})

// From object

Template

().

fromGCPRegistry

(

&#x27;ubuntu:22.04&#x27;

, {

  serviceAccountJSON: { project_id: 

&#x27;123&#x27;

, private_key_id: 

&#x27;456&#x27;

 },

})

​

AWS ECR

JavaScript & TypeScript

Python

Copy

Ask AI

Template

().

fromAWSRegistry

(

&#x27;ubuntu:22.04&#x27;

, {

  accessKeyId: 

&#x27;123&#x27;

,

  secretAccessKey: 

&#x27;456&#x27;

,

  region: 

&#x27;us-west-1&#x27;

,

})

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Defining template

How to create your own template

Next

⌘
I

On this page

General registry

GCP Artifact Registry

AWS ECR

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/defining-template

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Defining template

​

Method chaining

All template methods return the template instance, allowing for fluent API usage:

JavaScript & TypeScript

Python

Copy

Ask AI

const

 template

 =

 Template

()

  .

fromUbuntuImage

(

"22.04"

)

  .

aptInstall

([

"curl"

]) 

// necessary for waitForPort

  .

setWorkdir

(

&#x27;/app&#x27;

)

  .

copy

(

"package.json"

, 

"/app/package.json"

)

  .

runCmd

(

"npm install"

)

  .

setStartCmd

(

"npm start"

, 

waitForPort

(

3000

));

​

User and workdir

Set the working directory and user for the template:

JavaScript & TypeScript

Python

Copy

Ask AI

// Set working directory

template.

setWorkdir

(

"/app"

);

// Set user (runs subsequent commands as this user)

template.

setUser

(

&#x27;node&#x27;

)

template.

setUser

(

"1000:1000"

); 

// User ID and group ID

​

Copying files

Copy files from your local filesystem to the template:

JavaScript & TypeScript

Python

Copy

Ask AI

// Copy a single file

template.

copy

(

"package.json"

, 

"/app/package.json"

);

// Copy multiple files to same destination

template.

copy

([

"file1"

, 

"file2"

], 

"/app/file"

)

// Multiple copy operations using copyItems

template.

copyItems

([

  { src: 

"src/"

, dest: 

"/app/src/"

 },

  { src: 

"package.json"

, dest: 

"/app/package.json"

 },

]);

// Copy with user and mode options

template.

copy

(

"config.json"

, 

"/app/config.json"

, {

  user: 

"appuser"

,

  mode: 

0o644

,

});

​

File operations

Perform various file operations during template build:

JavaScript & TypeScript

Python

Copy

Ask AI

// Remove files or directories

template.

remove

(

"/tmp/temp-file.txt"

);

template.

remove

(

"/old-directory"

, { recursive: 

true

 });

template.

remove

(

"/file.txt"

, { force: 

true

 });

// Rename files or directories

template.

rename

(

"/old-name.txt"

, 

"/new-name.txt"

);

template.

rename

(

"/old-dir"

, 

"/new-dir"

, { force: 

true

 });

// Create directories

template.

makeDir

(

"/app/logs"

);

template.

makeDir

(

"/app/data"

, { mode: 

0o755

 });

// Create symbolic links

template.

makeSymlink

(

"/app/data"

, 

"/app/logs/data"

);

​

Installing packages

Install packages using package ma

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/start-ready-command

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Start & ready commands

​

Start command

The start command lets you specify a process that runs at the 
end of the template build
 — not when a sandbox is created.
During the build, E2B executes the start command, waits for the 
ready command
 to confirm the process is up, and then takes a 
snapshot
 of the entire sandbox including the running process.

When you later create a sandbox from that template, the snapshotted process is 
already running
 — there is no startup wait.
This is how you get servers, seeded databases, or any long-running process available instantly when spawning sandboxes with the SDK.

The start command runs 
once during template build
 and is captured in a snapshot. It does not re-execute each time you create a sandbox. If you need to run a command every time a sandbox is created, use 
sandbox.commands.run()
 after creating the sandbox instead.

This also means that 
environment variables passed to 
Sandbox.create()

 are 
not available
 to the start command process — it already ran during the build. If your start command needs environment variables, set them in the template definition using 
setEnvs()
 / 
set_envs()
.

You can see the full build process 
here
.

​

Ready command

The ready command allows you to specify a command that will determine 
template sandbox
 readiness before a 
snapshot
 is created.
It is executed in an infinite loop until it returns a successful 
exit code 0
.
This way you can control how long should we wait for the 
start command
 or any system state.

​

Usage

Set the start command (executed during template build) and the ready command (determines when the process is up before snapshotting):

JavaScript & TypeScript

Python

Copy

Ask AI

// Set both start command and ready command

template.

setStartCmd

(

&#x27;npm start&#x27;

, 

waitForPort

(

3000

))

// Set custom start and ready command

template.

setStartCmd

(

&#x27;npm start&#x27;

, 

&#x27;curl -s -o /dev/null -w "200"&#x27;

)

// Set only ready command

template.

setReadyCmd

(

waitForTimeout

(

10_000

))

The ready command is used to determine when the sandbox is ready to accept connections.

​

Ready command helpers

The SDK provides helper functions for common ready command patterns:

JavaScript & TypeScript

P

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/build

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Build

​

Build and wait for completion

The 
build
 method builds the template and waits for the build to complete. It returns build information including the template ID and build ID.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 buildInfo

 =

 await

 Template.

build

(template, 

&#x27;my-template&#x27;

, {

  cpuCount: 

2

, 

// CPU cores

  memoryMB: 

2048

, 

// Memory in MB

  skipCache: 

false

, 

// Configure cache skip (except for files)

  onBuildLogs: 

defaultBuildLogger

(), 

// Log callback receives LogEntry objects

  apiKey: 

&#x27;your-api-key&#x27;

, 

// Override API key

  domain: 

&#x27;your-domain&#x27;

, 

// Override domain

})

// buildInfo contains: { name, templateId, buildId }

​

Build in background

The 
buildInBackground
 method starts the build process and returns immediately without waiting for completion. This is useful when you want to trigger a build and check its status later.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 buildInfo

 =

 await

 Template.

buildInBackground

(template, 

&#x27;my-template&#x27;

, {

  cpuCount: 

2

,

  memoryMB: 

2048

,

})

// Returns immediately with: { name, templateId, buildId }

​

Check build status

Use 
getBuildStatus
 to check the status of a build started with 
buildInBackground
.

JavaScript & TypeScript

Python

Copy

Ask AI

const

 status

 =

 await

 Template.

getBuildStatus

(buildInfo, {

  logsOffset: 

0

, 

// Optional: offset for fetching logs

})

// status contains: { status: &#x27;building&#x27; | &#x27;ready&#x27; | &#x27;error&#x27;, logEntries: [...] }

​

Example: Background build with status polling

JavaScript & TypeScript

Python

Copy

Ask AI

// Start build in background

const

 buildInfo

 =

 await

 Template.

buildInBackground

(template, 

&#x27;my-template&#x27;

, {

  cpuCount: 

2

,

  memoryMB: 

2048

,

})

// Poll for build status

let

 logsOffset 

=

 0

let

 status 

=

 &#x27;building&#x27;

while

 (status 

===

 &#x27;building&#x27;

) {

  const

 buildStatus

 =

 await

 Template.

getBuildStatus

(buildInfo, {

    logsOffset,

  })

  logsOffset 

+=

 buildStatus.logEntries.

length

  status 

=

 buildStatus.status

  buildStatus.logEntries.

forEach

(

    (

logE

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/names

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Template names

Template names are unique identifiers used to reference and create sandboxes from your templates. They serve as human-readable names that make it easy to identify and use your templates across your applications.

​

What is a template name?

A name is a string identifier that you assign to a template when building it. Once a template is built with a name, you can use that name to create sandboxes from the template.

JavaScript & TypeScript

Python

Copy

Ask AI

// Build a template with a name

await

 Template.

build

(template, 

&#x27;my-python-env&#x27;

, {

  cpuCount: 

2

,

  memoryMB: 

2048

,

})

// Create a sandbox using the name

const

 sandbox

 =

 await

 Sandbox.

create

(

&#x27;my-python-env&#x27;

)

​

Team-local naming

Template names are scoped to your team. This means:

Your template named 
my-app
 is stored as 
your-team-slug/my-app

You can reference it simply as 
my-app
 within your team

Other teams can have their own 
my-app
 template without conflict

Public templates should be referenced using the full namespaced format (
team-slug/template-name
)

Backwards Compatibility
: Existing public templates remain accessible without the team slug prefix. New public templates should be referenced using the full namespaced format (
team-slug/template-name
).

​

Common use cases

​

Development and production environments

Use different names for different environments:

JavaScript & TypeScript

Python

Copy

Ask AI

// Development template

await

 Template.

build

(template, 

&#x27;myapp-dev&#x27;

, {

  cpuCount: 

1

,

  memoryMB: 

1024

,

})

// Production template

await

 Template.

build

(template, 

&#x27;myapp-prod&#x27;

, {

  cpuCount: 

4

,

  memoryMB: 

4096

,

})

​

Multiple template variants

Create different variants of the same template with different configurations:

JavaScript & TypeScript

Python

Copy

Ask AI

// Small instance

await

 Template.

build

(template, 

&#x27;myapp-small&#x27;

, {

  cpuCount: 

1

,

  memoryMB: 

512

,

})

// Large instance

await

 Template.

build

(template, 

&#x27;myapp-large&#x27;

, {

  cpuCount: 

8

,

  memoryMB: 

8192

,

})

When building variants with the same template definition but different CPU/RAM configurations, 

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/tags

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Template tags & versioning

Template versioning allows you to maintain multiple versions of the same template using tags. This enables workflows like semantic versioning, environment-based deployments, and gradual rollouts.

​

Tag format

Tags follow the 
name:tag
 format, where 
name
 is your template’s identifier and 
tag
 is the version label.

Copy

Ask AI

my-template:v1.0.0              // Within your team

my-template:production          // Within your team

acme/my-template:v1.0.0         // Full namespaced reference

​

The default tag

When you build or reference a template without specifying a tag, E2B uses the 
default
 tag automatically. This means:

my-template
 is equivalent to 
my-template:default

Existing templates without tags continue to work seamlessly

JavaScript & TypeScript

Python

Copy

Ask AI

// These are equivalent

const

 sandbox1

 =

 await

 Sandbox.

create

(

&#x27;my-template&#x27;

)

const

 sandbox2

 =

 await

 Sandbox.

create

(

&#x27;my-template:default&#x27;

)

​

Building with tags

You can build templates with one or more tags to create versioned builds.

​

Single tag

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Template } 

from

 &#x27;e2b&#x27;

// Build with a specific version tag

await

 Template.

build

(template, 

&#x27;my-template:v1.0.0&#x27;

)

​

Multiple tags

Build with multiple tags to assign several version labels to the same build artifact.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Template } 

from

 &#x27;e2b&#x27;

// Build with multiple tags pointing to the same artifact

await

 Template.

build

(template, 

&#x27;my-template&#x27;

, { tags: [

&#x27;v1.2.0&#x27;

, 

&#x27;latest&#x27;

] })

​

Managing tags

You can manage tags on existing template builds without rebuilding.

​

Assign tags

Assign new tag(s) to an existing build. This is useful for promoting a tested version to production or marking a version as stable.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Template } 

from

 &#x27;e2b&#x27;

// Assign a single tag

await

 Template.

assignTags

(

&#x27;my-template:v1.2.0&#x27;

, 

&#x27;production&#x27;

)

// Assign multiple tags at once

await

 Template.

assignTags

(

&#x27;my-template:v1.2.0&#x27;


...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/logging

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Logging

You can retrieve the build logs using the SDK.

​

Default logger

We provide a default logger that you can use to filter logs by level:

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Template, defaultBuildLogger } 

from

 &#x27;e2b&#x27;

;

await

 Template.

build

(template, 

&#x27;my-template&#x27;

, {

  onBuildLogs: 

defaultBuildLogger

({

    minLevel: 

"info"

, 

// Minimum log level to show

  }),

});

​

Custom logger

You can customize how logs are handled:

JavaScript & TypeScript

Python

Copy

Ask AI

// Simple logging

onBuildLogs

: (

logEntry

) 

=>

 console.

log

(logEntry.

toString

());

// Custom formatting

onBuildLogs

: (

logEntry

) 

=>

 {

  const

 time

 =

 logEntry.timestamp.

toISOString

();

  console.

log

(

`[${

time

}] ${

logEntry

.

level

.

toUpperCase

()

}: ${

logEntry

.

message

}`

);

};

// Filter by log level

onBuildLogs

: (

logEntry

) 

=>

 {

  if

 (logEntry.level 

===

 "error"

 ||

 logEntry.level 

===

 "warn"

) {

    console.

error

(logEntry.

toString

());

  }

};

The 
onBuildLogs
/
on_build_logs
 callback receives structured 
LogEntry
 objects with the following properties:

JavaScript & TypeScript

Python

Copy

Ask AI

type

 LogEntryLevel

 =

 &#x27;debug&#x27;

 |

 &#x27;info&#x27;

 |

 &#x27;warn&#x27;

 |

 &#x27;error&#x27;

class

 LogEntry

 {

  constructor

(

    public

 readonly

 timestamp

:

 Date

,

    public

 readonly

 level

:

 LogEntryLevel

,

    public

 readonly

 message

:

 string

  )

  toString

() 

// Returns formatted log string

}

// Indicates the start of the build process

class

 LogEntryStart

 extends

 LogEntry

 {

  constructor

(

timestamp

:

 Date

, 

message

:

 string

) {

    super

(timestamp, 

&#x27;debug&#x27;

, message)

  }

}

// Indicates the end of the build process

class

 LogEntryEnd

 extends

 LogEntry

 {

  constructor

(

timestamp

:

 Date

, 

message

:

 string

) {

    super

(timestamp, 

&#x27;debug&#x27;

, message)

  }

}

Together with the 
LogEntry
 type, there are also 
LogEntryStart
 and 
LogEntryEnd
 types that indicate the start and end of the build process. Their default log level is 
debug
 and you can use them to like this:

Ja

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/error-handling

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

Error handling

The SDK provides specific error types:

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { AuthError, BuildError, FileUploadError } 

from

 &#x27;e2b&#x27;

;

try

 {

  await

 Template.

build

(template, 

&#x27;my-template&#x27;

);

} 

catch

 (error) {

  if

 (error 

instanceof

 AuthError

) {

    console.

error

(

"Authentication failed:"

, error.message);

  } 

else

 if

 (error 

instanceof

 FileUploadError

) {

    console.

error

(

"File upload failed:"

, error.message);

  } 

else

 if

 (error 

instanceof

 BuildError

) {

    console.

error

(

"Build failed:"

, error.message);

  }

}

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Next.js app

Next.js web app running in the sandbox using Node.js

Next

⌘
I

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/template/migration-v2

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Templates

V2 migration guide

We’ve made ready for you three ways how to migrate existing template to the new definition format.

Using the migration command (recommended)

Using the 
fromDockerfile()
 method to parse existing Dockerfile

Building the Docker image manually and using 
fromImage()
 method

This is handled for you automatically when using any of the options below.

The default user for the template is 
user
 with the working directory set to the user home directory. This is a difference from the Docker defaults.

​

Migration command (recommended)

To migrate the existing template definition to the new format, follow these steps:

1

Install E2B CLI

Install the latest version of the 
E2B CLI

2

Navigate to your template folder

Navigate to the folder of your existing template definition (where you have 
e2b.toml
 and 
e2b.Dockerfile
 files).

3

Run migration command

Your existing 
e2b.toml
 and 
e2b.Dockerfile
 files will be renamed to 
e2b.toml.old
 and 
e2b.Dockerfile.old
, respectively, as they are no longer required.

Copy

Ask AI

e2b

 template

 migrate

4

Follow the prompts

Follow the prompts to complete the migration process.

5

Done

​

Generated output

The migration command generates three files (based on the selected language).

JavaScript & TypeScript

Python

Copy

Ask AI

template.ts - Template definition using the SDK

build.dev.ts - Development build script

build.prod.ts - Production build script

​

Using 
fromDockerfile()
 Method

If you want to keep using Dockerfile for your template, you can use the 
fromDockerfile()
 method.
We’ll automatically parse the Dockerfile for you and build the template based on it.
You can find more at 
Base Image
.

JavaScript & TypeScript

Python

Copy

Ask AI

// template.ts

import

 { Template } 

from

 &#x27;e2b&#x27;

;

const

 template

 =

 Template

()

  .

fromDockerfile

(dockerfileContent);

Only a limited set of instructions are supported and converted to equivalent template.

Compatible instructions:

FROM
, 
RUN
, 
COPY
, 
ADD
, 
WORKDIR
, 
USER
, 
ENV
, 
ARG
, 
CMD
, 
ENTRYPOINT

After the template definition, you can create the build scripts as described in the 
Quickstart
 section.

​

Using 
fromImage()
 Method

If you already have a Docker image built, or yo

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/filesystem

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Filesystem

Filesystem

Each E2B Sandbox has its own isolated filesystem. The 
Hobby tier
 sandboxes come with 10 GB of the free disk space and 
Pro tier
 sandboxes come with 20 GB.

With E2B SDK you can:

Read and write files to the sandbox.

Watch directory for changes.

Upload data to the sandbox.

Download data from the sandbox.

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Read & write

Next

⌘
I

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/filesystem/read-write

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Filesystem

Read & write files

​

Reading files

You can read files from the sandbox filesystem using the 
files.read()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 fileContent

 =

 await

 sandbox.files.

read

(

&#x27;/path/to/file&#x27;

)

​

Writing single files

You can write single files to the sandbox filesystem using the 
files.write()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

await

 sandbox.files.

write

(

&#x27;/path/to/file&#x27;

, 

&#x27;file content&#x27;

)

​

Writing multiple files

You can also write multiple files to the sandbox.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

await

 sandbox.files.

write

([

    { path: 

&#x27;/path/to/a&#x27;

, data: 

&#x27;file content&#x27;

 },

    { path: 

&#x27;/another/path/to/b&#x27;

, data: 

&#x27;file content&#x27;

 }

])

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

File & directory metadata

Next

⌘
I

On this page

Reading files

Writing single files

Writing multiple files

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/filesystem/info

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Filesystem

Get information about a file or directory

You can get information about a file or directory using the 
files.getInfo()
 / 
files.get_info()
 methods. Information such as file name, type, and path is returned.

​

Getting information about a file

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Create a new file

await

 sandbox.files.

write

(

&#x27;test_file.txt&#x27;

, 

&#x27;Hello, world!&#x27;

)

// Get information about the file

const

 info

 =

 await

 sandbox.files.

getInfo

(

&#x27;test_file.txt&#x27;

)

console.

log

(info)

// {

//   name: &#x27;test_file.txt&#x27;,

//   type: &#x27;file&#x27;,

//   path: &#x27;/home/user/test_file.txt&#x27;,

//   size: 13,

//   mode: 0o644, 

//   permissions: &#x27;-rw-r--r--&#x27;,

//   owner: &#x27;user&#x27;,

//   group: &#x27;user&#x27;,

//   modifiedTime: &#x27;2025-05-26T12:00:00.000Z&#x27;,

//   symlinkTarget: null

// }

​

Getting information about a directory

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Create a new directory

await

 sandbox.files.

makeDir

(

&#x27;test_dir&#x27;

)

// Get information about the directory

const

 info

 =

 await

 sandbox.files.

getInfo

(

&#x27;test_dir&#x27;

)

console.

log

(info)

// {

//   name: &#x27;test_dir&#x27;,

//   type: &#x27;dir&#x27;,

//   path: &#x27;/home/user/test_dir&#x27;,

//   size: 0,

//   mode: 0o755,

//   permissions: &#x27;drwxr-xr-x&#x27;,

//   owner: &#x27;user&#x27;,

//   group: &#x27;user&#x27;,

//   modifiedTime: &#x27;2025-05-26T12:00:00.000Z&#x27;,

//   symlinkTarget: null

// }

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Watch directory for changes

Next

⌘
I

On this page

Getting information about a file

Getting information about a directory

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/filesystem/watch

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Filesystem

Watch sandbox directory for changes

You can watch a directory for changes using the 
files.watchDir()
 method in JavaScript and 
files.watch_dir()
 method in Python.

Since events are tracked asynchronously, their delivery may be delayed.
It’s recommended not to collect or close watcher immediately after making a change.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox, FilesystemEventType } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 dirname

 =

 &#x27;/home/user&#x27;

// Start watching directory for changes

const

 handle

 =

 await

 sandbox.files.

watchDir

(dirname, 

async

 (

event

) 

=>

 {

  console.

log

(event)

  if

 (event.type 

===

 FilesystemEventType.

WRITE

) {

    console.

log

(

`wrote to file ${

event

.

name

}`

)

  }

})

// Trigger file write event

await

 sandbox.files.

write

(

`${

dirname

}/my-file`

, 

&#x27;hello&#x27;

)

​

Recursive watching

You can enable recursive watching using the parameter 
recursive
.

When rapidly creating new folders (e.g., deeply nested path of folders), events other than 
CREATE
 might not be emitted. To avoid this behavior, create the required folder structure in advance.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox, FilesystemEventType } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 dirname

 =

 &#x27;/home/user&#x27;

// Start watching directory for changes

const

 handle

 =

 await

 sandbox.files.

watchDir

(dirname, 

async

 (

event

) 

=>

 {

  console.

log

(event)

  if

 (event.type 

===

 FilesystemEventType.

WRITE

) {

    console.

log

(

`wrote to file ${

event

.

name

}`

)

  }

}, {

  recursive: 

true

})

// Trigger file write event

await

 sandbox.files.

write

(

`${

dirname

}/my-folder/my-file`

, 

&#x27;hello&#x27;

)

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Upload data

Next

⌘
I

On this page

Recursive watching

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/filesystem/upload

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Filesystem

Upload data to sandbox

You can upload data to the sandbox using the 
files.write()
 method.

​

Upload single file

JavaScript & TypeScript

Python

Copy

Ask AI

import

 fs 

from

 &#x27;fs&#x27;

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Read file from local filesystem

const

 content

 =

 fs.

readFileSync

(

&#x27;/local/path&#x27;

)

// Upload file to sandbox

await

 sandbox.files.

write

(

&#x27;/path/in/sandbox&#x27;

, content)

​

Upload with pre-signed URL

Sometimes, you may want to let users from unauthorized environments, like a browser, upload files to the sandbox.
For this use case, you can use pre-signed URLs to let users upload files securely.

All you need to do is create a sandbox with the 
secure: true
 option. An upload URL will then be generated with a signature that allows only authorized users to upload files.
You can optionally set an expiration time for the URL so that it will be valid only for a limited time.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Start a secured sandbox (all operations must be authorized by default)

const

 sandbox

 =

 await

 Sandbox.

create

(template, { secure: 

true

 })

// Create a pre-signed URL for file upload with a 10 second expiration

const

 publicUploadUrl

 =

 await

 sandbox.

uploadUrl

(

  &#x27;demo.txt&#x27;

, {

    useSignatureExpiration: 

10_000

, 

// optional

  },

)

// Upload a file with a pre-signed URL (this can be used in any environment, such as a browser)

const

 form

 =

 new

 FormData

()

form.

append

(

&#x27;file&#x27;

, 

&#x27;file content&#x27;

)

await

 fetch

(publicUploadUrl, { method: 

&#x27;POST&#x27;

, body: form })

// File is now available in the sandbox and you can read it

const

 content

 =

 sandbox.files.

read

(

&#x27;/path/in/sandbox&#x27;

)

​

Upload directory / multiple files

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Read all files in the directory and store their paths and contents in an array

const

 readDirectoryFiles

 =

 (


...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/filesystem/download

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Filesystem

Download data from sandbox

You can download data from the sandbox using the 
files.read()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 fs 

from

 &#x27;fs&#x27;

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Read file from sandbox

const

 content

 =

 await

 sandbox.files.

read

(

&#x27;/path/in/sandbox&#x27;

)

// Write file to local filesystem

fs.

writeFileSync

(

&#x27;/local/path&#x27;

, content)

​

Download with pre-signed URL

Sometimes, you may want to let users from unauthorized environments, like a browser, download files from the sandbox.
For this use case, you can use pre-signed URLs to let users download files securely.

All you need to do is create a sandbox with the 
secure: true
 option. A download URL will then be generated with a signature that allows only authorized users to access files.
You can optionally set an expiration time for the URL so that it will be valid only for a limited time.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 fs 

from

 &#x27;fs&#x27;

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

// Start a secured sandbox (all operations must be authorized by default)

const

 sandbox

 =

 await

 Sandbox.

create

(template, { secure: 

true

 })

// Create a pre-signed URL for file download with a 10 second expiration

const

 publicUrl

 =

 await

 sandbox.

downloadUrl

(

  &#x27;demo.txt&#x27;

, {

    useSignatureExpiration: 

10_000

, 

// optional

  },

)

// Download a file with a pre-signed URL (this can be used in any environment, such as a browser)

const

 res

 =

 await

 fetch

(publicUrl)

const

 content

 =

 await

 res.

text

()

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Overview

Next

⌘
I

On this page

Download with pre-signed URL

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/commands

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Commands

Running commands in sandbox

You can run terminal commands inside the sandbox using the 
commands.run()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 result

 =

 await

 sandbox.commands.

run

(

&#x27;ls -l&#x27;

)

console.

log

(result)

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Streaming

Next

⌘
I

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/commands/streaming

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Commands

Streaming command output

To stream command output as it is being executed, pass the 
onStdout
, 
onStderr
 callbacks to the 
commands.run()
 method in JavaScript
or the 
on_stdout
, 
on_stderr
 callbacks to the 
commands.run()
 method in Python.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

const

 result

 =

 await

 sandbox.commands.

run

(

&#x27;echo hello; sleep 1; echo world&#x27;

, {

  onStdout

: (

data

) 

=>

 {

    console.

log

(data)

  },

  onStderr

: (

data

) 

=>

 {

    console.

log

(data)

  },

})

console.

log

(result)

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Run commands in background

Next

⌘
I

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/commands/background

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

Commands

Running commands in background

To run commands in background, pass the 
background
 option to the 
commands.run()
 method. This will return immediately and the command will continue to run in the sandbox.
You can then later kill the command using the 
commands.kill()
 method.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;@e2b/code-interpreter&#x27;

const

 sandbox

 =

 await

 Sandbox.

create

()

// Start the command in the background

const

 command

 =

 await

 sandbox.commands.

run

(

&#x27;echo hello; sleep 10; echo world&#x27;

, {

  background: 

true

,

  onStdout

: (

data

) 

=>

 {

    console.

log

(data)

  },

})

// Kill the command

await

 command.

kill

()

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Overview

Connect to 200+ tools through the Model Context Protocol

Next

⌘
I

Assistant

Responses are generated using AI and may contain mistakes.

---

## Documentation - E2B

> Source: https://e2b.dev/docs/mcp

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

MCP gateway

Overview

E2B provides a batteries-included MCP gateway that runs inside sandboxes, giving you type-safe access to 200+ MCP tools from the 
Docker MCP Catalog
 or 
custom MCPs
 through a unified interface. This integration gives developers instant access to tools like 
Browserbase
, 
Exa
, 
Notion
, 
Stripe
, or 
GitHub
.

The 
Model Context Protocol (MCP)
 is an open standard for connecting AI models to external tools and data sources. E2B sandboxes provide an ideal environment for running MCP tools, giving AI full access to an internet-connected Linux machine where it can safely install packages, write files, run terminal commands, and AI-generated code.

TypeScript

Python

Copy

Ask AI

import

 Sandbox 

from

 &#x27;e2b&#x27;

const

 sbx

 =

 await

 Sandbox.

create

({

    mcp: {

        browserbase: {

            apiKey: process.env.

BROWSERBASE_API_KEY

!

,

            geminiApiKey: process.env.

GEMINI_API_KEY

!

,

            projectId: process.env.

BROWSERBASE_PROJECT_ID

!

,

        },

        exa: {

            apiKey: process.env.

EXA_API_KEY

!

,

        },

        airtable: {

            airtableApiKey: process.env.

AIRTABLE_API_KEY

!

,

        },

    },

});

const

 mcpUrl

 =

 sbx.

getMcpUrl

();

const

 mcpToken

 =

 await

 sbx.

getMcpToken

();

// You can now connect the gateway to any MCP client, for example claude:

// This also works for your local claude!

await

 sbx.commands.

run

(

`claude mcp add --transport http e2b-mcp-gateway ${

mcpUrl

} --header "Authorization: Bearer ${

mcpToken

}"`

, { timeoutMs: 

0

, onStdout: console.log, onStderr: console.log });

await

 sbx.commands.

run

(

    `echo &#x27;Use browserbase and exa to research open positions at e2b.dev. Collect your findings in Airtable.&#x27; | claude -p --dangerously-skip-permissions`

,

    { timeoutMs: 

0

, onStdout: console.log, onStderr: console.log }

)

​

Documentation

Quickstart

Get started with MCP

Available servers

Browse 200+ pre-built MCP servers

Custom templates

Prepull MCP servers for faster runtime

Custom servers

Use custom MCP servers from GitHub

Examples

See examples

Was this page helpful?

Yes

No

Suggest edits

Raise issue

Previous

Quickstart

Get started with MCP integra

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/mcp/quickstart

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

MCP gateway

Quickstart

You can connect to the MCPs running inside the sandbox both from outside and inside the sandbox.

​

From outside the sandbox

To connect to the MCPs running inside the sandbox, use the 
sandbox.getMcpUrl()
 in JavaScript and 
sandbox.get_mcp_url()
 in Python.

TypeScript

Python

Copy

Ask AI

import

 Sandbox 

from

 &#x27;e2b&#x27;

import

 { Client } 

from

 &#x27;@modelcontextprotocol/sdk/client/index.js&#x27;

;

import

 { StreamableHTTPClientTransport } 

from

 &#x27;@modelcontextprotocol/sdk/client/streamableHttp.js&#x27;

;

const

 sandbox

 =

 await

 Sandbox.

create

({

    mcp: {

        browserbase: {

            apiKey: process.env.

BROWSERBASE_API_KEY

!

,

            geminiApiKey: process.env.

GEMINI_API_KEY

!

,

            projectId: process.env.

BROWSERBASE_PROJECT_ID

!

,

        },

        exa: {

            apiKey: process.env.

EXA_API_KEY

!

,

        },

        notion: {

            internalIntegrationToken: process.env.

NOTION_API_KEY

!

,

        },

    },

});

const

 client

 =

 new

 Client

({

    name: 

&#x27;e2b-mcp-client&#x27;

,

    version: 

&#x27;1.0.0&#x27;

});

const

 transport

 =

 new

 StreamableHTTPClientTransport

(

    new

 URL

(sandbox.

getMcpUrl

()), 

    {

        requestInit: {

            headers: {

                &#x27;Authorization&#x27;

: 

`Bearer ${

await

 sandbox

.

getMcpToken

()

}`

            }

        }

    }

);

await

 client.

connect

(transport);

const

 tools

 =

 await

 client.

listTools

();

console.

log

(

&#x27;Available tools:&#x27;

, tools.tools.

map

(

t

 =>

 t.name));

await

 client.

close

();

await

 sandbox.

kill

();

​

From inside the sandbox

If you need to access the MCP gateway from within the sandbox itself, it’s available at:

Copy

Ask AI

http://localhost:50005/mcp

You’ll need to include the Authorization header with the MCP token when making requests from inside the sandbox. How that is added depends on the MCP client you use:

​

Claude

Copy

Ask AI

claude mcp add --transport http e2b-mcp-gateway <url goes here> --header "Authorization: Bearer <token goes here>"

​

OpenAI Agents

TypeScript

Python

Copy

Ask AI

import

 { MCPServerStreamableHttp } 

from

 &#x2

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/mcp/available-servers

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

MCP gateway

Available servers

E2B provides access to 200+ MCP servers from 
Docker’s catalog
. You can also run 
custom MCP servers
 inside the sandbox.

​

Airtable

Provides AI assistants with direct access to Airtable bases, allowing them to read schemas, query records, and interact with your Airtable data. Supports listing bases, retrieving table structures, and searching through records to help automate workflows and answer questions about your organized data.

View on Docker Hub

​

airtable

object

Show
 
properties

​

airtableApiKey

string

required

​

nodeenv

string

required

​

Azure Kubernetes Service (AKS)

Azure Kubernetes Service (AKS) official MCP server.

View on Docker Hub

​

aks

object

Show
 
properties

​

accessLevel

string

required

Access level for the MCP server, One of [ readonly, readwrite, admin ]

​

additionalTools

string

Comma-separated list of additional tools, One of [ helm, cilium ]

​

allowNamespaces

string

Comma-separated list of namespaces to allow access to. If not specified, all namespaces are allowed.

​

azureDir

string

required

Path to the Azure configuration directory (e.g. /home/azureuser/.azure). Used for Azure CLI authentication, you should be logged in (e.g. run 
az login
) on the host before starting the MCP server.

​

containerUser

string

Username or UID of the container user (format 
<name|uid>
[:
<group|gid>
] e.g. 10000), ensuring correct permissions to access the Azure and kubeconfig files. Leave empty to use default user in the container.

​

kubeconfig

string

required

Path to the kubeconfig file for the AKS cluster (e.g. /home/azureuser/.kube/config). Used to connect to the AKS cluster.

​

Apify

Apify is the world’s largest marketplace of tools for web scraping, data extraction, and web automation. You can extract structured data from social media, e-commerce, search engines, maps, travel sites, or any other website.

View on Docker Hub

​

apify

object

Show
 
properties

​

apifyToken

string

required

​

tools

string

required

Comma-separated list of tools to enable. Can be either a tool category, a specific tool, or an Apify Actor. For example: “actors,docs,apify/rag-web-browser”. For more details visit 
https://mcp.apify.com
.

​

Api-gateway

A universal MCP (Mod

...(truncated)

---

## Documentation - E2B

> Source: https://e2b.dev/docs/mcp/custom-templates

Documentation - E2B

Skip to main content

E2B Docs
 home page

Search...

⌘
K

Documentation

SDK reference

Getting started

Home

Quickstart

API key

Cookbook

Need help?

Billing

Use cases

Coding Agents

Computer use

GitHub Actions CI/CD

Agents in sandbox

Amp

Claude Code

Codex

OpenClaw

OpenCode

Code interpreting

Analyze data with AI

Charts & visualizations

Streaming

Code contexts

Supported languages

Sandbox

Lifecycle

Lifecycle events API

Lifecycle events webhooks

Persistence

Snapshots

Git integration

Metrics

Metadata

Environment variables

List sandboxes

Connect to running sandbox

Internet access

Interactive terminal

SSH access

Connecting storage bucket

Rate limits

Secured access

Proxy tunneling

Custom domain

Templates

Quickstart

How it works

User and workdir

Caching

Base image

Private registries

Defining template

Start & ready commands

Build

Names

Tags & versioning

Logging

Error handling

Examples

V2 migration guide

Filesystem

Overview

Read & write

File & directory metadata

Watch directory for changes

Upload data

Download data

Commands

Overview

Streaming

Run commands in background

MCP gateway

Overview

Quickstart

Available servers

Custom templates

Custom servers

Examples

CLI

Installation

Authentication

List sandboxes

Create sandbox

Connect to sandbox

Execute commands in sandbox

Shutdown running sandboxes

Deployment

Bring Your Own Cloud

Migration

SDK v2 migration guide

Troubleshooting

Build authentication error

The sandbox is running but port is not open - 49999

pip install fails during template build

Dashboard

e2b-dev/e2b

E2B Docs
 home page

Search...

⌘
K

Ask AI

Search...

Navigation

MCP gateway

Custom templates

You can prepull MCP server Docker images during template build time to significantly improve runtime performance.

​

How it works

When you build a template with prepulled MCP servers, the Docker images for those servers are downloaded and cached during the build process. This means when you create a sandbox from that template, the MCP servers are ready to use immediately without waiting for image downloads.

You must use the MCP gateway enabled template (
mcp-gateway
) as your base template to use this feature.

​

Building a template with MCP servers

Use the 
addMcpServer()
 method (TypeScript) or 
add_mcp_server()
 method (Python) to prepull MCP server images during template build. You can pass a single server or an array of servers.

The server names (like 
"browserbase"
 and 
"exa"
) correspond to the keys defined in the 
Available Servers
 documentation.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 "dotenv/config"

;

import

 { Template, defaultBuildLogger } 

from

 &#x27;e2b&#x27;

;

export

 const

 template

 =

 Template

()

  .

fromTemplate

(

"mcp-gateway"

)

  .

addMcpServer

([

"browserbase"

, 

"exa"

]);

await

 Template.

build

(template, 

&#x27;my-mcp-gateway&#x27;

, {

  cpuCount: 

8

,

  memoryMB: 

8192

,

  onBuildLogs: 

defaultBuildLogger

(),

});

​

Using the template

Once built, create sandboxes from your template. You still need to provide the configuration for each MCP server.

JavaScript & TypeScript

Python

Copy

Ask AI

import

 { Sandbox } 

from

 &#x27;e2b&#x27;

;

const

 sandbox

 =

 await

 Sandbox.

create

({

    template: 

"my-mcp-gateway"

,

    mcp: {

        browserbase: {

            apiKey: process.env.

BROWSERBASE_API_KEY

!

,

            geminiApiKey: process.env.

GEMINI_API_KEY

!

,

            projectId: process.env.

BROWSERBASE_PROJECT_ID

!

,

        },

        exa: {

            apiKey: process.env.

EXA_API_KEY

!

,

        },

    },

});

​

Learn more

For more information about working with templates, see:

Template Quickstart
 - Get started with custom templates

Defining Templates
 - Learn all template configuration options

Template Build
 - Understand the build process

Was this page helpful?

Yes

No

Sugges

...(truncated)

---

