Before you begin
You need the following:- A Linux machine for
host fetch; the other host commands also run on macOS and Windows. - A mount helper that speaks the requests in Out-of-process
snapshots.mountHelper, with its socket, its images folder, and its slots folder. To try the commands without one, the repository’s stand-in helper (test/helpers/stand-in-mount-helper.ts) answers the same requests. - Snapshot storage and its credentials (see Store snapshots in the cloud).
- The signed records your helper checks before it attaches a generation. Your host’s control plane makes them.
- These environment variables on every host command, so no
settings.jsonfile changes what runs:ATOMIC_SNAPSHOTS=1,ATOMIC_SNAPSHOTS_SETTINGS_SOURCES=env,flags,ATOMIC_SNAPSHOTS_STORAGE,ATOMIC_SNAPSHOTS_MOUNT_HELPER,ATOMIC_SNAPSHOTS_MOUNT_HELPER_IMAGE_DIR, andATOMIC_SNAPSHOTS_MOUNT_HELPER_SLOT_DIR. Each one can also be passed as a flag.
Run the host steps from the CLI
The following steps build a base on one machine, then start, save, and wake a worktree in a helper slot. Each command prints one JSON document with--json.
-
On the build machine, after your helper made and filled
HELPER_IMAGE_DIR/IMAGE_ID.img, have the helper keep a copy of it:The output names the copy’shandle, for example{"handle": "hb-1.1", ...}. -
Publish the copy as a base:
Confirm that the output has
base.baseId,base.rawSha256, andbase.compactSha256. Keep all three: every later step checks them. -
Have the helper delete its copy:
-
Optional: On a machine that runs worktrees, if your helper adopts bases from a file, place the base there:
-
Start generation 0 of a chain in a slot:
-
After each turn, save the next generation:
Confirm that the last line is
{"type":"result","saved":true,...}with"generation"one more thanGENERATION. -
To wake the worktree, on this machine or another, restore the generation your host last saw into a slot:
Confirm that the output has
"status": "restored". If this machine set a worktree up in that slot before, the restore refuses withchain-conflictuntil you add--force, which discards whatever the slot still holds. -
When the worktree sleeps, or after a host run was killed, detach its image:
Confirm that the output has
"detached": true. Running it again is safe:"alreadyDetached": true.
HELPER_IMAGE_DIRandHELPER_SLOT_DIR: your helper’s images and slots folders.IMAGE_IDandSLOT: the names your helper gave the built image and the worktree’s slot.HANDLE: thehandlefrom step 1. It can be passed as JSON ('"hb-1.1"') or as the bare string.REPOSITORY_URL: the repository the base was built from.BASE_ID,RAW_SHA256, andCOMPACT_SHA256: thebaseId,rawSha256, andcompactSha256from step 2.BASE_FILE: where your helper reads a base from.CHAIN_ID: the ID of the worktree’s chain.RECORD_FILE: a file holding the signed record your helper checks for the generation it attaches.TURN_ID: your host’s ID for the turn the save records.GENERATION: the chain head your host last saw (0before the first save).SCAN_FILE: a file holding{"values": ["..."]}, the values that must never be uploaded (mode0600on Linux and macOS).
Host commands
atomic snapshots host --help lists these commands; atomic snapshots --help doesn’t. The following syntax covers every atomic snapshots host command:
HASH: the environment hash (--env-hash) or blueprint hash (--blueprint-hash) recorded with a base.COMMIT: the commit the base was built from (--head).COMPRESSION:zstd(the default) ornone.FILE_OR_BASE_ID: an image file to package as a base, or the ID of a base in storage.FILE_OR_JSON: a file holding the helper’s record, or the record itself.SNAPSHOT_ID: the ID of one saved generation, asatomic snapshots list --chain CHAIN_IDshows it.MODE: how a save finds changed blocks (--engine):auto,metadata-only, orcontent.N: a generation number.HEX: a SHA-256 in hex.PATH,DIR, andURL: a file, a folder, and a storage URL.
--expect file, --scan-secrets-file, --mount-helper-image-dir, or --mount-helper-slot-dir is read from the folder you run the command in, even with --worktree, never from the worktree.
Keep, publish, and release a built image
host checkpoint --image HELPER_IMAGE_DIR/IMAGE_ID.img has the helper copy an image it created and keep the copy. It prints the helper’s handle, attestation, and position, and the next commands to run.
host publish --handle HANDLE publishes that copy as a prepared base. Atomic reads the copy only through the read-only descriptor the helper sends, never by a path. Once the base is stored, it prints {"base": {...}, "reused": BOOLEAN} with the base ID, rawSha256, and compactSha256. Publishing the same bytes again reports "reused": true. Publishing a handle the helper no longer keeps (it was released) refuses with not-mounted and says to keep a new copy with host checkpoint.
host release --handle HANDLE has the helper delete the copy. A handle the helper no longer knows counts as released ("alreadyReleased": true).
Fetch a base for the helper
host fetch BASE_ID --expect-raw-sha256 HEX --output PATH writes a base read-only (0444) at PATH. It does so only when the base’s record names exactly that ID and those SHA-256s (otherwise wrong-base) and the downloaded image hashes to them.
It checks a copy in a private folder through one descriptor, then links that file into place. It never replaces an existing file or follows a link. It resolves links in PATH first, makes missing folders 0755 (less what your umask removes), and prints where it placed the file.
It refuses with invalid-setting an output folder, or a folder above it, that anyone but you or root could rename files in: one owned by another user, or writable by its group or by others without the sticky bit (/tmp is fine). The message prints the chmod that fixes it.
It works on Linux only, and only on ext4, XFS, btrfs, or tmpfs, for the output folder and each folder above it. On macOS, Windows, overlayfs (such as a container’s root), and network file systems such as NFS or SMB it refuses: ACLs or lower layers there can let others change a folder in ways its mode doesn’t show.
Cache and check bases
host ensure BASE_ID downloads a base and caches it read-only (0444) in snapshots.baseCacheDir, scoped per storage URL. It checks the SHA-256 of every byte against rawSha256 first (in parallel, one GiB per CPU core, when the base records segment hashes). --verify-base hashes a cached base again.
host seed FILE_OR_BASE_ID packages a local image file as a base, or ensures an existing base.
host verify checks the cached bases not checked in the last 24 hours and removes any that no longer match. It prints how many it checked and how many aren’t due yet; --all checks every cached base. A restore downloads and checks the base it needs by itself, so these commands are for warming a cache or an idle-time check.
Detach an image
host detach --image PATH asks the mount helper to detach one image, for example after a host run was killed. The image must be in the helper’s images folder. When the helper has nothing attached for the image, it exits 0 and --json reports "alreadyDetached": true, so running it again is safe. Without a mount helper it fails with invalid-setting.
Start, save, restore, and roll back with checks
host init, host save, host restore, and host rollback run the commands of the same name with the host options in the following table. The same commands without host refuse a host option with exit 2, for example Error: --head-must-be is a host option. Use "atomic snapshots host save …", before anything runs. Environment variables (ATOMIC_SNAPSHOTS_*) apply to both.
host restore restores into an existing chain only. To start a new chain from a stored generation, run atomic snapshots fork --from-chain CHAIN_ID.
A host re-restoring the head into a worktree it already holds passes --force (force: true in the SDK). Atomic can’t confirm that worktree’s files when a mount helper mounted it (see Mount helper slots), or when an SDK mountController did and Atomic has no record of its files, so without --force the restore refuses with chain-conflict and changes nothing. A session opening there keeps the worktree as it is.
A usage mistake exits 2. With --json-events alone it prints one line on stderr, with --json alone a JSON error on stdout, and with both one {"type":"result","error":{"code":"usage",...}} line on stdout.
Scan a save for secrets
--scan-secrets-file PATH names a file holding {"values": ["..."]}. On Linux and macOS it must be a regular file with mode 0600, owned by you, and not a link. On Windows, Atomic checks only that it is a regular file, not its permissions, its owner, or whether it is a link. Each value must be at least 8 bytes, since a shorter one would match ordinary data, and valid Unicode text, with no half of a surrogate pair (as \ud800 alone in JSON). Otherwise the save refuses with invalid-setting before anything is paused.
The scan looks for each value in three encodings: UTF-8, UTF-16LE (how Windows stores most text) and UTF-16BE. Any other form of a value, such as base64, needs its own entry in the list.
When a listed value appears in a changed part of the image, the save refuses with secret-in-diff, uploads nothing, and leaves the head where it was. The message names the value’s position in the list, the encoding it was found in, and its byte offset, never the value.
Deleting the file that holds the value doesn’t clear it: the file’s bytes stay in the image’s free space, where the next save finds them again. Overwrite the value in place, or trim the worktree’s free space (for example fstrim on its mount), then save again with the same scan.
A save with --scan-secrets-file that would also upload a new base refuses with invalid-setting, because the scan reads only what changed against the base.
Mount helper slots
--mount-helper-image-dir DIR and --mount-helper-slot-dir DIR (or snapshots.mountHelperImageDir and snapshots.mountHelperSlotDir) name the helper’s folders. With a mount helper:
- The worktree folder must be
HELPER_SLOT_DIR/SLOT.root. - The image must be in the helper’s images folder:
--image HELPER_IMAGE_DIR/IMAGE_ID.img, orHELPER_IMAGE_DIR/SLOT.imgwhen you leave out--image. initandrestorerefuse any other folder or image withinvalid-settingbefore an image is made, naming the folder or image.- Atomic never creates, empties, lists, or resolves the slot’s folder (the helper owns it), keeps no listing of its files, and keeps the worktree’s local state under the slot’s name.
saverefuses a worktree or image outside those folders before it writes anything. On Linux and macOS it reads the helper’s checkpoint only through the descriptor the helper sends; an answer with only a path is given back and refused withio.headnever says a slot’s worktree is saved, because Atomic keeps no record of a slot’s files. When the slot’s local state names the stored head, or the slot has no local state, it printshead: unknownwith the stored head and exits1(saved: falsewith anunverifiedomission in the SDK). When the local state names an earlier generation than the stored head, it printshead: unsaved (chain CHAIN_ID, store head gen N)and exits1.- A restore or rollback into a slot this machine set a worktree up in refuses with
chain-conflictand touches nothing, not even the helper: Atomic keeps no record of a slot’s files, and the helper may keep them in a copy, so it can’t tell whether the worktree there has unsaved edits. Save first to keep them, or pass--forceto restore over them. A session opening in such a slot keeps the worktree as it is and asks the helper for nothing. - A restore builds the image again from storage unless the image file in the images folder holds the head itself, as it does right after a restore. A helper may attach a copy of the image, and saves read that copy, so after a save the file can still hold an older generation.
Settings and exit codes
SetATOMIC_SNAPSHOTS_SETTINGS_SOURCES=env,flags so host commands ignore project and global settings.json files and read only environment variables and flags; every command’s flags apply under it. Exit codes are those of atomic snapshots: 0 done, 1 failed, 2 usage mistake, and 143 (SIGTERM) or 130 (SIGINT) when stopped. A stop takes effect when the running step ends; a second signal stops it within seconds, without releasing the helper’s copy (see the CLI reference).
Host commands and SDK functions
The following table maps each host command to the TypeScript SDK function that does the same; the SDK options are in the Worktree snapshots reference:Run the host steps from the SDK
A pool host that runs worktree images through its own root mount helper builds bases on one machine, wakes and saves worktrees on others, and expects each step to touch only what it names. The following example shows the three host steps, with the same settings a host passes to the CLI as flags or environment variables:ACCOUNT_NAME: your storage account name.OWNER/REPO: the repository the base was built from.SIGNED_RECORDandSIGNED_RECORD_OF_GENERATION_1: the signed records your host’s helper checks before it attaches generation 0 and generation 1.TURN_IDandHELPER_BASE_ID: the host’s ID for the turn and the base ID the helper adopted, which the helper signs into the checkpoint.
atomic snapshots host checkpoint, publish, release, and fetch, then host init, host save, and host restore.
What a host keeps between sleep and wake
A host that stops a machine between turns can wake its worktree on another machine from storage, without anything the first machine kept locally. The new machine must run the same operating system and image format as the base (otherwiserestore refuses with os-mismatch), be able to read the storage with its credentials, and have the encryption key when client-side encryption is on. With a mount helper, the host also passes the signed record the helper checks before it attaches (--expect). Keep the following:
You can drop the following; a wake rebuilds them:
Wake with
atomic snapshots host restore --chain CHAIN_ID --into DIR --head-must-be GENERATION --json, where DIR is the worktree folder (with a mount helper, HELPER_SLOT_DIR/SLOT.root) and GENERATION is the head generation your host last saw (0 when the chain was never saved). What restore does depends on the stored head:
A refusal happens before
restore mounts or writes anything, and exits 1. A chain-conflict refusal carries expectedGeneration (the --head-must-be value) and, when the chain has a head, headGeneration (that head’s generation). The messages are:
- No head:
Chain "CHAIN_ID" has no head, but this restore expected generation GENERATION (--head-must-be GENERATION); nothing was mounted or changed. Run `atomic snapshots list --chain CHAIN_ID` to see the chain. - Another head: the message starts
Chain "CHAIN_ID" head is at generation HEAD_GENERATION, but this restore expected generation GENERATION, orexpected no headwith--head-must-be 0.