Skip to main content
Snapshots capture the filesystem state of a running sandbox. Use them to save work mid-session and restore it later in a new sandbox — useful for checkpointing long-running tasks, cloning environments, or resuming interrupted work.

Creating a Snapshot

Create a snapshot from a running sandbox using snapshot_and_wait():
from tensorlake.sandbox import SandboxClient

client = SandboxClient()

# Create a sandbox and do some work
sandbox = client.create_and_connect()
sandbox.commands.run("pip install numpy pandas")
sandbox.commands.run("python -c \"import pandas as pd; pd.DataFrame({'a': [1,2,3]}).to_csv('/data/output.csv')\"")

# Snapshot the sandbox filesystem
snapshot = client.snapshot_and_wait(sandbox.sandbox_id)
print(snapshot.snapshot_id)  # Use this to restore later
For more control over the async operation, use snapshot() and poll with get_snapshot():
result = client.snapshot(sandbox.sandbox_id)

# Poll until complete
import time
while True:
    info = client.get_snapshot(result.snapshot_id)
    if info.status.value == "completed":
        break
    if info.status.value == "failed":
        raise Exception(f"Snapshot failed: {info.error}")
    time.sleep(1)

Restoring from a Snapshot

Create a new sandbox from a snapshot. The new sandbox inherits the image, resources, entrypoint, and secrets from the snapshot unless explicitly overridden.
# Restore a sandbox from a snapshot
restored = client.create_and_connect(snapshot_id=snapshot.snapshot_id)

# The filesystem state is preserved
result = restored.commands.run("cat /data/output.csv")
print(result.stdout)
You can override inherited settings when restoring:
restored = client.create_and_connect(
    snapshot_id=snapshot.snapshot_id,
    cpus=4.0,          # Override CPU allocation
    memory_mb=2048,    # Override memory
)

Managing Snapshots

List Snapshots

snapshots = client.list_snapshots()
for s in snapshots:
    print(f"{s.snapshot_id} | {s.status.value} | {s.size_bytes} bytes")

Get Snapshot Details

info = client.get_snapshot("snapshot_id")
The SnapshotInfo object contains:
FieldTypeDescription
snapshot_idstrUnique snapshot identifier
namespacestrNamespace the snapshot belongs to
sandbox_idstrID of the sandbox that was snapshotted
base_imagestrContainer image of the original sandbox
statusSnapshotStatusin_progress, completed, or failed
errorstr | NoneError message if the snapshot failed
size_bytesint | NoneSize of the snapshot in bytes
created_atdatetime | NoneWhen the snapshot was created

Delete a Snapshot

client.delete_snapshot("snapshot_id")

snapshot_and_wait Parameters

ParameterTypeDefaultDescription
sandbox_idstrID of the running sandbox to snapshot
timeoutfloat300Max seconds to wait for completion
poll_intervalfloat1.0Seconds between status polls