Skip to content

You’ll pause a sandbox and resume it, then fork it into two copies and change one of them. You need a server on gVisor, Firecracker or vz, 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
# Pause it, which saves its memory to disk. The list shows it as paused.
shard pause base
shard list
# Resume it. Its processes carry on where they left off.
shard resume base
# Fork it twice. Each fork prints its ID.
shard fork --name try-a base
shard fork --name try-b base
# Change one fork only. The first prints 2.31.0, the second base's version.
shard exec try-a pip install requests==2.31.0
shard exec try-a python -c 'import requests; print(requests.__version__)'
shard exec try-b python -c 'import requests; print(requests.__version__)'
# Remove all three.
shard remove --force try-a try-b base

A paused sandbox uses no memory on the host. It keeps its record, its files and its address, and resume continues its processes from the instant they paused.

  • A pause ends running commands. An exec still running ends, and a new one fails with sandbox base is paused: resume it with shard resume base.
  • A stop deletes the checkpoint. shard stop on a paused sandbox ends it, so you can no longer resume it. Its files stay, and shard start boots it fresh from them.
State In the fork
Files yes, as its own copy
Memory, and the processes that ran yes, from where they left off
The memory, CPU and disk bounds yes, the source’s
Secret grants and the network policy yes
The ID, the name and the network address no, the fork gets new ones
Logs and port forwards no

A fork takes no bounds of its own, so the --memory 512MiB on base applies to every fork of it. The copied secret grants are the fork’s own: an ungrant or a stop of the source does not change them.

Set up one sandbox with what every task needs, and leave it running. Then fork it once for each new task, so no task waits for the setup.

The source freezes for a moment while shard copies its memory and files, then keeps running with the same processes and ID.

  • On gVisor, a freeze of 10 minutes fails the fork. The source then thaws.
  • On Firecracker and vz, a running exec can lose its stream. The command keeps running in the source, but nothing reads its output.
  • On Firecracker and vz, an exec that starts during the freeze is refused. The error ends with a fork holds the sandbox frozen, and nothing starts in it until that ends: run the command again. Run it again after the fork returns.
  • A running sandbox only. A fork of a stopped sandbox fails with sandbox <name> is stopped: fork takes a running sandbox. To copy one, take a snapshot: see Snapshot a sandbox and create from it.
  • gVisor, Firecracker and vz. On Sysbox and runc, pause, resume and fork fail with an error such as provider sysbox does not support fork on this host. shard capabilities shows what your server supports: see Providers and capabilities.
  • A token needs sandbox:write. A fork also needs secret:* when the source has secret grants, and policy:* when it has a network policy.

Pause, resume and fork explains how shard keeps the checkpoint and what a daemon restart does to it.