Sandboxed agents cancel and recover across replicas without Redis
November 12, 20261 min read
Sandboxed ClaudeAgent and CodexAgent runs now cancel and recover correctly across AgentOS replicas that share Postgres and a checkpoint store, with no Redis required. Agno's durable queue, QueueConfig(durable=True), handles both, along with /resume.
Before, a cancel that reached the wrong replica settled the run as failed, and a resumed stream could tail forever. Large checkpoint transfers also held a database transaction open the whole time.
sandbox = DockerSandbox(
"agno-sandbox:local",
network="isolated",
checkpoints=FileCheckpointStore(Path("/shared/checkpoints")),
)
agent = ClaudeAgent(id="coder", permission_mode="acceptEdits", sandbox=sandbox)
agent_os = AgentOS(
agents=[agent],
db=db,
queue=QueueConfig(durable=True, db=db, max_attempts=2),
)- A cancel sent to the replica that isn't running the turn now ends it as cancelled. When the turn fails, the replica running it checks Postgres for that cancel.
/resumeon a replica that can't see the run's live events answers from the database with the run's real status. The stream closes withstream_expiredorreplay, and the client polls the run for its output.- An attempt that finds its computer gone removes what's left, restores the last checkpoint onto a new one and finishes the turn, so
max_attempts=2covers losing either the worker process or the host. - The queue worker retires computers kept warm past
warm_computer_secondsevery 180 seconds, on every replica.
Checkpoint restore and capture used to run inside the Postgres transaction that locked the session, run and binding rows. While files moved, the cancel endpoint and the queue's writers waited, a pooled connection stayed checked out, the heartbeat couldn't renew the lease, and a database with idle_in_transaction_session_timeout killed the turn. Both transfers now run with no transaction open. The binding records the pending restore, a short transaction under the lease confirms it, and nothing executes on the computer until that confirmation commits.
We started this AgentOS against an embedded Postgres with no Redis, and it came up on the queue. The cancel, resume and recovery paths need a real sandbox image, so this entry describes them from the pull requests and their tests.
See the cookbook, and learn more about multi-replica deployments in the documentation.
Frequently asked questions
A durable queue on Postgres, QueueConfig(durable=True, db=db), and a checkpoint store every replica reads, such as S3CheckpointStore, PostgresCheckpointStore, or a FileCheckpointStore on shared storage. Every replica also reaches the same Docker daemon and uses the same runtime configuration. Redis is optional.
Redis adds live event streams and /resume from any replica. Without it, a replica that cannot stream a run sends a stream_expired or replay event carrying the run's status, and the client polls GET /agents/{agent_id}/runs/{run_id}?session_id=... until the status is terminal to read the full output.
The sandbox is using the host-local default checkpoint directory. A local run without Redis raised ValueError: Sandbox checkpoints default to ~/.agno/sandbox/checkpoints, which other queue replicas cannot read and which does not survive losing this host; pass checkpoints= to the sandbox (home path shortened). With checkpoints=FileCheckpointStore(...) set, the same AgentOS started and /health answered 200.
No. Restore and capture run with no open transaction. Only the short steps that bind the computer, confirm the restore and record the checkpoint take row locks, each checked against the lease.



