Leap0

Snapshots

Save a running sandbox and restore it later with the same in-memory and writable-disk state.

Snapshots let you create a point-in-time capture of a running sandbox, including its in-memory execution state and writable disk state.

You can then restore that snapshot into a brand new sandbox that starts from the same checkpoint.

If you only need to shut compute down and later boot the same sandbox with its writable disk changes, use sandbox stop/start instead. Snapshots are named, reusable checkpoints. Stopped sandboxes are not.

Sandbox state

Snapshots can only be created from a running sandbox. The VM is briefly paused during the capture and then resumed automatically unless you set kill_sandbox_after.

Restore behavior

Restoring a snapshot creates a brand new sandbox.

  • Compute settings come from the snapshot, not the restore request.
  • The snapshot's template is reattached automatically.
  • timeout can be overridden when restoring.
  • auto_pause can be enabled when restoring if you want the new sandbox to pause itself at timeout.
  • network_policy defaults to the snapshot values, but you can override it on restore.
  • Restore requests address snapshots by snapshot_name.

Create a snapshot

from leap0 import Leap0Client

client = Leap0Client()
sandbox = client.sandboxes.create()
snapshot = sandbox.create_snapshot(name="workspace-warm")

print(snapshot.id, snapshot.name)
import { Leap0Client } from "leap0";

const client = new Leap0Client();
const sandbox = await client.sandboxes.get("<sandbox_id>");
const snapshot = await sandbox.createSnapshot({
  name: "workspace-warm",
});

console.log(snapshot.id, snapshot.name);
await client.close();

Snapshot and terminate a sandbox

Use this when you want to create a named snapshot and shut the sandbox down immediately after the snapshot is stored.

from leap0 import Leap0Client

client = Leap0Client()
sandbox = client.sandboxes.create()
snapshot = sandbox.create_snapshot(name="workspace-warm", kill_sandbox_after=True)

print(snapshot.id, snapshot.name)
import { Leap0Client } from "leap0";

const client = new Leap0Client();
const sandbox = await client.sandboxes.get("<sandbox_id>");
const snapshot = await sandbox.createSnapshot({
  name: "workspace-warm",
  killSandboxAfter: true,
});

console.log(snapshot.id, snapshot.name);
await client.close();

Restore a snapshot

from leap0 import Leap0Client, NetworkPolicyMode

client = Leap0Client()
sandbox = client.snapshots.restore(
    snapshot_name="workspace-warm",
    auto_pause=True,
    timeout=30,
    network_policy={
        "mode": NetworkPolicyMode.CUSTOM,
        "allow_cidrs": ["1.2.3.4/32"],
    },
)

print(sandbox.id, sandbox.state)
import { Leap0Client, NetworkPolicyMode } from "leap0";

const client = new Leap0Client();
const sandbox = await client.snapshots.restore({
  snapshotName: "workspace-warm",
  autoPause: true,
  timeout: 30,
  networkPolicy: {
    mode: NetworkPolicyMode.CUSTOM,
    allowCidrs: ["1.2.3.4/32"],
  },
});

console.log(sandbox.id, sandbox.state);
await client.close();

Delete a snapshot

When a snapshot is deleted, all stored data for that sandbox (memory state, disk state) is permanently removed.

from leap0 import Leap0Client

client = Leap0Client()
client.snapshots.delete("<snapshot_id>")
import { Leap0Client } from "leap0";

const client = new Leap0Client();
await client.snapshots.delete("<snapshot_id>");
await client.close();

Was this page helpful?

On this page