Running a Codex Agent Loop on Durable Objects Makes Recovery the Main Feature
Cloudflare’s Codex loop example puts recovery, replay, and durable state ahead of the fantasy of an always-on agent.
When an agent fails in a local terminal, I can usually rerun the command. When it is editing files in the cloud, calling tools, and waiting on another system, the harder question is where it stopped. On November 9, Cloudflare showed an experimental way to run a Codex agent loop inside a Durable Object, with conversations, files, and completed model and tool results surviving restarts.
This is more than moving a script to the cloud
Cloudflare’s Agents changelog describes several pieces with different jobs. Tasks journal model calls and tool execution, allowing completed steps to be reused after a restart. Sessions store conversation history and compact context. Streams preserve ordered events for replay after a reconnect. Workspace provides persistent file reads and writes. The example also adapts Codex’s Rust turn-processing code to WebAssembly.
I would model that as a state machine with a ledger, not as a process that should never exit. Every tool call needs an ID, an input digest, start and finish states, and an explicit retry policy. Model output should not mutate business state directly. An adapter should turn a proposed action into an executable action with its own checks.
Even a small event shape can make the boundary visible:
{"id":"tool-184","kind":"write_file","status":"completed","replayable":false}
The replayable flag matters. Reading a file or calculating a diff is often safe to replay. Sending an email, charging a card, or creating a cloud resource is not safe to repeat just because the network timed out. Recovery must ask whether the external side effect happened, not only whether the local step was marked complete.
Recovery needs explicit answers
I want the system to answer three questions after a restart: what is the last confirmed step, did the current tool call receive external confirmation, and should the task continue, compensate, or wait for a human? The combination of Tasks, Sessions, and Streams makes the point: durable agent work is mostly about event and context consistency. It is not solved by increasing an HTTP timeout. Cloudflare’s Agents documentation is a starting point, but the limits of an experimental example still need to be checked against the version being deployed.
Before production, I would add leases and deadlines to every task. A Durable Object can retain state, but that does not give an agent permission to wait forever. An upstream API may change while the agent is recovering. A cautious retry path would read the event log, validate the current resource version, re-check external state, and retry only when the idempotency key is still valid. Otherwise it should create a pending event for a human or a more restricted worker.
Where I would use it
This pattern fits long conversations, file edits, staged research, and work that needs to resume after a disconnected client. I would not put every production permission inside one agent. I would separate input, workspace, and pending-release files; allowlist network tools; represent writes as diffs; and keep release in a separately authorised workflow. For Kubernetes, the agent can read manifests, produce a patch, and run offline validation. Applying it should remain behind a service account boundary and an approval step.
Cloudflare also lists examples for running Exo and Nanocode agent harnesses in Durable Objects. That suggests the platform is becoming a host for different runtimes, not that all of those runtimes share one recovery contract. The same changelog is useful evidence for what was announced, but I would still inspect each harness independently.
I would rename the goal from “long-running” to “recoverable”. An agent staying online for hours is not impressive by itself. Being able to explain what happened after a power cut, network failure, or model timeout is the infrastructure I would pay for. I would write the recovery tests before writing a smarter prompt.
The tests should not cover only the happy path. I would disconnect before a write, refresh the client mid-stream, and return a duplicated tool call from the model. Then I would check that the event log remains ordered and that a resumed output is labelled as resumed rather than pretending to be a fresh success. That evidence matters when an operator is investigating a bill, a permission decision, or an unexpected file write.
Sources: Cloudflare Agents changelog, Cloudflare Agents documentation.
