E2B.Snapshot reference
CreateSnapshot
Section titled “CreateSnapshot”Source:
packages/e2b/src/CreateSnapshot.ts
Take and manage E2B snapshots at runtime: a warm base per repository or per customer, created on demand and forked into sandboxes.
Snapshots taken at runtime carry no metadata, so they are not deleted when
the host is destroyed. Delete them with delete when their owner goes
away.
CreateSnapshot: Warm bases at runtime
Section titled “CreateSnapshot: Warm bases at runtime”const snapshots = yield* E2B.CreateSnapshot();const sandboxes = yield* E2B.CreateSandbox();// in fetch:const [existing] = yield* snapshots.list({ name: `warm-${slug}` });const base = existing ?? (yield* snapshots.create(`warm-${slug}`, { template: "node-22", run: [`git clone https://github.com/${repo} repo`, "cd repo && npm ci"], }));const sandbox = yield* sandboxes.create({ templateID: base.snapshotID });CreateSnapshotHttp
Section titled “CreateSnapshotHttp”Source:
packages/e2b/src/CreateSnapshotHttp.tsKind: Layer · Provides:E2B.CreateSnapshot
HTTP implementation of CreateSnapshot. Works on any host.
CreateSnapshotHttp: Provide the layer
Section titled “CreateSnapshotHttp: Provide the layer”Effect.gen(function* () { const snapshots = yield* E2B.CreateSnapshot(); // ...}).pipe(Effect.provide(E2B.CreateSnapshotHttp))Snapshot
Section titled “Snapshot”Source:
packages/e2b/src/Snapshot.ts
A warm base to fork sandboxes from: a template booted, set up with your commands, and snapshotted — memory included, so sandboxes created from it start exactly where the setup left off.
Use a snapshot for work that is too slow to repeat per sandbox and does
not belong in an image: cloning a repository, installing its
dependencies, starting a language server. A deploy re-runs the setup only
when the template or the commands change. E2B stores a snapshot as a
template, so it is created from with E2B.CreateSandbox(snapshot) and
deleted with its template.
Snapshot: Creating a Snapshot
Section titled “Snapshot: Creating a Snapshot”export const Agent = E2B.Template("Agent", { image: "node:22-bookworm" });
export const Warm = E2B.Snapshot("Warm", { template: Agent, run: [ "git clone https://github.com/alchemy-run/alchemy /home/user/alchemy", "cd /home/user/alchemy && pnpm install", ],});Snapshot: Forking sandboxes from a Snapshot
Section titled “Snapshot: Forking sandboxes from a Snapshot”const sandboxes = yield* E2B.CreateSandbox(Warm);const sandbox = yield* sandboxes.create({ timeout: 600 });yield* sandbox.exec("cd alchemy && pnpm test");Snapshot: Referencing a snapshot the stack doesn’t manage
Section titled “Snapshot: Referencing a snapshot the stack doesn’t manage”E2B.Snapshot.lookup finds an existing snapshot by name. Nothing is created,
adopted or deleted.
const warm = E2B.Snapshot.lookup({ name: "warm-repo" });const sandboxes = yield* E2B.CreateSandbox(warm);