Snapshots & forks
A snapshot saves a sandbox, memory and disk, as a template of its own. Sandboxes from it start where the original was: a repository cloned, its dependencies installed, a server listening. A fork snapshots a running sandbox and starts copies of it at once, while the original keeps running. Each copy changes on its own from then on.
Copies start where the original was
Section titled “Copies start where the original was”Build a warm base at deploy
Section titled “Build a warm base at deploy”const warm = yield* E2B.Snapshot("Warm", { template: MyTemplate, run: [ "git clone https://github.com/my-org/app /home/user/app", "cd /home/user/app && npm ci", ],});Alchemy boots the template, runs the commands, snapshots the sandbox with its memory, and kills it. A command that exits non-zero fails the deploy with SnapshotSetupFailed. A deploy runs the setup again only when the template or the commands change.
Start sandboxes from a snapshot
Section titled “Start sandboxes from a snapshot”const sandboxes = yield* E2B.CreateSandbox(Warm);const sandbox = yield* sandboxes.create({ timeout: 600 });yield* sandbox.exec("cd app && npm test");Snapshot a running sandbox
Section titled “Snapshot a running sandbox”const snapshot = yield* sandbox.snapshot({ name: `session-${id}` });const restored = yield* sandboxes.create({ templateID: snapshot.snapshotID });Pass memory: false to keep only the filesystem; sandboxes from it boot fresh.
Fork a running sandbox
Section titled “Fork a running sandbox”const results = yield* sandbox.fork({ count: 3 });for (const result of results) { if (result._tag === "Forked") yield* result.sandbox.exec("npm test -- --shard");}E2B checkpoints the sandbox (it keeps running) and starts copies of it. Each fork succeeds or fails on its own.
Take snapshots while your app runs
Section titled “Take snapshots while your app runs”const snapshots = yield* E2B.CreateSnapshot();const info = yield* snapshots.create(`warm-${slug}`, { template: "node-22", run: ["npm ci"] });yield* snapshots.delete(`warm-${slug}`);Runtime snapshots are not deleted when you destroy the Worker.