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-keyAuthentication
Get your API key from the E2B dashboard:
- Sign up or log in at e2b.dev
- Navigate to your dashboard
- Copy your API key
- Set the environment variable:
export E2B_API_KEY=your-api-keyConfiguration
Environment Variables
| Variable | Description | Default |
|---|---|---|
SANDBOX_PROVIDER | Set to e2b to enable | local |
E2B_API_KEY | Your E2B API key | - |
E2B_SANDBOX_TIMEOUT | Sandbox lifetime in milliseconds | 3600000 (1 hour) |
E2B_SANDBOX_TEMPLATE | Custom E2B template name | E2B 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=7200000Higher 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-templateSee 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 URLCommon development ports (3000, 5173, 8080, etc.) work out of the box.
How It Works
-
Sandbox Creation: When a session starts, Sesame calls
Sandbox.create()with the configured API key, timeout, and optional template. -
Working Directory: The project is cloned to
/home/user/projectinside the sandbox. -
Command Execution: Agent commands run via
sandbox.commands.run(). Background commands (like dev servers) use thebackground: trueoption. Output is streamed back to Sesame in real-time. -
File Operations: File reads, writes, and directory operations use the native E2B SDK (
sandbox.files.*) for efficiency. -
Port Access: Ports are exposed dynamically via
sandbox.getHost(port), returning a publicly accessible hostname. -
Cleanup: When the session completes, the sandbox is destroyed via
sandbox.kill().
Limitations
| Aspect | Limitation |
|---|---|
| OS-level sandboxing | Not used (E2B's cloud provides full isolation) |
| stdin | Not supported for background processes |
| Persistence | Sandboxes are destroyed on session completion or timeout |
| Resource configuration | Controlled 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_KEYIf 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=7200000Template Not Found
If you get a template error:
- Verify the template name exists in your E2B account
- Try without a custom template (uses E2B default):
unset E2B_SANDBOX_TEMPLATE