Snapshot and restore running SmolVM sandboxes to checkpoint agents, preserve configured environments, retry failed steps, and skip cold-start setup.
Snapshots let you save a sandbox and bring it back later. This is useful when you want to keep a configured environment, retry a failed step, or checkpoint an agent’s progress before a risky operation.A full snapshot captures the VM’s CPU state, memory, and disk. When you restore it, the sandbox resumes where it was when you created the snapshot.
Snapshots are available on Firecracker and QEMU for Linux guests that use isolated disks. Windows guests, workspace mounts, and extra drives are not supported yet. QEMU snapshots require a qcow2 per-VM disk, so raw QEMU disks created for grow_filesystem=True cannot be snapshotted.
Checkpoint before risky operations — Save state before an agent runs untrusted code, so you can roll back if something goes wrong.
Reuse a configured environment — Set up a sandbox with the right packages and files, snapshot it, and restore it multiple times instead of repeating setup.
Speed up agent workflows — Skip boot and configuration time by restoring from a ready-to-go snapshot.
To create a snapshot, the VM must be running or paused. SmolVM pauses the VM during snapshot creation and optionally resumes it afterward.
Python SDK
CLI
from smolvm import SmolVMvm = SmolVM()vm.start()# Install packages and configure the environmentvm.run("apk add python3 py3-pip")vm.run("pip install requests")# Save the current statesnapshot = vm.snapshot(snapshot_id="my-checkpoint")print(f"Snapshot created: {snapshot.snapshot_id}")vm.close()
By default, the VM stays paused after a snapshot. Pass resume_source=True to keep working with it:
snapshot = vm.snapshot( snapshot_id="my-checkpoint", resume_source=True,)# VM is still running — you can continue using itresult = vm.run("echo 'still running'")
If you omit snapshot_id, SmolVM generates one automatically (for example, snap-my-vm-1717012345).
When you create a snapshot, you can pick how much of the VM to store:
full (default) — Saves a complete, self-contained disk copy plus the guest’s memory and CPU state. Use this when you want to resume the sandbox exactly where you left off.
diff — Saves a smaller disk artifact. On QEMU, the snapshot state is stored inside the qcow2 artifact and the backing image must still exist at restore time. On Firecracker, SmolVM still captures memory and VM state in full, and uses a copy-on-write disk copy when the host filesystem supports it.
disk — On QEMU, saves only the disk and skips the memory dump. Restoring boots the sandbox fresh from that disk instead of resuming the exact running process state. Use this when you only need filesystem state and a cold boot is acceptable.
On Firecracker, VM state and memory files are captured for every snapshot type. This means disk is mainly useful on QEMU today.
QEMU disk snapshots are much faster and use less space than full because they skip the RAM dump. They are the right choice for suspend/restore workflows where you only need the filesystem state.
Python SDK
CLI
from smolvm import SmolVMvm = SmolVM()vm.start()# Space-saving snapshot — stores only what changed since the base imagesnapshot = vm.snapshot( snapshot_id="nightly-checkpoint", snapshot_type="diff",)print(snapshot.snapshot_type) # SnapshotType.DIFFvm.close()
You can also pass the SnapshotType enum for type safety:
from smolvm import SnapshotTypesnapshot = vm.snapshot(snapshot_type=SnapshotType.DIFF)
# Space-saving snapshotsmolvm snapshot create my-vm --snapshot-type diff# QEMU disk-only snapshot — fast, no RAM dump, restores as a cold bootsmolvm snapshot create my-vm --snapshot-type disk# Full snapshot (default — same as omitting the flag)smolvm snapshot create my-vm --snapshot-type full
Take a QEMU disk snapshot when you want to save the filesystem state quickly and don’t need to resume the running process state:
from smolvm import SmolVM, SnapshotTypevm = SmolVM(backend="qemu")vm.start()vm.run("apk add python3")# Fast, lightweight snapshot — disk only, no RAMsnapshot = vm.snapshot( snapshot_id="cold-boot-checkpoint", snapshot_type=SnapshotType.DISK,)# Later — restoring boots the sandbox fresh from the saved diskvm = SmolVM.from_snapshot("cold-boot-checkpoint", resume_vm=True)result = vm.run("python3 --version") # python3 is already installed
If the backing image for a QEMU diff snapshot is missing at restore time, SmolVM raises a clear error pointing to the missing path and suggesting you take a full snapshot instead. To stay safe, keep backing images in place while their diff snapshots exist.
Restoring a snapshot recreates the original VM with the saved state. The restored VM starts in a paused state by default.
Python SDK
CLI
from smolvm import SmolVM# Restore and resume the VM in one stepvm = SmolVM.from_snapshot("my-checkpoint", resume_vm=True)print(f"Restored VM: {vm.vm_id}")print(f"Status: {vm.status}") # VMState.RUNNING# The VM is back exactly where it wasresult = vm.run("python3 -c 'import requests; print(requests.__version__)'")print(result.output)vm.close()
smolvm snapshot restore my-checkpoint --resume
A snapshot can only be restored once by default. If you need to restore the same snapshot again, use the force flag:
Python SDK
CLI
vm = SmolVM.from_snapshot("my-checkpoint", resume_vm=True, force=True)
from smolvm import SmolVMManagerwith SmolVMManager() as sdk: snapshots = sdk.list_snapshots() for snap in snapshots: print(f"{snap.snapshot_id} vm={snap.vm_id} restored={snap.restored}")
Deleting a snapshot removes the saved state files and metadata. You cannot delete a snapshot while a restored VM from that snapshot is still running.
Python SDK
CLI
from smolvm import SmolVMManagerwith SmolVMManager() as sdk: sdk.delete_snapshot("my-checkpoint")
smolvm snapshot delete my-checkpoint
Deleting a snapshot is permanent. SmolVM removes the saved files for that snapshot, including any disk, VM state, and memory artifacts that snapshot type created.
This example shows how an agent can checkpoint a sandbox before running untrusted code, then roll back if something fails.
from smolvm import SmolVM, SmolVMError# Set up a sandboxvm = SmolVM()vm.start()vm.run("apk add python3")# Checkpoint before the risky stepsnapshot = vm.snapshot(snapshot_id="before-experiment")vm.close()# Restore and try the experimentvm = SmolVM.from_snapshot("before-experiment", resume_vm=True)result = vm.run("python3 -c 'import this_will_fail'")if not result.ok: print("Experiment failed — rolling back") vm.stop() vm.delete() # Restore from checkpoint and try a different approach vm = SmolVM.from_snapshot("before-experiment", resume_vm=True, force=True) result = vm.run("python3 -c 'print(42)'") print(result.output) # 42vm.close()
Snapshot IDs must contain only lowercase letters, numbers, hyphens, and underscores. SmolVM validates this on creation and raises an error for invalid IDs.Valid examples: my-checkpoint, snap-agent-001, pre-deploy-v2
SmolVM provides specific exceptions for snapshot operations:
from smolvm import ( SmolVM, SnapshotAlreadyExistsError, SnapshotNotFoundError, SnapshotType, SmolVMError,)try: snapshot = vm.snapshot(snapshot_id="my-checkpoint")except SnapshotAlreadyExistsError: print("A snapshot with this ID already exists")except SmolVMError as e: print(f"Snapshot failed: {e.message}")try: vm = SmolVM.from_snapshot("missing-snapshot")except SnapshotNotFoundError: print("Snapshot not found")