The default snapshot policy excludes secrets, git metadata, and install trees. A capture or restore stops when it finds an unsafe filesystem entry.
Portable snapshots store regular files with their permission bits, directories, and symlinks. A capture fails with SandboxSnapshotError code SANDBOX_SNAPSHOT_UNSUPPORTED_ENTRY when it finds one of these entries:
A restore fails with the same code when the destination workspace has a fifo, a socket, or a device file.
Add the path to policy.exclude. The policy runs before this check, so an excluded path never fails. See Skip a link that leaves the workspace.
To write a checkpoint at another time, see Checkpoint at Any Time.
The default policy excludes these path segments at every depth:
It also excludes these exact paths:
These exclusions use paths for regular files and copied files too.
To keep only some files, or one file, see Pick Which Files to Keep. If you pass only include or only redact, the default exclusions stay in place. If you pass exclude, copy defaultSandboxSnapshotPolicy() first. Then add your rules.
import { defaultSandboxSnapshotPolicy } from '@tanstack/ai-sandbox'
const policy = {
...defaultSandboxSnapshotPolicy(),
redact({ bytes }: { bytes: Uint8Array }) {
return bytes
},
}When you create the snapshots object, pass policy. See Keep Files After Reload.
The exact projection marker for the workspace stays protected. A custom policy cannot capture or restore that marker.
Resolved secret values are replaced with zero bytes before the content is hashed or stored.
An invalid manifest, a missing blob, or changed blob content stops the restore before it writes the workspace. The failed private sandbox is then discarded. Your existing resumed sandbox stays unchanged.
See Providers for provider-native snapshot and resume support.