Snapshots & forks

On-demand disk snapshots, copy-on-write forks, and recovering a sandbox from a snapshot.


A snapshot is an immutable copy of a sandbox's disk that you create on demand. A fork is a new sandbox that starts from a parent's disk state. Both are disk-level: neither copies live memory or running processes.

Create a snapshot#

createSnapshot returns immediately with a snapshot in a pending state. Poll getSnapshot until it is ready (7-11 s measured at size s). A saved snapshot keeps its source sandbox pinned: you cannot delete the source while the snapshot exists.

import { randomUUID } from "node:crypto";

const { revision } = await sandal.sandboxes.get(sandboxId);
const admitted = await sandal.sandboxes.createSnapshot(sandboxId, {
  idempotencyKey: randomUUID(),
  expectedSandboxRevision: revision,
});

let snapshot = await sandal.sandboxes.getSnapshot(sandboxId, admitted.snapshot.id);
while (snapshot.state !== "ready") {
  if (snapshot.state === "failed") throw new Error(`snapshot failed: ${snapshot.failureCode}`);
  await new Promise((r) => setTimeout(r, 500));
  snapshot = await sandal.sandboxes.getSnapshot(sandboxId, snapshot.id);
}
console.log(snapshot.id);

const { snapshots } = await sandal.sandboxes.listSnapshots(sandboxId);

From the CLI: sandal snapshot create <sandbox> (waits until ready), sandal snapshot list <sandbox>, sandal snapshot get.

What a snapshot contains#

  • The sandbox's filesystem: everything you wrote, installed packages, build artifacts, virtualenvs, node_modules.

What it does not contain#

  • Memory and processes. Restoring or forking from a snapshot boots the machine fresh: snapshots and forks are disk-level. Memory is kept only by pause/resume on the same sandbox; there are no memory snapshots, and stop/start keeps only the disk.
  • Open network connections. Anything mid-request must be retried.
  • Environment you only exported in a shell. If it was never written to disk, it is not in the snapshot.

Snapshots are taken when you ask for them. Automatic periodic snapshots are not a feature you can rely on today.

Recover from a snapshot#

recover brings an archived or failed sandbox back to running. Pass snapshotId to roll the sandbox back to a specific ready snapshot of its own:

const { revision } = await sandal.sandboxes.get(sandboxId);
const { operation } = await sandal.sandboxes.recover(sandboxId, {
  idempotencyKey: randomUUID(),
  expectedRevision: revision,
  snapshotId: snapshot.id, // optional; omit to recover the latest state
});
await sandal.sandboxes.waitForOperation(operation.id, { timeoutMs: 300_000 });

Archive followed by recover keeps files intact (verified in all three SDKs; recover takes 6-9 s). The CLI equivalent is sandal recover <sandbox>, optionally from a snapshot.

Fork a sandbox#

A fork is a new sandbox with its own id, starting from the parent's disk. Without a sourceSnapshotId, the server captures the parent's current state first, so every completed write is in the fork. The parent keeps running.

const { revision } = await sandal.sandboxes.get(parentId);
const forked = await sandal.sandboxes.fork(parentId, {
  idempotencyKey: randomUUID(),
  expectedRevision: revision,
  name: "child-a",
  lifecycle: { expiresAt: new Date(Date.now() + 60 * 60_000) },
});
await sandal.sandboxes.waitForOperation(forked.operation.id, { timeoutMs: 300_000 });
console.log(forked.sandbox.id); // a new, running sandbox with the parent's files

Optional inputs: sourceSnapshotId forks a specific ready snapshot instead of the current state. CLI: sandal fork <sandbox> --name <name>.

Fork currently takes 10-15 s end to end (measured on production), so it pays off when setup is the expensive part: do pip install / npm install / a repo clone once, then fork per experiment. Each fork counts against your concurrent-workload quota (64 per project today; see Limits), and forking needs room for both parent and child.

What a fork inherits#

  • Disk contents, yes. If the parent's disk holds credentials (an API key in a config file, an SSH key), those bytes are copied. Rotate anything sensitive per child if forks should have separate blast radii.
  • Memory, processes, open connections, no. The child boots fresh from the copied disk. A computation in progress in the parent does not continue in the child.
  • Port exposures, no. The child has its own id; expose its ports separately.
  • Lifecycle, no. The child has its own lifecycle (pass it at fork time) and its own revision.

Memory-level ("live") fork and memory snapshots are not available. Volume snapshots are not available either (422).

Failure policy#

  • A snapshot that fails ends in state failed with a failureCode; earlier ready snapshots are unaffected.
  • archive is reversible (recover); delete is not.
  • Automatic deletion only happens if a lifecycle policy asks for it: autoDeleteAfterSeconds on the sandbox or inherited from the project default. Check sandal lifecycle get <sandbox> and sandal lifecycle defaults before relying on an idle sandbox to keep its data. See Sandboxes.

If the platform ever discards sandbox state without a delete call or a lifecycle policy that asked for it, that is a bug. Report it to hello@sandal.dev.