Concepts
E2B gives you five things. Some you declare in your Stack. Most you create at runtime, one per user or per task.
Templates are images
Section titled “Templates are images”A template is the image a sandbox boots from. E2B builds it into a microVM snapshot, so a sandbox starts in well under a second.
export const Agent = E2B.Template("Agent", { image: "node:22-bookworm" });Declare the templates your app always needs. Build more at runtime with E2B.CreateTemplate(), for example one per repository. See Templates.
Snapshots are warm bases
Section titled “Snapshots are warm bases”A snapshot is a template after some work: a repository cloned, its dependencies installed, a server started. Sandboxes created from it resume with memory, so that work is already done.
const warm = yield* E2B.Snapshot("Warm", { template: Agent, run: ["git clone https://github.com/my-org/app", "cd app && npm ci"],});Take more at runtime with sandbox.snapshot() or E2B.CreateSnapshot(). See Snapshots & forks.
Sandboxes are created at runtime
Section titled “Sandboxes are created at runtime”A sandbox is short-lived: E2B kills it after its timeout, or pauses it with autoPause. You never declare one. You create them from a Worker with E2B.CreateSandbox(base), and find them again by their metadata.
const sandboxes = yield* E2B.CreateSandbox(Agent);const sandbox = yield* sandboxes.create({ metadata: { user }, autoPause: true });Sandboxes a Worker creates carry the stack, stage and Worker in their metadata, and stay when you destroy the stack. See Sandboxes.
Volumes hold files that outlive sandboxes
Section titled “Volumes hold files that outlive sandboxes”A volume is a filesystem sandboxes mount by name. Declare a shared one, or create one per user at runtime.
const volumes = yield* E2B.CreateVolume();const home = yield* volumes.getOrCreate(`home-${user}`);You can read and write a volume’s files without a sandbox. See Volumes.
Secrets never enter the sandbox
Section titled “Secrets never enter the sandbox”A secret is a value E2B adds to the sandbox’s outgoing requests, on the host, for the domains you choose. Code in the sandbox sees only a placeholder.
network: { allowOut: ["api.github.com"], rules: { "api.github.com": [{ transform: { headers: { Authorization: `Bearer ${github.ref}` } } }] },},See Network & secrets.
Two kinds of binding
Section titled “Two kinds of binding”Every binding either acts on one resource you declared, or on any object of its kind:
const fromAgent = yield* E2B.CreateSandbox(Agent); // sandboxes from this templateconst anyTemplate = yield* E2B.CreateSandbox(); // pass templateID per callconst reports = yield* E2B.ReadVolume(Reports); // files of this volumeconst homes = yield* E2B.CreateVolume(); // any volume, by nameBoth kinds return the same handles, and their calls take E2B’s own parameters.
Access
Section titled “Access”Every host that uses a binding gets its own E2B API key. Alchemy mints it at deploy with your access token and revokes it when the host is destroyed. Your own credentials never reach the host.
E2B keys are not scoped, so a host’s key still reaches the whole team. Data calls inside a sandbox use the sandbox’s own token, and volume files use the volume’s own token.