What is E2B?
E2B runs sandboxes: Linux microVMs for code you don’t trust. Each sandbox boots from a template, an image E2B builds and snapshots once, so a new sandbox starts in well under a second with its files and processes already in place. A sandbox runs until its timeout, then E2B kills it or pauses it with its memory. Everything belongs to a team: its templates, sandboxes, volumes, secrets and API keys, and the bill.
Take one small app: a MyTemplate template with Node.js and git, and a Warm snapshot of it with a repository already cloned and installed. For each user, a Cloudflare Worker creates a volume for their files, home-42, then creates a sandbox from Warm with that volume mounted at /home/user, and runs the agent’s commands there.
Teams: who owns and pays
Section titled “Teams: who owns and pays”A team owns everything you create on E2B, and pays for it. You sign in as yourself, and your account can belong to several teams.
E2B has two kinds of credential. Your access token is personal: it lists your teams and creates API keys. An API key acts for one team, on everything in it. E2B can’t narrow a key to some sandboxes or some operations.
export const Ci = E2B.ApiKey("Ci", {});See Team & API keys.
Templates: the image a sandbox boots
Section titled “Templates: the image a sandbox boots”A template is the image a sandbox boots from. E2B builds it on its side, from a registry image, a Dockerfile or another template, then boots it once, runs its start command, and snapshots the running microVM. Every sandbox from it starts from that snapshot.
export const MyTemplate = E2B.Template("MyTemplate", { image: "node:22-bookworm" });See Templates.
Sandboxes: a microVM per user or task
Section titled “Sandboxes: a microVM per user or task”A sandbox is one microVM, created from a template while your app runs, usually one per user or per task. You run commands in it, read and write its files, open a terminal, and call its ports at https://<port>-<sandboxId>.e2b.app. It runs for its timeout, which you can extend. When the timeout runs out, E2B kills it, or with autoPause pauses it with its memory, files and processes, until you resume it.
const sandbox = yield* sandboxes.create({ metadata: { user }, autoPause: true, timeout: 600 });See Sandboxes.
Snapshots: start where another sandbox was
Section titled “Snapshots: start where another sandbox was”A snapshot captures a running sandbox, memory and disk, as a template of its own. Sandboxes from it start where the original was: a repository cloned, dependencies installed, a server listening. A fork snapshots a sandbox and starts copies of it straight away, while the original keeps running.
export const Warm = E2B.Snapshot("Warm", { template: MyTemplate, run: ["npm ci"] });See Snapshots & forks.
Volumes: files that outlive the sandbox
Section titled “Volumes: files that outlive the sandbox”A volume is a filesystem that lives outside any sandbox. A sandbox mounts it at a path when it’s created, and the files stay when the sandbox is gone. You can also read and write a volume’s files without a sandbox. E2B turns volumes on per team.
export const Cache = E2B.Volume("Cache", {});See Volumes.
Network rules and secrets: what leaves the sandbox
Section titled “Network rules and secrets: what leaves the sandbox”A sandbox reaches the internet unless you limit it. Its network rules list the only hosts it may call, or block it entirely, and you can change them while it runs. A secret is a value E2B stores for the team and adds to a sandbox’s outgoing requests, on the host and only for the hosts you choose, so code in the sandbox never sees it.
export const GitHubToken = E2B.Secret("GitHubToken", { value: Config.Redacted("GITHUB_TOKEN") });See Network & secrets.
Lifecycle events: E2B calls you when a sandbox changes
Section titled “Lifecycle events: E2B calls you when a sandbox changes”E2B reports what happens to each sandbox (created, paused, resumed, checkpointed, killed) to a webhook: a URL you register for the team, called with each event, signed with a secret. A Worker receives them with consumeSandboxEvents:
yield* E2B.consumeSandboxEvents({ events: ["sandbox.lifecycle.killed"] }, (event) => Effect.log(`${event.sandbox_id} killed`),);See Lifecycle events.
State: where Alchemy keeps its record
Section titled “State: where Alchemy keeps its record”E2B has no storage for Alchemy’s own record of what each Stack created. Keep it on disk with Alchemy.localState(), or share it with your team and CI through Cloudflare.state() or AWS.state().
How @alchemy.run/e2b models these concepts
Section titled “How @alchemy.run/e2b models these concepts”Your profile signs you in and picks the team, and E2B.providers() deploys into it. What an app shares for its whole life (templates, snapshots, a volume, a secret, a long-lived dev box, a webhook) are resources in the Stack. Sandboxes, volumes, secrets and templates made per user or task come from bindings your Worker or Function uses while it runs (CreateSandbox, CreateVolume, CreateSecret, CreateTemplate). None of it is deleted when the Stack is destroyed. Sandboxes and secrets carry their stack, stage and binding in their E2B metadata, so you can find them again; volumes and templates have no metadata, so delete them when their owner goes away. Each host that uses a binding gets an API key of its own, created at deploy, never yours.
Next, build one: the tutorial puts these ideas to work, one step at a time.