Skip to content

Snapshots

A snapshot captures the filesystem and memory of a running sandbox. The source sandbox is briefly paused while the snapshot is created, then continues with the same ID. The snapshot can start more than one new sandbox.

mjs
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create();
let restored;
let snapshot;

try {
  await sandbox.files.write("/tmp/checkpoint.txt", "state from snapshot");
  snapshot = await sandbox.createSnapshot();

  restored = await Sandbox.create(snapshot.snapshotId);
  console.log(await restored.files.read("/tmp/checkpoint.txt"));
} finally {
  if (restored) await restored.kill();
  await sandbox.kill();
  if (snapshot) await Sandbox.deleteSnapshot(snapshot.snapshotId);
}

Creating a snapshot interrupts active command streams, PTYs, and connections to services in the source sandbox. Reconnect them after the operation.

Use a snapshot for runtime checkpoints and rollback points. Use a template when the starting environment can be described as repeatable build steps. Call deleteSnapshot or delete_snapshot when a checkpoint is no longer needed.