How to resume an AI agent after its container dies

To resume an AI agent after its container dies, save its state outside the container after every
turn, then start a fresh container and put that state back. In alineod,
set "checkpoint": true in the agent spec. alineod tars the agent’s home directory after each
turn that finishes cleanly. If the container is gone when alineod next looks for it, alineod starts
a new one from the spec’s setup snapshot and extracts the newest checkpoint into it.
{
// ...your existing AgentSpec
"checkpoint": true,
}
What is lost when an agent’s container dies?
Everything inside it that isn’t somewhere else. A coding agent keeps two kinds of state in its
container. One is the conversation: Pi, the harness, writes its session file under /root. The
other is the work: files the agent created. Both go when the container goes, whether an OOM kill,
a host reboot, or a reaper removed it.
A fresh container does not fix that. It has the right packages and an empty session. The agent starts again with no memory of what it was doing.
What do I need to save to resume an agent?
Two things, from one directory tree. A checkpoint is a tar of /root and, when it exists,
/workspace. It leaves out package caches (.npm, .cache, the Cargo and Go download caches,
__pycache__) and the node_modules folders inside /workspace. The agent installs those again
after a restore.
Three things in this stack get called a snapshot, and only one carries a conversation:
| Name | Taken | Holds the conversation? |
|---|---|---|
| Setup snapshot | Once per spec, so a start skips installing Pi and packages | No. A container restored from it is empty. |
| Turn checkpoint | After every turn that finishes cleanly, when the spec sets "checkpoint": true |
Yes |
sb.checkpoint() |
When you call it, on the sandbox SDK | No. It snapshots a whole container, for exec replay. |
alineod keeps the newest three checkpoints per sandbox. Checkpointing is off by default.
How does alineod bring a lost agent back?
On boot, alineod reconnects to every agent it knows about. It tries four steps in order and stops at the first that works:
| Step | Used when | What it does |
|---|---|---|
| Reattach | The container is up and its bridge answers | Binds to the running bridge. Nothing restarts. |
| Resume | The container is up but the bridge doesn’t answer | Restarts the bridge in the same container. |
| Restore | The container is gone | Provisions a fresh container and restores the latest checkpoint into it. |
lost |
Every step above failed | Records the agent as lost, with the error. |
Restore is the step that matters here. It provisions a container from the setup snapshot,
extracts the latest checkpoint, writes the agent’s waitFor inputs again, and starts the bridge
on the restored session. The agent’s recorded sandbox id changes to the new container, so the next
boot doesn’t restore the same checkpoint twice.
Does it work? What does a restore look like?
Here is the durable-agent
example, run once on a test host with 1 vCPU and Docker. It runs a turn that writes a file, takes a
checkpoint, removes the container with docker rm -f, and resumes:
1 · a turn that writes a file
sandbox: 0b82774e-8b65-46ef-b48c-21ab9a7f3f0e
WRITTEN
pi session: 01a15a0d-1fad-708d-849f-f642a4dc1379
3 · remove the container (docker rm -f)
removed 1 container(s) for 0b82774e-8b65-46ef-b48c-21ab9a7f3f0e
4 · Alineo.resume() restores the agent onto a fresh container
resumed in: 3543 ms
new sandbox: 247d07c5-1193-45dd-8640-f389d4d878bb
restore: {"checkpointTurn":1}
5 · the same session continues
pi session: 01a15a0d-1fad-708d-849f-f642a4dc1379 (same)
durable
The new container came up and took the checkpoint in 3.5 seconds. The Pi session id is the same
one as before the container was removed. That id lives in the session file inside the checkpoint,
so it only matches when the file came back. The agent then read the file it had written, which
printed durable.
The whole script took 273 seconds end to end, and we did not time its other steps separately. A first start installs Pi and builds the setup snapshot. A restore doesn’t pay that cost again while the snapshot is still on the host.
What happens with alineod running the agent?
The same restore runs inside alineod. This is the log from alineod’s own integration test, which
starts an agent with "checkpoint": true, lets one turn finish, removes the container, kills
alineod with kill -9, and starts it again. Fields trimmed:
reattaching sandboxId=fdd2c126
sandbox is gone — provisioning a fresh one and restoring from checkpoint
snapshot ready sandboxId=01ba05f7 elapsed=1123ms
restoring checkpoint turn=1
agent.provisioned sandboxId=01ba05f7
agent.restored
reattached — container was gone, restored onto a new one
From the restart to agent.restored took about 4 seconds on the same host, in one run. Before that, the new
alineod waited about 10 seconds for the killed one’s lease to expire. That wait is how alineod
makes sure two daemons never drive the same database. Then the agent read back the file it wrote
before the container was removed, and the test passed all four assertions, including the same Pi
session id.
What happens to the turn that was running?
A turn that hadn’t finished when the container went is not in any checkpoint. alineod records it as
agent.turn_interrupted, so it is reported and not silently dropped or silently repeated. That is
in the durability contract.
We recorded it once. The agent finished turn 1, which wrote before.txt. Then we prompted it to run
sleep 75; echo late > /root/work/late.txt, removed the container 10 seconds in, killed alineod, and
restarted it. The ledger after the checkpoint:
16 agent.state_changed from=done to=running reason=prompt
19 tool.started bash: sleep 75; echo late > /root/work/late.txt
20 agent.provisioned sandboxId=42493041
21 agent.restored checkpointTurn=1
22 agent.turn_interrupted
The new container held before.txt and not late.txt. The agent’s own ls /root/work printed
before.txt, so the interrupted turn’s work was lost and not half done. Replaying that turn is
your decision, because alineod doesn’t retry it for you.
Side effects are at-least-once. If an interrupted turn had already run git push or called an
external API, and you retry it, the effect can happen twice. Nothing de-duplicates a side effect a
model chose to take mid-turn.
What can’t a restore bring back?
- Agents without
"checkpoint": true. They still come back after a lost container, on a fresh one, but with a blank session. They keep their place in the tree and lose the conversation. - Files outside
/rootand/workspace./tmpand anywhere else come back as the setup snapshot left them. Packages innode_modulesunder/workspaceare installed again by the agent. - The turn in flight. See above.
- A lost disk. A checkpoint lives on the host that runs alineod. If that host’s disk is gone, so are the checkpoints. Copying them off the machine is a separate feature, covered in Back up and restore, and not part of what this post measured.
- Agents with held credential bindings. A spec with
approval: "hold"bindings can’t be restored onto a fresh container yet. If its container is gone, the agent endslost. - Agents that don’t run as root. A checkpoint captures
/root. - Failover. alineod is one process per database. Restore brings one daemon back on one machine.
When alineod keeps running, the record lags. We also removed a container mid-turn and left
alineod up, twice. The turn ended as agent.turn_interrupted, then settled as success with whatever
text it had, so check for the interrupted event and not only the outcome. The agent carried on in a
new container with its files from the checkpoint (ls /root/work printed before.txt). But
GET /agents/:id still named the old, removed sandbox, and the ledger had no agent.restored for
it. The new container was cleaned up when we closed the run.
Frequently asked questions
Does checkpointing slow down my agent?
The checkpoint runs after the turn settles, not during it. In alineod’s log, agent.checkpointed
appeared 0.07 and 0.14 seconds after the turn settled, for an agent whose home directory held one
small file. A larger /workspace costs more, and we did not measure that here.
Do my agents need to change?
No. The spec is the same AgentSpec you already use. Add "checkpoint": true. The permission gate
and credential injection apply unchanged.
What if the model provider is down when I restore?
The restore doesn’t call the model, so it can finish. The next prompt can still fail. When the model
we had pinned began returning a 404 for our account, alineod ended that turn as failed with the
provider’s error, not as a success.
Try it
- Docs: Crash recovery and the durability contract.
- Example:
durable-agentruns the whole sequence above. It needs Docker, OpenSandbox frombunx alineo-cli init, and anNVIDIA_API_KEY.
EngineeringHow to stop a runaway AI agent swarm
Pause, steer, or stop a whole tree of sandboxed AI agents from outside them. Real calls, real timings, and what these controls can't reach.
ProductAn MCP server for swarm control
alineo-mcp puts alineod's swarm-control API behind stdio, so any MCP client — Claude Code, Claude Desktop, Cursor — can spawn, steer, and pause sandboxed agent swarms as tool calls.
ProductA control plane for swarms of agents
alineod spawns, steers, and recovers trees of sandboxed agents over HTTP and SSE, so orchestrating a swarm isn't code you write yourself.