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",
  timeoutMs: 10 * 60_000,
});

In TypeScript, @threads/e2b runs on Bun only. On Node, the E2B SDK sends requests through a client threads can't safely wrap, so e2b() throws ConfigError transport_fence_unsupported instead of running with weaker crash safety.

Options

TypeScriptPythonDefaultWhat it does
apiKeyapi_keyE2B_API_KEYAuthenticates threads' calls to E2B. Never enters the sandbox.
templatetemplate"base"The E2B template a new sandbox starts from.
timeoutMslifetime_ms5 minutes (TS), 1 hour (Python)How long a sandbox lives before E2B deletes it.
internetallow_internetfalseOpens the network. Also set egress: "unenforced" on the agent.
domaindomainE2B'sThe E2B domain to connect to, for self-hosted E2B.

A custom template needs /bin/sh and the GNU tools sed, find, stat and sha256sum. 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.

Edit on GitHub

On this page