Live demo · Sandbox snapshots

Pause a sandbox.
Pick up mid-thought.

Start something in a live terminal, then press Suspend. Chalk checkpoints the whole sandbox, memory included, and releases its compute. Resume brings back the same sandbox, with every process where it left off, a second later or after you close the tab.

Press suspend

Press Launch sandbox and run python3 count.py, a counter that only lives in memory. Press Suspend, wait as long as you like, then Resume: the count carries on from where it stopped. Close the tab while it is suspended and the page offers to resume it when you come back.

What happens when you suspend

Sandboxes run under gVisor, which can checkpoint a whole sandbox, memory included. A suspend is that checkpoint plus releasing the sandbox's compute; a resume restores it under the same id. A mostly idle sandbox checkpoints to a few megabytes.

Suspend

The terminal detaches, and the whole sandbox is checkpointed: memory, processes, file system, and the in-memory /tmp. In this demo that takes about a second.

Go cold

The checkpoint goes to storage and the sandbox's compute is released. Nothing runs and no CPU or memory is held; the running-time clock stops with it.

Resume

The same sandbox id is restored on whichever host has room, about a second later. Processes keep their PIDs, so a counter picks up exactly where it stopped.

Getting started

Suspend and resume in two calls

Suspend a running sandbox by id, and resume it by the same id whenever you need it again. Suspending needs a host-backed sandbox (ComputeClass.HOST), and processes you want to keep running across a resume should be started by the sandbox's own entrypoint; the demo's README explains why.

The example calls the sandbox API directly with the SDK's credentials. Dedicated sandbox.suspend() and sandbox.resume() methods are on their way to chalkcompute. Want a copy of a running sandbox instead of a pause? See the fork demo.

chalk-ai/sandbox-suspend
import time

import httpx
from chalkcompute import ComputeClass, Sandbox
from chalkcompute._connect import ConnectClient  # the SDK's credentials

auth = ConnectClient()
auth._ensure_auth()


def call(method: str, body: dict) -> dict:
    headers = {**dict(auth._rpc_metadata()), "content-type": "application/json"}
    url = f"{auth._api_server.rstrip('/')}/chalk.sandbox.v2.SandboxService/{method}"
    resp = httpx.post(url, json=body, headers=headers, timeout=120)
    resp.raise_for_status()
    return resp.json()


def wait_for(sandbox_id: str, status: str) -> None:
    while call("GetSandbox", {"id": sandbox_id})["sandbox"]["status"] != status:
        time.sleep(0.2)


sandbox = Sandbox(cpu="500m", memory="1Gi", lifetime="1800s", compute_class=ComputeClass.HOST)
sandbox.run()
sandbox.exec("bash", "-c", "mkdir -p /workspace && echo hello > /workspace/notes.txt")

# Checkpoint the whole sandbox, memory included, and release its compute.
call("SuspendSandbox", {"id": sandbox.id})
wait_for(sandbox.id, "SANDBOX_STATUS_SUSPENDED")

time.sleep(30)  # suspended: nothing runs and no CPU or memory is held

# The same sandbox id comes back, with every process where it left off.
call("ResumeSandbox", {"id": sandbox.id})
wait_for(sandbox.id, "SANDBOX_STATUS_RUNNING")
print(sandbox.exec("cat", "/workspace/notes.txt").stdout.decode())  # hello
sandbox.terminate()

Why suspend a sandbox

Most of an agent's life is waiting. Suspend turns that waiting into storage instead of a running machine, and loses nothing when it wakes.

Long-running agents

Suspend an agent's sandbox while it waits on a human, a webhook, or tomorrow's data, and resume it the moment there is work again.

Free up capacity

A suspended sandbox holds no CPU or memory, so idle sessions stop taking up capacity without losing any of their state.

Sessions that survive

Close the tab, come back later, and resume the same shell: same directory, same variables, same history behind the up arrow.

Any host

Resume restores the checkpoint wherever there is room, so a sandbox is not tied to the machine it was suspended on.

Same isolation

A resumed sandbox keeps its spec: gVisor kernel, network policy, CPU, memory, and identity. Suspending never widens what it can reach.

Open source

The terminal server, its page, and the deploy script are Apache-2.0 on GitHub, built on the same sandbox API you use.

Let your agents sleep on it

Talk to an engineer about suspending and resuming sandboxes in your cloud, next to your data.