Skip to content

Pause, resume, snapshots and forks

A pause keeps the sandbox’s memory and disk, including running processes. A resume brings it back where it was. connect resumes a paused sandbox for you.

from svm import Sandbox
with Sandbox.create(template="base") as sandbox:
sandbox.files.write("/tmp/state.txt", "kept across a pause\n")
sandbox.pause(wait=True)
print(sandbox.get_info().state) # paused
sandbox.resume()
print(sandbox.files.read_text("/tmp/state.txt"))
# From anywhere that has the id: connect resumes a paused sandbox.
sandbox.pause(wait=True)
again = Sandbox.connect(sandbox.id)
print(again.files.read_text("/tmp/state.txt"))

Four settings control what happens:

Setting Values Where
on_timeout pause keeps the sandbox; kill deletes it lifecycle at create, or set_lifecycle
auto_resume true: a request to the public URL wakes a paused sandbox lifecycle at create, or set_lifecycle
mode memory (default) keeps memory and disk; filesystem keeps only the disk pause
on_resume restore (default) brings back memory and processes; reboot boots cold from the disk resume, connect

resume and connect return once the sandbox runs, waiting up to 120 seconds. After that they raise the SDK’s timeout error.

A snapshot captures a sandbox so that you can start new sandboxes from it later. Use one for a warmed-up environment, or for a checkpoint before a risky step. A fork copies a running sandbox into live children directly.

from svm import Sandbox
with Sandbox.create(template="base") as sandbox:
sandbox.files.write("/tmp/model.txt", "trained\n")
snapshot = sandbox.create_snapshot(name="after-training")
restored = Sandbox.from_snapshot(snapshot["snapshot_id"])[0]
try:
print(restored.files.read_text("/tmp/model.txt"))
finally:
restored.kill()
copies = sandbox.fork(count=2) # memory, disk and running processes
try:
for copy in copies:
print(copy.id, copy.commands.run("cat /tmp/model.txt").stdout)
finally:
for copy in copies:
copy.kill()
sandbox.delete_snapshot(snapshot["snapshot_id"])

From the CLI:

Terminal window
svm snapshot create <sandbox-id> --name before-migration
svm snapshot fork <snapshot-id> --count 8 --timeout-seconds 600
svm sandbox fork <sandbox-id> --count 4 --metadata branch=a

To try many approaches at once and keep the best, use rollouts.