Skip to content

Snapshot a sandbox and create from it

You’ll install a package in a sandbox, save its files as a snapshot, and start a new sandbox from it with the package already there. You need a shard server and a client: see Create a sandbox, run commands and move files.

Terminal window
# Create a sandbox and install a package in it.
shard create --name base --memory 512MiB python:3.12
shard exec base pip install requests
# Stop it, then copy its files into a snapshot. Prints the snapshot's ID.
shard stop base
shard snapshot create --name py-requests base
# List your snapshots. Prints py-requests, its source and its size.
shard snapshot list
# Create a sandbox from the snapshot. Prints the version of requests.
shard create --name worker --memory 512MiB --snapshot py-requests
shard exec worker python -c 'import requests; print(requests.__version__)'
# Remove both sandboxes, then the snapshot.
shard remove --force worker
shard remove base
shard snapshot remove py-requests

A snapshot is a copy of a stopped sandbox’s files. It holds no memory and no processes, and it outlives the sandbox it came from.

  • The source must be stopped. A snapshot of a running or paused sandbox fails with 409 sandbox_not_stopped, because its memory holds what a copy of its files would miss.
  • Each create gets its own copy. Every sandbox made from a snapshot has its own files, ID and address, so many sandboxes can start from one snapshot.
  • A snapshot names its image. A create from it needs that image at the same digest on the server, and never downloads one.

A snapshot does not hold secrets or a network policy. Pass --secret and --policy to each create from it, as you would for an image. See Credential brokering and Network policy and proxy.

A sandbox made from a snapshot starts with no processes. If you leave out --memory or --disk, it gets the bounds its source ran with.

A snapshot copies files from a stopped sandbox. A fork copies memory, processes and files from a running one, and works only on gVisor, Firecracker and vz. See Pause, resume and fork a sandbox.

Images and snapshots covers every snapshot command and how each provider makes the copy.