Snapshots are coming soon and not yet available in the current SDK.
Snapshots capture the full VM state: memory, CPU registers, filesystem, everything. From a single snapshot you can fork hundreds of sandboxes, each starting exactly where the original left off with no re-boot or dependency reinstall. Forks are cheap because each one gets its own copy-on-write filesystem.
Particularly useful for agent workloads where every sandbox needs the same base environment (Python + packages, Node + node_modules, etc). Install once, snapshot, fork on demand.
Create a snapshot
Capturing a snapshot pauses the sandbox, saves its state, and returns a handle. You can resume the original sandbox afterward.
use microsandbox::Sandbox;
let sb = Sandbox::builder("base")
.image("python:3.12")
.create()
.await?;
sb.exec("pip", ["install", "-r", "requirements.txt"]).await?;
let snapshot = sb.snapshot().await?;
sb.resume().await?;
Save and load named snapshots
Persist a snapshot under a name so it survives beyond the lifetime of the original sandbox. Load it later to fork workers without keeping the base sandbox around.
use microsandbox::Snapshot;
// Save
let snapshot = sb.snapshot().await?;
snapshot.save_named("after-pip-install").await?;
// Load by name
let saved = Snapshot::get("after-pip-install").await?;
Fork workers
Restore multiple sandboxes from a single snapshot. Each fork skips the entire setup phase and starts running immediately from the captured state.
use microsandbox::Snapshot;
let saved = Snapshot::get("after-pip-install").await?;
let workers: Vec<Sandbox> = futures::future::try_join_all(
(0..10).map(|i| saved.restore(format!("worker-{i}")))
).await?;
Restore with overrides
Override memory, CPU count, or environment variables when restoring. The VM state is restored from the snapshot, but the overridden configuration takes effect on the new sandbox.
use microsandbox::Snapshot;
let saved = Snapshot::get("after-pip-install").await?;
let custom = saved.restore_with("custom", |r| r
.memory(1024)
.cpus(4)
.env("WORKER_ID", "42")
).await?;
List and delete snapshots
use microsandbox::Snapshot;
let snapshots = Snapshot::list().await?;
Snapshot::delete("old-snapshot").await?;