SesameSesame

E2B

Run tasks in E2B's lightweight cloud sandboxes

The E2B provider uses the e2b SDK to run agent tasks in E2B's cloud sandbox environments. These sandboxes are lightweight Linux VMs that boot in ~150ms, providing secure isolation with native file operations and dynamic port exposure.

When to Use

Choose E2B sandboxes when:

  • You want fast cloud-based isolation (~150ms boot time)
  • You need dynamic port exposure without upfront declaration
  • You want a simple setup with minimal configuration (just an API key)
  • You prefer lightweight cloud VMs over containers

Quick Start

# Set the provider
export SANDBOX_PROVIDER=e2b

# Set your API key
export E2B_API_KEY=your-api-key

Authentication

Get your API key from the E2B dashboard:

  1. Sign up or log in at e2b.dev
  2. Navigate to your dashboard
  3. Copy your API key
  4. Set the environment variable:
export E2B_API_KEY=your-api-key

Configuration

Environment Variables

VariableDescriptionDefault
SANDBOX_PROVIDERSet to e2b to enablelocal
E2B_API_KEYYour E2B API key-
E2B_SANDBOX_TIMEOUTSandbox lifetime in milliseconds3600000 (1 hour)
E2B_SANDBOX_TEMPLATECustom E2B template nameE2B default

Config File

Alternatively, configure via config.json:

{
  "sandboxProvider": {
    "type": "e2b",
    "e2b": {
      "apiKey": "your-api-key",
      "timeout": 3600000,
      "template": "base"
    }
  }
}

Timeout Configuration

The timeout controls the maximum sandbox lifetime. After this duration, the sandbox is automatically terminated.

# 15 minutes
export E2B_SANDBOX_TIMEOUT=900000

# 1 hour (default)
export E2B_SANDBOX_TIMEOUT=3600000

# 2 hours
export E2B_SANDBOX_TIMEOUT=7200000

Higher timeouts may incur additional costs. Start with the default and increase as needed for long-running tasks.

Custom Templates

E2B supports custom sandbox templates with pre-installed tools and configurations. If your tasks require specific software, you can create a custom template and reference it:

export E2B_SANDBOX_TEMPLATE=my-custom-template

See the E2B documentation for details on creating custom templates.

Port Exposure

Like Daytona, E2B allows dynamic port exposure at any time. You don't need to declare ports upfront.

When an agent starts a development server, Sesame automatically retrieves the public URL:

// Internal: sandbox.getHost(port) returns the hostname
const host = sandbox.getHost(3000);
// Returns something like: 3000-sandbox-abc123.e2b.app
// Sesame prefixes with https:// for the full URL

Common development ports (3000, 5173, 8080, etc.) work out of the box.

How It Works

  1. Sandbox Creation: When a session starts, Sesame calls Sandbox.create() with the configured API key, timeout, and optional template.

  2. Working Directory: The project is cloned to /home/user/project inside the sandbox.

  3. Command Execution: Agent commands run via sandbox.commands.run(). Background commands (like dev servers) use the background: true option. Output is streamed back to Sesame in real-time.

  4. File Operations: File reads, writes, and directory operations use the native E2B SDK (sandbox.files.*) for efficiency.

  5. Port Access: Ports are exposed dynamically via sandbox.getHost(port), returning a publicly accessible hostname.

  6. Cleanup: When the session completes, the sandbox is destroyed via sandbox.kill().

Limitations

AspectLimitation
OS-level sandboxingNot used (E2B's cloud provides full isolation)
stdinNot supported for background processes
PersistenceSandboxes are destroyed on session completion or timeout
Resource configurationControlled via templates rather than per-sandbox settings

The @anthropic-ai/sandbox-runtime OS-level sandboxing feature (used by Filesystem and Docker providers) is not applicable to E2B sandboxes. This is because E2B's cloud VMs already provide complete process and network isolation at the infrastructure level.

Troubleshooting

Authentication Errors

Verify your API key is set correctly:

echo $E2B_API_KEY

If the key is invalid or expired, get a new one from the E2B dashboard.

Sandbox Timeout

If tasks are failing due to timeout:

# Increase timeout to 2 hours
export E2B_SANDBOX_TIMEOUT=7200000

Template Not Found

If you get a template error:

  1. Verify the template name exists in your E2B account
  2. Try without a custom template (uses E2B default):
    unset E2B_SANDBOX_TEMPLATE

On this page