Snapshots let you capture a Sandbox filesystem as an immutable artifact, then restore it into new Sandboxes or turn it into a reusable base image.Use snapshots when you want to:
Fork Sandboxes to test different variations of code
Initialize Sandboxes with existing state for faster cold starts
Save a reproducible environment you can return to later
Snapshots capture filesystem state only, so running processes and environment
variables are not preserved. Memory snapshots will be released in early
September 2025.
from beam import Image, Sandbox# Create a sandbox and make some changes to the filesystemsandbox = Sandbox(cpu=1).create()p = sandbox.process.exec("sh", "-c", "mkdir -p /something && touch /something/file.txt")# Read the logsp.wait()print(p.logs.read())# Generate a filesystem snapshot and terminate the sandboxsnapshot_id = sandbox.snapshot()sandbox.terminate()
from beam import Image, Sandbox# Create a new sandbox and restore the snapshotsandbox = Sandbox().create_from_snapshot(snapshot_id)# This sandbox uses the filesystem state from the snapshot created abovep = sandbox.process.exec("ls", "-l", "/something")p.wait()print(p.logs.read())sandbox.terminate()
You can use Snapshots as a base image for any other abstraction or Sandbox on Beam, using Image.from_snapshot:
Copy
Ask AI
from beam import Image, Sandbox# Creates an image from a snapshotimage = Image().from_snapshot(snapshot_id)sandbox = Sandbox(image=image).create()p = sandbox.process.exec("ls", "-l", "/something")p.wait()print(p.logs.read())sandbox.terminate()