E2B
Run an agent's commands and files in an E2B cloud sandbox.
E2B runs each sandbox as a small cloud VM. Set E2B_API_KEY and pass e2b() as the agent's sandbox.
import { e2b } from "@threads/e2b";
const e2bSandbox = e2b({
template: "base",
lifetimeMs: 10 * 60_000,
});Options
| TypeScript | Python | Default | What it does |
|---|---|---|---|
apiKey | api_key | E2B_API_KEY | Authenticates threads' calls to E2B. Never enters the sandbox. |
template | template | "base" | The E2B template a new sandbox starts from. |
lifetimeMs | lifetime_ms | 1 hour | How long a sandbox lives before E2B deletes it. |
allowInternet | allow_internet | false | Opens the network. Also set egress: "unenforced" on the agent. |
domain | domain | E2B's | The E2B domain to connect to, for self-hosted E2B. |
| — | name | "e2b" | Python only: the provider name sandboxes are recorded under. |
A custom template needs /bin/sh, env and tar. E2B's base template has them.
Good to know
- No fork points yet. threads doesn't take E2B snapshots today, so an E2B thread can't be forked at a sandbox state.
- Crashes park. If the host crashes mid-command, threads can't prove E2B stopped the command's child processes, so the run parks for you instead of re-running it.
See Sandboxes for the tools an agent gets and how internet access works.