The TypeScript client supports snapshot mounts, restores, mid-life snapshots, and snapshot management, but not snapshot-on-stop.
Choose authentication
These examples run on serverless capacity unless a section specifies CoreWeave Kubernetes Service (CKS). Choose the credential for the account that owns your sandboxes. See Choose and get credentials to obtain a key or token. Save the configuration for your language beside the scripts you run from this page. Python examples importAUTH from sandbox_auth.py. TypeScript examples import client from sandbox-client.mts. These files select authentication without storing your credential. For Python, use an active virtual environment. For TypeScript, first install the client with npm install @coreweave/cwsandbox.
- Forge API key
- CoreWeave API access token
Use your Forge API key with the SDK’s
wandb integration. Replace [WANDB-API-KEY] with your API key:- Python
- TypeScript
sandbox_auth.py
placement_mode="cks" on sandbox creation or in SandboxDefaults. In TypeScript, choose the CoreWeave token and set a nonempty runnerIds array to select CKS. Creating a Python session with auth=AUTH also authenticates the sandboxes it owns. Keep the same credential when reconnecting, listing, or cleaning up sandboxes.
For the HTTP API examples, run the Bash commands from your credential tab in the same shell as the requests. The sandbox_headers array supplies the selected authentication header. The HTTP creation examples use serverless placement.
How it works
A sandbox with FSS mounts a writable scratch filesystem at a path you choose. The runner backs this mount with anEmptyDir, not a direct object storage mount. Snapshot and restore operations copy a tarball between that local filesystem and an organization-scoped object storage bucket.
Each snapshot is a FileSystemSnapshot resource identified by a server-assigned fileSystemSnapshotId. Snapshots have three defining properties:
- Immutable: creating a snapshot writes one archive. Restoring a snapshot never changes the source snapshot, so a later restore always sees the original bytes.
- Organization-scoped: you can restore only snapshots created in your own organization. A teammate with sandbox access in the same organization can restore your snapshot using their own credentials. A snapshot ID from another organization is treated as not found.
- Independent lifecycle: snapshots are managed separately from sandboxes. Deleting a sandbox does not delete its snapshots, and deleting a snapshot does not affect sandboxes already running from it.
Start a sandbox with a snapshot mount
A sandbox can start from one of two filesystem sources: a fresh, empty scratch filesystem, or a restore of an existing snapshot.Fresh scratch
A fresh scratch filesystem starts empty and can be snapshotted later. Use it for workflows that need writable local state during a run.- Python
- TypeScript
- HTTP API
Restore from a snapshot
A restore starts the filesystem from an existing snapshot. Set the snapshot ID on the mount’s snapshot source.- Python
- TypeScript
- HTTP API
READY before you restore it. Restoring a snapshot that is still CREATING fails. See Snapshot status and failures.
Plan for restore time
A snapshot restore copies and extracts its archive before the sandbox can run your application. Large model snapshots can take several minutes to restore. Startup time depends on the following factors:- Archive size
- File count
- Available CPU
- Local storage
- Network throughput
- Image startup work
CREATING alone doesn’t distinguish waiting for scheduling from restoring files. Before deleting a slow launch, check the sandbox’s status_reason and retain its ID for support. A fixed deadline can bound your wait, but elapsed time alone doesn’t establish that a restore has failed.
Take a snapshot
You can capture a snapshot in two ways: on stop, when a sandbox shuts down, and mid-life, from a running sandbox.Snapshot on stop
To preserve a sandbox’s filesystem when it shuts down, stop the sandbox with snapshot-on-stop enabled. This is the pattern for suspend and resume: stop with a snapshot, then later start a new sandbox that restores it.- Python
- TypeScript
- HTTP API
Mid-life snapshot
A mid-life snapshot captures a running sandbox without stopping it. The sandbox keeps running afterward.- Python
- TypeScript
- HTTP API
snapshot() waits until the snapshot is READY by default and returns the snapshot ID.Fork a snapshot
The same snapshot can be restored into more than one sandbox. Because each snapshot is immutable, the restored sandboxes start from identical bytes and then diverge as they write.- Create a
READYsnapshot, with either snapshot-on-stop or a mid-life snapshot. - Start sandbox A with
fileSystemSnapshotIdset to that snapshot. - Start sandbox B with the same
fileSystemSnapshotId. - Writes in sandbox A and sandbox B diverge independently. The source snapshot is unchanged, so a later restore from the same ID still sees the original snapshot, not the writes from either fork.
- Python
- TypeScript
Manage snapshots
List, fetch, and delete snapshots independently of the sandboxes that created them.- Python
- TypeScript
- HTTP API
list_snapshots(), get_snapshot(), and delete_snapshot() also accept an AuthHeaders object through auth.
Snapshot status and failures
Snapshots are created asynchronously. A snapshot request can succeed and return afileSystemSnapshotId while the archive is still being written, and the snapshot can fail afterward. This happens most often when waitForReady is false, or when a client timeout occurs while the runner is still archiving.
To check progress through the HTTP API, fetch the snapshot and read these fields:
status: the lifecycle state. The terminal values areFILE_SYSTEM_SNAPSHOT_STATUS_READYandFILE_SYSTEM_SNAPSHOT_STATUS_FAILED.statusReason: populated whenstatusisFILE_SYSTEM_SNAPSHOT_STATUS_FAILED, explaining why.
state and stateReason from the snapshot record. The corresponding state values are "ready" and "failed".
Poll GetFileSystemSnapshot until the snapshot is ready before you restore it. The Python client’s snapshot() and get_snapshot() handle this polling for you when you wait for the result. The TypeScript client’s snapshot() waits until state is "ready" and throws if the snapshot fails.
Recover from a failed snapshot request
While recovering from a mid-life snapshot failure, keep the source sandbox running. A snapshot remote procedure call (RPC) failure doesn’t itself delete the sandbox or its mount. If you leave a Python sandbox context manager or run teardown code, the sandbox can stop. Data that hasn’t reached a ready snapshot can be discarded. Handle the failure before that cleanup runs. First-use bucket provisioning can returnCWSANDBOX_FSS_BUCKET_PROVISIONING. The Python client retries transient snapshot RPC failures for a bounded budget. If provisioning outlasts that budget, retry with backoff while retaining the source sandbox. When retrying the same request after an ambiguous transport failure, reuse an explicit request_id so the server can deduplicate it. If a snapshot ID is available after a timeout, check that snapshot before requesting another archive. A snapshot that has reached FAILED requires a new request to capture the data again.
For Python client 1.19.6, transient snapshot failures can raise SandboxUnavailableError, while other snapshot failures raise SandboxSnapshotError. When preserving a build, handle both and use the error’s reason to decide whether retrying is appropriate. Don’t retry quota or configuration failures without addressing their cause.
The following table lists the common failure reasons and what to do about each.
If a runner finishes uploading the archive but cannot record the result, the snapshot row can become
FAILED even though an object exists in the bucket. Retry the snapshot in this case.
For asynchronous failures, the platform also emits a sandbox.file_system_snapshot.async_fail event, so downstream notification systems can react to snapshots that fail after the original call returned.
Limitations
FSS version 1 provides snapshot-backed local scratch storage. It is not a shared filesystem and does not provide live, multi-writer mounts. Sandboxes do not read or write each other’s filesystems while running. They share state only by snapshotting and restoring.SDK example
For a complete, runnable Python example that starts a sandbox, takes a mid-life snapshot, forks it, captures a snapshot on stop, and manages snapshots, seefile_system_snapshots.py in the cwsandbox-client repository. For TypeScript, file-system-snapshots.ts in the cwsandbox-js repository takes a mid-life snapshot, restores it, and manages snapshots.
Related resources
- Bring your own bucket for file system snapshots: store snapshots in a bucket you own.
- Volumes: scratch volumes and registered Volumes that several sandboxes share.
-
Sandbox lifecycle: how
stop()and the sandbox states work. - Python client: install the SDK and explore the API.