Skip to content

Snapshots

A snapshot saves a running sandbox so another can start where it was. Modal saves three things: the whole filesystem as an image, the memory with its running processes, or one directory to mount elsewhere.

The original keeps running after a snapshot. Every copy starts from the saved state, and changes only its own files:

session-samsandboxcopyfrom the snapshotpnpm installsnapshotagent editspnpm testsession-samsandboxcopyfrom the snapshotpnpm installsnapshotagent editspnpm test
session-sam installs dependencies and takes a snapshot. The copy starts with them installed, and the agent's later edits stay in session-sam.
yield* sandbox.exec(["pnpm", "install"], { cwd: "/work" });
const image = yield* sandbox.snapshotFilesystem();

The result is an image. Pass it to create:

const next = yield* sandboxes.create({ image });

A sandbox created with enableSnapshot can save its memory too. The copy resumes with its processes running:

const sandbox = yield* sandboxes.create({ enableSnapshot: true });
const snapshot = yield* sandbox.snapshotMemory();
const restored = yield* sandboxes.restore(snapshot, { name: `session-${user}` });
const workspace = yield* sandbox.snapshotDirectory("/work");
yield* other.mountDirectory("/work", workspace);

other gets a copy of /work and nothing else from the original.