Skip to content

E2B.Snapshot reference

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.

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 });

Source: packages/e2b/src/CreateSnapshotHttp.ts Kind: Layer · Provides: E2B.CreateSnapshot

HTTP implementation of CreateSnapshot. Works on any host.

Effect.gen(function* () {
const snapshots = yield* E2B.CreateSnapshot();
// ...
}).pipe(Effect.provide(E2B.CreateSnapshotHttp))

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.

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);