# Pause, snapshot or stop: choosing a lifecycle for each agent sandbox

> Three lifecycles cover most agent workloads: throwaway, paused between turns, and started from a snapshot. What each keeps, what each costs while waiting, and how to wire them with the TypeScript SDK.

Three lifecycles cover most agent workloads: throwaway, paused between turns, and started from a snapshot. What each keeps, what each costs while waiting, and how to wire them with the TypeScript SDK.

November 26, 2026 · 4 min read · The Sandscale team

Most teams start with one lifecycle for every sandbox: create, run, stop. That is the right default, and it stays right for a lot of work. But agents have other shapes. A chat assistant waits minutes or hours between turns and wants its Python session intact. A coding agent spends its first few minutes installing the same dependencies every time. Picking the lifecycle per workload, not per platform, saves money and makes runs more predictable.

This post uses Sandscale’s TypeScript SDK (`@sandscale/sdk` 1.0.0), but the decisions apply anywhere.

## The tools

| Operation | What it keeps | SDK call |
| --- | --- | --- |
| Stop | Nothing; the sandbox is released | `sandboxes.stop(id)` |
| Pause | Memory and files; resume carries on where it stopped | `sandboxes.pause(id)`, `sandboxes.resume(id)` |
| Snapshot | The sandbox’s `/workspace`, as a starting point for new sandboxes | `sandboxes.snapshot(id)`, then `sandboxes.create({ snapshotId })` |
| Idle between calls | The running sandbox; an idle one is hibernated and woken by the next call | automatic; `keepAwake(id, ttlSeconds)` to hold it awake |

On billing: Sandscale counts awake vCPU-hours. Paused time and idle time between tool calls do not count. Snapshots use storage, which counts against your plan’s included storage (the first 10 GB of snapshots and templates is free). Details on [pricing](https://sandscale.dev/pricing).

## Lifecycle 1: throwaway

Create, do the work, stop. Every run starts from the same template, so nothing from a previous run can leak into this one, and nothing this run did survives.

```ts
import { Sandscale } from '@sandscale/sdk';

const sandscale = new Sandscale(); // reads SANDSCALE_API_KEY

const box = await sandscale.sandboxes.create({
  template: 'builtin:python',
  timeoutSeconds: 15 * 60,
  labels: { task: 'grade-submission' },
});
try {
  const result = await sandscale.sandboxes.run(box.id, ['python', 'main.py'], {
    region: box.region,
    timeoutSeconds: 120,
  });
  // hand result.exitCode, result.stdout and result.stderr back to the caller
} finally {
  await sandscale.sandboxes.stop(box.id, { region: box.region });
}
```

**Use it for:** one-shot code execution, grading, CI-style test runs, anything where a run should not see another run’s state. The `finally` matters; the `timeoutSeconds` lifetime is the backstop when your process dies before reaching it.

## Lifecycle 2: paused between turns

A conversational agent runs code, answers the user, and waits. The next message might come in ten seconds or tomorrow. If the run’s state (a loaded dataframe, a running dev server, an open REPL) is worth keeping, pause instead of stopping.

```ts
// after the agent's turn ends
await sandscale.sandboxes.pause(box.id, { region: box.region });

// when the next user message arrives
await sandscale.sandboxes.resume(box.id, { region: box.region });
const next = await sandscale.sandboxes.run(box.id, ['python', '-c', 'print(len(df))'], {
  region: box.region,
});
```

Pause keeps memory and files, so processes carry on after resume. It works on every plan. Check `box.suspend?.canPause` if you want the server’s word on whether pause is possible right now; pausing a container-based sandbox answers `409 pause_unsupported`.

You may not need an explicit pause for short gaps. A sandbox that is idle between two calls is hibernated, its memory compressed in RAM, and woken by the next call. Explicit pause is for gaps where you want the box clearly parked, with its own record.

**Use it for:** chat assistants with stateful sessions, notebooks, agents waiting on a human approval or a slow external system.

**Watch for:** the sandbox’s lifetime still applies. Keep it within your plan’s session length, and decide what happens to a session that is never resumed (a sweep that stops paused sandboxes older than a day is a good habit).

## Lifecycle 3: start from a snapshot

A coding agent clones a repository and runs `npm ci` before it can do anything useful. If every run does the same setup, do it once, snapshot, and start each run from the snapshot.

```ts
// once, when dependencies change
const base = await sandscale.sandboxes.create({ template: 'builtin:node', network: 'allowlist' });
await sandscale.sandboxes.run(base.id, 'npm ci', { region: base.region, timeoutSeconds: 600 });
const snap = await sandscale.sandboxes.snapshot(base.id, { region: base.region, label: 'deps-2026-11-26' });
await sandscale.sandboxes.stop(base.id, { region: base.region });

// every run
const box = await sandscale.sandboxes.create({ snapshotId: snap.id });
```

The snapshot covers `/workspace`, so put what you want reused there. Each run still gets its own sandbox; the snapshot is only its starting point.

**Use it for:** repeated setup that does not depend on the task. Rebuild the snapshot when the lockfile changes, and label it with the date or the lockfile hash so you can tell which one a run used.

**Watch for:** anything secret in `/workspace` at snapshot time is in every sandbox started from it. Our post on [microVM snapshot pitfalls](https://sandscale.dev/blog/microvm-snapshots-pitfalls) covers this and the entropy and clock issues on restore. Snapshot after `npm ci`, before any credential arrives.

## Choosing

Ask two questions about each workload:

1. **Must this run be isolated from the previous one?** If yes, throwaway or snapshot. Never reuse a paused sandbox across users.
2. **Is there state worth keeping across a wait?** If it is per session, pause. If it is the same for every run, snapshot.

| Workload | Lifecycle |
| --- | --- |
| Run a model’s code once, return the result | Throwaway |
| Grade or test user submissions | Throwaway |
| Chat assistant with a Python session | Pause between turns |
| Agent waiting on a human approval | Pause |
| Coding agent on a repository with heavy setup | Snapshot, then throwaway per run |
| Long-lived personal dev machine | A workspace, not a sandbox |

Label every sandbox with the task or session it belongs to, so a sweep can find paused or forgotten ones. That one habit prevents most lifecycle surprises.

**On this page**

1. The tools
2. Lifecycle 1: throwaway
3. Lifecycle 2: paused between turns
4. Lifecycle 3: start from a snapshot
5. Choosing

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [November 26, 2026 · **30 questions to ask any agent sandbox provider before you sign up** · A vendor-neutral checklist for choosing where your agents run code: isolation, network, secrets, lifecycle, billing for waiting time, governance, data location, reliability and leaving. With where to find each answer for Sandscale.](https://sandscale.dev/blog/questions-to-ask-an-agent-sandbox-provider)
- [November 26, 2026 · **Agent sandbox glossary: 41 terms in plain English** · Plain definitions for the words that come up when you run AI agent code in isolation: microVM, VMM, KVM, jailer, gVisor, seccomp, namespaces, egress allowlist, lease, snapshot, warm pool, awake vCPU-hour and more.](https://sandscale.dev/blog/agent-sandbox-glossary)

---
Source: https://sandscale.dev/blog/pause-resume-or-stop-agent-sandboxes
