cd /news/ai-agents/pause-snapshot-or-stop-choosing-a-li… · home › topics › ai-agents › article
[ARTICLE · art-176509] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

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

A developer working with Sandscale's TypeScript SDK outlined a per-workload approach to agent sandbox lifecycles, arguing teams should choose stop, pause, snapshot or automatic idle hibernation based on how each agent behaves rather than applying one default platform-wide. The writeup details that stop releases everything, pause preserves memory and files for resumption, snapshots capture the /workspace as a starting point for new sandboxes, and idle sandboxes are hibernated and woken by the next call, with billing counted only against awake vCPU-hours.

recommendation

Snapshot a sandbox after one-time setup like dependency installs and start each run from that snapshotId, and pause stateful chat sessions instead of stopping them so memory and files survive between turns.

more in playbook: Designing agent systems
by read4 min views5 publishedNov 26, 2026

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.

Operation What it keeps SDK call
Stop Nothing; the sandbox is released sandboxes.stop(id)
Memory and files; resume carries on where it stopped sandboxes.(id) ,sandboxes.resume(id)
Snapshot The sandbox's /workspace , as a starting point for new sandboxes sandboxes.snapshot(id) , thensandboxes.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. d 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.

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.

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.

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, instead of stopping.

// after the agent's turn ends
await sandscale.sandboxes.(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,
});

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

You may not need an explicit 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 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 d sandboxes older than a day is a good habit).

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.

// 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 covers this and the entropy and clock issues on restore. Snapshot after npm ci, before any credential arrives.

Ask two questions about each workload:

Workload Lifecycle
Run a model's code once, return the result Throwaway
Grade or test user submissions Throwaway
Chat assistant with a Python session between turns
Agent waiting on a human approval
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 d or forgotten ones. That one habit prevents most lifecycle surprises.

Originally published on the Sandscale blog.

── more in #ai-agents 4 stories · sorted by recency
── more on @sandscale 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/pause-snapshot-or-st…] indexed:0 read:4min 2026-11-26 · —