{"slug": "how-to-deploy-durable-agents-with-pi-durable", "title": "How to Deploy Durable Agents with Pi Durable", "summary": "Earendil launched Pi Durable, an MIT-licensed TypeScript library for agents that persist state through crashes, restarts and redeploys, on October 1 alongside Pi 1.0; the library is still marked experimental. Pi Durable ships with four storage backends — in-memory, Node SQLite, JSONL and SQLite inside a Cloudflare Durable Object — and can run on Cloudflare Durable Objects, Vercel or self-hosted servers, but the README states \"One process owns a storage at a time; there is no cross-process locking,\" so operators must supply their own single-instance enforcement, scheduled wake-ups and restarts. Earendil published a Cloudflare sample app pinning Pi Durable 1.2.0, while version 1.3.0 fixes two Durable Object issues.", "body_md": "[All guides](https://www.omnara.com/guides)\n\n# How to Deploy Durable Agents with Pi Durable\n\nRunning Pi agents on Cloudflare, Vercel, or your own servers, what Cloudflare costs, what you still build, and how it compares with Omnara\n\n## On this page\n\n[Pi Durable](https://github.com/earendil-works/pi/tree/main/packages/durable) is Earendil's library for agents that keep their state through crashes, restarts, and redeploys. It's built by the team behind [Pi](https://pi.dev/), the open-source coding agent, and it's for agents that live longer than one request: they take new messages while they work, run on a schedule, and pick up where they left off.\n\nThe library doesn't decide where your agent runs. Today you can deploy it on Cloudflare Durable Objects, on Vercel, or on your own servers. [Omnara](https://github.com/omnara-ai/omnara), an open-source agent platform, solves the same problem with a different design: a service you call instead of a library you host. Pi Durable is still marked experimental.\n\n## The Short Version\n\n## What Pi Durable Does\n\nPi Durable is a TypeScript library, MIT licensed, with [a long README and a full spec](https://github.com/earendil-works/pi/tree/main/packages/durable). Earendil [launched it on October 1](https://earendil.com/posts/pi-durable/) alongside Pi 1.0. It isn't a hosted service. You open a `Harness` on a storage backend, and everything the agent does is saved there as it happens.\n\nA session can hold many conversations, and you can fork any of them from a saved message. While the agent is busy, a new message can steer the current turn, wait as a follow-up, or be turned away, and a `requestId` makes a retried submission safe. Long conversations are summarized for the model, while the full history stays in storage.\n\nTwo things set it apart. The first is how it handles tools: Pi saves each tool call before running it, and after a crash the tool runs again only if you marked it `replay: \"safe\"`. Otherwise the model gets an \"interrupted\" result and decides what to do. The second is that your own app state can live inside the same transactions as the conversation. Typed documents and multi-step tasks commit together with the agent's messages, so your app's records and the conversation are always saved together, and Code Mode replays model-written JavaScript from a journal after a restart, so finished steps don't run twice.\n\nIt ships with four storage backends: in-memory, Node SQLite, JSONL, and SQLite inside a Cloudflare Durable Object. Earendil says a Postgres or key-value backend would be easy to write, but Pi itself doesn't ship one yet. Vercel's durable-harness, [below](#on-vercel-with-durable-harness), is one way to keep Pi's state in Postgres.\n\nThe rule that matters most when you deploy it is this line from [the README](https://github.com/earendil-works/pi/blob/7ec1f648e9b21391ab2a886d3ef8325945660d6d/packages/durable/README.md#L688): \"One process owns a storage at a time; there is no cross-process locking.\" Pi keeps your agent's state correct, but something else has to make sure only one copy of the agent is running, wake it up for scheduled work, and restart it when it fails.\n\n## Three Ways to Deploy Pi Durable\n\n### On Cloudflare Durable Objects\n\nA [Durable Object](https://developers.cloudflare.com/durable-objects/) is a small stateful server Cloudflare runs for you, with its own SQLite database and a single owner at any time. It sleeps when nothing is happening and wakes on a request, a WebSocket message, or an alarm. That covers most of what Pi needs from a host, which is why Earendil [wrote up running Pi Durable on Cloudflare](https://earendil.com/posts/pi-durable-on-cloudflare/) and published [a sample app](https://github.com/earendil-works/pi-durable-cloudflare).\n\nThe sample's setup, shortened. The sample pins Pi Durable 1.2.0; [1.3.0](https://github.com/earendil-works/pi/blob/7ec1f648e9b21391ab2a886d3ef8325945660d6d/packages/durable/CHANGELOG.md) fixes two Durable Object issues, so use the newer version:\n\n1. \nDeclare a SQLite-backed Durable Object in `wrangler.jsonc` :\n2. Route each session to its object from your Worker with `env.SESSIONS.getByName(sessionId).fetch(request)` .\n3. \nOpen the harness when the object starts, and reset the object if storage fails, so the next event reopens it: `harnessOptions` holds your models, tools, and settings; the sample builds them in[`chat.ts`](https://github.com/earendil-works/pi-durable-cloudflare/blob/dcb56ce2d174babb3f00112ac5b8cd597e58ab45/src/chat.ts) .\n4. Set alarms for scheduled and unfinished work. Pi keeps its timers in memory, so a sleeping task [won't wake on its own](https://github.com/earendil-works/pi/issues/10857) after the object restarts. The sample's`alarm()` handler reads the harness's tasks, sets the next alarm for the earliest deadline, and sets a 60-second recovery alarm while any work is still running. Alarms can fire more than once, so keep the handler idempotent.\n\nThe sample connects clients over hibernatable WebSockets, so the object can sleep while they stay connected. Before you deploy, add authentication and rate limiting: the sample ships with neither, and its README warns, \"Anyone who can reach this sample can create sessions that use your model credentials.\"\n\nCloudflare also has its own integration, [`PiHarness`](https://developers.cloudflare.com/agents/harnesses/pi/) in the Agents SDK, which handles the alarms for you. It's in beta, and its docs list what it doesn't do yet: tool approvals, replaying missed events to a client, and deleting conversations. A single model call longer than 15 minutes can be cut off. The two also split conversations differently. Earendil's sample puts many conversations in one object, so they can share state and search each other. Cloudflare recommends one object per conversation, because Pi chooses conversation IDs itself. That spreads the load, but anything shared across conversations then needs its own storage.\n\n### On Vercel with durable-harness\n\nVercel's [`durable-harness`](https://vercel.com/docs/agent-harnesses/pi) runs Pi Durable on its [Workflow SDK](https://workflow-sdk.dev/). Each of Pi's commits becomes an event in a workflow log, and Vercel Queues run each turn in a function. If a function crashes, another one picks up the turn from the log. It also handles ownership: when a new request opens a session, the old request's next write is refused, so two copies can't both write to the same agent.\n\nYou keep your Pi code and swap the storage for `openWorldStorage(sessionId)`. A ready-made chat route streams turns to the browser, and in production it refuses requests unless you pass an `authorize` function. You still implement the login and who-owns-which-session check yourself.\n\nThe same package runs off Vercel too. Point it at a [Postgres \"World\"](https://workflow-sdk.dev/worlds) on your own servers, and your sessions live in your database. It's new: the [repository](https://github.com/vercel-labs/durable-harness) went public on October 16 at version 0.0.x, and its API may change. Each step waits for the log, so turns are slower than with Vercel's lighter `durable-harness/pi` variant, which runs only Pi's agent loop.\n\n### On your own servers\n\nThe simplest setup is Pi Durable on Node with the SQLite backend, on one server. It needs no cloud services, and it's a reasonable choice for a small internal agent. You're now the host, though, so the jobs Cloudflare would do are yours. Only one process can open a session's database, so stop the old process before starting its replacement. Run it under a supervisor that reopens the harness when it closes, and keep the process running so in-memory timers fire. And back up the database: Pi's [README](https://github.com/earendil-works/pi/blob/7ec1f648e9b21391ab2a886d3ef8325945660d6d/packages/durable/README.md#L667) says SQLite \"commits survive process crashes; the newest may be lost on power or host failure.\"\n\nRunning across several servers means adding routing, locking, and takeover yourself. A few projects are building hosts for this, like Deno's [celld](https://github.com/denoland/celld) (beta) and [Rivet Agents](https://github.com/rivet-dev/agents). If you're already on Postgres, durable-harness with a Postgres World is the most direct path today.\n\n## Cloudflare Durable Objects Pricing for Pi Agents\n\nDurable Objects are billed for requests, storage, and the time each object is awake. On the [$5 Workers Paid plan](https://developers.cloudflare.com/workers/platform/pricing/), [time awake costs](https://developers.cloudflare.com/durable-objects/platform/pricing/) $12.50 per million GB-seconds after 400,000 included, and every awake object counts as 128 MB, however much memory it uses. Requests cost $0.15 per million after the first million, rows written cost $1.00 per million after 50 million, and stored data costs $0.20 per GB-month after 5 GB. The Free plan also runs SQLite-backed objects, within daily limits.\n\nThe time an object is awake is what drives the bill, and an object stays awake while it waits on a model. A pending outbound request keeps it in memory, and Cloudflare [bills that time](https://developers.cloudflare.com/durable-objects/concepts/durable-object-lifecycle/) even though the CPU is idle. Pi's in-memory sleep timers [also keep it awake](https://github.com/earendil-works/pi/issues/10325). Objects only sleep for free when nothing is in flight.\n\nThese examples assume one Durable Object per agent and a 30-day month.\n\nRequests, rows written, storage, and model tokens are on top, and rows written can cost more than time awake. Pi saves streaming output as often as every [100 milliseconds](https://github.com/earendil-works/pi/blob/7ec1f648e9b21391ab2a886d3ef8325945660d6d/packages/durable/README.md#L406) while a model answers. 1,000 agents streaming an hour a day could commit about a billion times a month, which is over $1,000 at one row per commit. `settings.progress` makes it commit less often.\n\nThe cost of awake objects has drawn attention. Wordware's Robert Chandler [packed 1,000 awake objects into containers](https://github.com/nyacg/do-on-container) and estimated $22 a month instead of $4,050 (his cost model counts 0.125 GB per object). His test objects were simple timers, not Pi agents. The pool also saves state to storage every 30 seconds, and in his hard-kill test, the 5 writes made since the last save were lost. He [says it himself](https://x.com/bertie_ai/status/2110818493360947391): \"for anything with money in it, keep real DOs.\" If your agents mostly sleep, plain Durable Objects are already cheap.\n\nDurable Objects also have [limits](https://developers.cloudflare.com/durable-objects/platform/limits/) worth planning around. Each object gets 10 GB of SQLite on the Paid plan (1 GB on Free), shared by every conversation, task, and document in it, and writes fail when it's full. Pi can't delete conversations [yet](https://github.com/earendil-works/pi/issues/11026), so that store only grows. A single row or value can be at most 2 MB, so large tool outputs and files belong in something like R2. Memory is 128 MB per isolate, shared by everything running in it, including large contexts and images. And each object runs on one thread, so many busy conversations in one object share its CPU. The 30-second CPU limit per request, configurable up to 5 minutes, counts CPU time, not time spent waiting on a model.\n\n## What You Still Build Around Pi Durable\n\nPi Durable gives you a durable agent, not the product around it. Whichever host you pick, you'll still need:\n\n- Access control. Authentication, rate limits, and who can create agents, read their history, change their tools, and use which credentials. Earendil's sample has none of this, and Vercel's chat route refuses requests until you pass an `authorize` function, but you still write the login.\n- Approvals. Pi's `beforeTool` hook can wait for a person to approve a tool call and save the answer, but the wait lives in memory, so a restart loses it. A pause that's saved to storage is[an open proposal](https://github.com/earendil-works/pi/issues/10852) .\n- Fleet visibility. On Cloudflare, every object has its own database, so questions like \"which agents failed today\" mean exporting events somewhere central. Pi's maintainer [sketched one way](https://news.ycombinator.com/item?id=49927546) : a background task that copies entries to Postgres.\n- Retention and webhooks. Deleting data for privacy requests and storage limits, and telling other systems what your agents did.\n- Machines. Pi's `pi-env` reaches machines through Node subprocesses and SSH, so it[doesn't run inside a Worker](https://github.com/earendil-works/pi/issues/10846) yet. You'd use Cloudflare's sandboxes, Vercel Sandbox, or your own bridge.\n\nYou'd need the same list for any agent you put in front of users.\n\n## How Omnara Handles the Same Job\n\nOmnara is an open-source (Apache 2.0) agent platform. Instead of a library you host, it's a service with an API: you create agents, send them messages, and read their events over HTTP, from the [CLI](https://www.npmjs.com/package/omnara), or from the [TypeScript SDK](https://www.npmjs.com/package/@omnara/sdk).\n\nThe design is different from Pi on Cloudflare. Agent state lives mainly in [one Postgres database](https://docs.omnara.com/self-hosting/architecture), with files and tool outputs in blob storage, and a pool of stateless workers takes turns running whichever agents have work. An idle agent is a row in Postgres, not a running process, so it doesn't tie up a worker, and a worker waiting on a model can run other agents' turns at the same time, up to 4 per worker by default.\n\nOwnership and crashes work through leases. A worker claims an agent with a lease, [90 seconds by default](https://github.com/omnara-ai/omnara/blob/d570d1f0f12c1e19632280bf1d5536749bd43f26/internal/executionpolicy/policy.go), and renews it while it works. A worker that loses its lease can't save anything more for that agent. If a worker dies, its lease expires and another worker picks the agent up from Postgres. A model call that was cut off is retried from the start, up to [8 times](https://github.com/omnara-ai/omnara/blob/d570d1f0f12c1e19632280bf1d5536749bd43f26/internal/executionpolicy/policy.go). A tool call the worker was running is never re-run: it's marked failed with \"its external outcome is unknown,\" and the model decides what to do. Custom tool calls waiting on your own system stay pending until it answers.\n\nThe pieces you'd otherwise build come with it:\n\n- [Queued or steering messages](https://docs.omnara.com/events/sending-input) , with an`Idempotency-Key` so retried requests are safe\n- [Approvals](https://docs.omnara.com/tools/permissions) that wait, saved in Postgres, until someone answers in the dashboard, Slack, Discord, or the API\n- [Custom tools](https://docs.omnara.com/tools/custom) held durably until your code posts a result, plus[MCP servers](https://docs.omnara.com/tools/mcp) and built-in tools for commands, files, and the web\n- [Cron triggers](https://docs.omnara.com/api-reference/endpoints/configs-and-profiles/create-cron-trigger) for schedules\n- Saved events as a [stream](https://docs.omnara.com/events/streaming) you can resume, or as[webhooks](https://docs.omnara.com/events/webhooks) with retries\n- [Organizations, projects, and roles](https://docs.omnara.com/organization/members) , API keys, and[encrypted secrets](https://docs.omnara.com/organization/secrets)\n- Commands on [your own Linux or macOS machines](https://docs.omnara.com/machines/overview) through a daemon that connects out, or in[sandboxes from nine providers](https://docs.omnara.com/machines/providers/overview)\n\nOn [Omnara Cloud](https://www.omnara.com/pricing), there's nothing to run, and the platform pieces are already built. The platform is free with your own model keys and machines, and Omnara-managed models are billed at the provider's token rates. There's no charge for the time an agent spends waiting on a model; you pay for tokens and any Omnara-managed machines. Compare that with Pi on Cloudflare, where Cloudflare runs the servers but you still set up the host, or use `PiHarness`, and build everything around it.\n\nThe bigger difference is running it in your own cloud. You [self-host Omnara](https://docs.omnara.com/self-hosting/deployment) with Docker Compose on standard infrastructure: Postgres 18, Redis or Valkey, S3-compatible storage, and a shared filesystem for agent memory. Workers are stateless, so you add more to handle more agents, and ownership, worker failover, and wake-ups already work. All of its agents share Postgres, so plan that database's capacity and uptime as you would for any production database.\n\nCloudflare's Durable Objects service can't be self-hosted. Its open-source runtime, workerd, can run Durable Objects on your own server, but keeps each one on a single machine ([source](https://github.com/cloudflare/workerd/blob/01bb2e6deca73934885507d25ba105a0dfe202e6/src/workerd/server/workerd.capnp#L793-L806)). So to run Pi across several servers in your own cloud, you build ownership, routing, and wake-ups yourself, or use an early project like durable-harness on Postgres or Deno's celld.\n\n## Pi Durable vs Omnara\n\n## What \"Durable\" Does and Doesn't Promise\n\nBoth recover from the common failures in similar ways. If the host dies after saving progress, Pi's session reopens on the next request or alarm, or Vercel hands the turn to another function. In Omnara, the lease expires and another worker continues from Postgres. A model answer that's cut off mid-stream is retried from the start on both, up to 8 times in Omnara, and neither picks up mid-answer. A client that sends the same message twice gets one copy, through `requestId` in Pi and an `Idempotency-Key` in Omnara. And neither can bring back data the storage itself lost.\n\nThey differ in how they handle tools, which matters most for tools that change something outside the agent, like sending an email. If a tool ran but its result wasn't saved, Pi runs it again only if you marked it `replay: \"safe\"` and otherwise tells the model the call was interrupted. Omnara doesn't run a tool again after its worker dies and tells the model its outcome is unknown. Either way, the model may simply call the tool again. In [a test by the One CLI team](https://www.withone.ai/blog/pi-durable-crash-safe-one-cli), Pi correctly reported a Gmail call as interrupted, and Haiku called the tool again, leaving two drafts. Their fix combined a key from the tool-call ID, a check in Gmail for that key, and marking the tool safe to replay. A key from the tool-call ID alone only catches reruns of the same call, not a new call from the model. For anything with side effects, give the tool a way to check whether the action already happened, on either platform.\n\n## Which One to Pick\n\nPi Durable suits a custom agent app or an internal tool where you want to own every piece. Its durable tasks and Code Mode save your own workflow steps in the same transaction as the conversation, while in Omnara the steps inside a custom tool are your code's job. On Cloudflare, it's cheap for many agents that sleep most of the time. On one server, a Node process with SQLite and good backups is less to run than Omnara's four services, and durable-harness, still at 0.0.x, runs it on Vercel or your own Postgres. In exchange, you take on an experimental library whose API changes without notice, and you build the host, access control, approvals that survive a restart, and fleet visibility yourself.\n\nFor agents other people use in production, or more agents than one server can handle, Omnara is the better choice. Roles, approvals that survive a restart, schedules, and webhooks are already built. Self-hosted, its stateless workers scale out across servers in your own cloud, and if one dies, another continues from the last saved step. It works with any model from OpenAI, Anthropic, OpenRouter, or a compatible endpoint on your own keys, and on Omnara Cloud there's nothing to run and the platform itself is free.\n\nFor the wider checklist of running agents for real users, see [How to Deploy an AI Agent to Production](https://www.omnara.com/guides/deploy-ai-agents-to-production). For the difference between a harness like Pi and a runtime that hosts it, see [Four Ways to Build an AI Agent](https://www.omnara.com/guides/agent-framework-vs-harness-vs-runtime).\n\n## FAQ\n\n### What is Pi Durable?\n\nPi Durable is an open-source TypeScript library from Earendil, the team behind the Pi coding agent, for building agents that save every step as they work and recover after a crash. It holds conversations, tasks, and your own app state in one store, and it runs on Node, Bun, Cloudflare Durable Objects, or Vercel through durable-harness.\n\n### Is Pi Durable production ready?\n\nEarendil labels it experimental: \"The API changes without notice between releases.\" Cloudflare's `PiHarness` is in beta, Vercel's durable-harness is on 0.0.x, and Earendil calls its Cloudflare example \"a sample, not a production service.\" People are building on it, but expect to keep up with changes.\n\n### How much does it cost to run Pi agents on Cloudflare?\n\nOn the $5 Workers Paid plan, you pay for Durable Objects usage on top. An object that's awake all month costs about $4.15 in duration once you're past the 400,000 GB-seconds included, and an object that's asleep costs nothing for duration. Waiting on a model counts as awake. Model tokens, requests, rows written, and storage are extra.\n\n### Can I run Pi Durable without Cloudflare?\n\nYes. It runs on Node with SQLite or JSONL storage, and on Vercel or your own Postgres through durable-harness. Off Cloudflare, your host has to make sure only one process owns a session, restart it when it fails, and wake it for scheduled work.\n\n### Does Pi Durable work with Postgres?\n\nNot directly. Pi ships in-memory, SQLite, JSONL, and Durable Object storage. Vercel's durable-harness can keep Pi's commits in a Postgres-backed Workflow SDK World, and you could write your own backend against Pi's storage interface.\n\n### What's the difference between Pi Durable and Cloudflare's PiHarness?\n\nPi Durable is the library. `PiHarness` is Cloudflare's wrapper that runs it inside a Durable Object and handles the alarms that keep its work moving. You can use the wrapper, or extend a Durable Object yourself like Earendil's sample.\n\n### Is Omnara built on Pi?\n\nNo. Omnara runs its own agent loop and keeps its state in Postgres. It doesn't use Pi or Pi Durable.", "url": "https://wpnews.pro/news/how-to-deploy-durable-agents-with-pi-durable", "canonical_source": "https://www.omnara.com/guides/deploy-pi-durable-agents", "published_at": "2026-10-16 00:00:00+00:00", "updated_at": "2026-11-05 19:21:50.007903+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Earendil", "Pi Durable", "Pi", "Cloudflare", "Cloudflare Durable Objects", "Vercel", "Omnara"], "also_reported_by": [], "takeaway": "Pi Durable saves each tool call before running it and re-runs it after a crash only if marked replay: \"safe\"; otherwise the model receives an \"interrupted\" result, and because one process owns a storage at a time with no cross-process locking, the host must guarantee a single running copy.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/how-to-deploy-durable-agents-with-pi-durable", "markdown": "https://wpnews.pro/news/how-to-deploy-durable-agents-with-pi-durable.md", "text": "https://wpnews.pro/news/how-to-deploy-durable-agents-with-pi-durable.txt", "jsonld": "https://wpnews.pro/news/how-to-deploy-durable-agents-with-pi-durable.jsonld"}}