All guides
Updated By Kartik Sarangmath

How to Deploy Durable Agents with Pi Durable

Running Pi agents on Cloudflare, Vercel, or your own servers, what Cloudflare costs, what you still build, and how it compares with Omnara

Pi Durable is Earendil's library for agents that keep their state through crashes, restarts, and redeploys. It's built by the team behind Pi, 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.

The library doesn't decide where your agent runs. You can deploy it on Cloudflare Durable Objects, on Vercel, or on your own servers, and you build the host and the product around it. Pi Durable is still marked experimental.

The Short Version

If you wantUse
Durable agents in production for customers or teams, on any model, with an API, organizations, roles, approvals, schedules, and webhooks already builtOmnara
Agents and transcripts in your own cloud, across several servers, without building the hostOmnara self-hosted
A custom agent app where you own the loop, the state, and your own resumable workflow steps, and you're fine with an experimental library and building the service around itPi Durable
Many agents that sit idle most of the time, if you're already on CloudflarePi Durable on Cloudflare
An existing Next.js app on Vercel, or Pi Durable on your own Postgres, if you're fine with a 0.0.x packagePi Durable with Vercel's durable-harness
One small internal agent on one serverPi Durable on Node with SQLite

What Pi Durable Does

Pi Durable is a TypeScript library, MIT licensed, with a long README and a full spec. Earendil launched it on October 1 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.

A 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.

Two things set it apart. First, 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.

Second, your own app state can live inside the same transactions as the conversation, so typed documents and multi-step tasks commit together with the agent's messages. Code Mode replays model-written JavaScript from a journal after a restart, so finished steps don't run twice.

It 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, is one way to keep Pi's state in Postgres.

The rule that matters most when you deploy it is this line from the README: "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.

Three Ways to Deploy Pi Durable

On Cloudflare Durable Objects

A Durable Object 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 and published a sample app.

The sample pins Pi Durable 1.2.0, but 1.3.0 fixes two Durable Object issues, so use the newer version. Here's the sample's setup, shortened:

  1. Declare a SQLite-backed Durable Object in wrangler.jsonc:

    jsonc
    "durable_objects": { "bindings": [{ "name": "SESSIONS", "class_name": "Session" }] },"exports": { "Session": { "type": "durable-object", "storage": "sqlite" } },
  2. Route each session to its object from your Worker with env.SESSIONS.getByName(sessionId).fetch(request).
  3. Open the harness when the object starts, and reset the object if storage fails, so the next event reopens it:

    ts
    import { DurableObject } from "cloudflare:workers";import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";import { Harness } from "@earendil-works/pi-durable";import { openDurableObjectSqliteStorage } from "@earendil-works/pi-durable/storage/sqlite/cloudflare";
    export class Session extends DurableObject<Env> {  #harness!: Harness;
      constructor(ctx: DurableObjectState, env: Env) {    super(ctx, env);    void ctx.blockConcurrencyWhile(() => this.#initialize());  }
      async #initialize(): Promise<void> {    const storage = await openDurableObjectSqliteStorage(this.ctx.storage);    this.#harness = await Harness.open(storage, harnessOptions, BACKGROUND_CONTEXT);    void this.#harness.closed.then((end) => {      if (end.reason === "failed") this.ctx.abort("Harness failed");    });  }}

    harnessOptions holds your models, tools, and settings; the sample builds them in chat.ts.

  4. Set alarms for scheduled and unfinished work. Pi keeps its timers in memory, so a sleeping task won't wake on its own 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.

The sample connects clients over hibernatable WebSockets, so the object can sleep while they stay connected. Before you deploy, add authentication and rate limiting, since the sample ships with neither. Its README warns, "Anyone who can reach this sample can create sessions that use your model credentials."

Cloudflare also has its own integration, PiHarness 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.

On Vercel with durable-harness

Vercel's durable-harness runs Pi Durable on its Workflow SDK. 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.

You 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.

The same package runs off Vercel too. Point it at a Postgres "World" on your own servers, and your sessions live in your database. The repository 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.

On your own servers

The 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. Back up the database too, since Pi's README says SQLite "commits survive process crashes; the newest may be lost on power or host failure."

Running across several servers means adding routing, locking, and takeover yourself. A few projects are building hosts for this, like Deno's celld (beta) and Rivet Agents. If you're already on Postgres, durable-harness with a Postgres World is the most direct path today.

Cloudflare Durable Objects Pricing for Pi Agents

Durable Objects are billed for requests, storage, and the time each object is awake. On the $5 Workers Paid plan, time awake costs $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.

The 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 even though the CPU is idle. Pi's in-memory sleep timers also keep it awake. Objects only sleep for free when nothing is in flight.

These examples assume one Durable Object per agent and a 30-day month.

ExampleAwake time per monthCost of time awake
One agent awake the whole month331,776 GB-secondsWithin the allowance, or about $4.15 once you're past it
1,000 agents, each working one hour a day13.8 million GB-secondsAbout $175
1,000 agents awake the whole month331.8 million GB-secondsAbout $4,150

Requests, 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 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.

The cost of awake objects has drawn attention. Wordware's Robert Chandler packed 1,000 awake objects into containers 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: "for anything with money in it, keep real DOs." If your agents mostly sleep, plain Durable Objects are already cheap.

Durable Objects also have 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, 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. 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.

What You Still Build Around Pi Durable

Pi Durable gives you a durable agent, not the product around it. Whichever host you pick, you'll still need:

  • 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.
  • 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.
  • 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: a background task that copies entries to Postgres.
  • Retention and webhooks. Deleting data for privacy requests and storage limits, and telling other systems what your agents did.
  • Machines. Pi's pi-env reaches machines through Node subprocesses and SSH, so it doesn't run inside a Worker yet. You'd use Cloudflare's sandboxes, Vercel Sandbox, or your own bridge.

You'd need the same list for any agent you put in front of users.

How Omnara Handles the Same Job

Omnara is an open-source (Apache 2.0) managed agent platform, a service with an API instead of a library you host. You create agents, send them messages, and read their events over HTTP, from the CLI, or from the TypeScript SDK. Agents are API objects, so you launch one per customer, ticket, or thread with a single call.

The design is different from Pi on Cloudflare. Agent state lives mainly in one Postgres database, 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. A worker waiting on a model can run other agents' turns at the same time, up to 4 per worker by default.

Ownership and crashes work through leases. A worker claims an agent with a lease, 90 seconds by default, 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. 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.

The pieces you'd otherwise build come with it:

On Omnara Cloud, there's nothing to run and no platform fee, so your own model keys and machines cost nothing. Models bought through Omnara cost the provider's token rates, and its machines are billed by usage. Both are paid with credits that carry a 5% service fee covering provider costs.

Time an agent spends waiting on a model costs nothing, while on Cloudflare an object waiting on a model is billed as awake. Cloudflare runs the servers, but you still set up the host, or use PiHarness, and build everything around it.

The bigger difference is running it in your own cloud. You self-host Omnara on standard infrastructure: Postgres 18, Redis or Valkey, S3-compatible storage, and a shared filesystem for agent memory. Omnara's team can also deploy and manage it in your own cloud (BYOC) or on premises. To set that up, book a call with the founders.

Workers are stateless, so you add more to handle more agents. Ownership, worker failover, and wake-ups already work across every server.

Cloudflare'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). 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.

Pi Durable vs Omnara

OmnaraPi Durable
What it isA managed agent platform with an API, self-hosted or on Omnara CloudA TypeScript library you host
Where state livesOne Postgres database for every agent, plus blob storage for filesOne SQLite database per session, or a Workflow SDK log
Who runs the agentA shared pool of workers, each holding a leaseThe host: one Durable Object, one function at a time, or your process
ApprovalsBuilt in; the agent waits, saved, until someone answersA beforeTool hook can wait, but the wait doesn't survive a restart
SchedulingCron triggersYou set alarms or timers in the host
Teams, roles, and secretsBuilt inYou build them
Custom workflow stepsCustom tools in your own backend, in any language, held durably until you answerDurable tasks, documents, and Code Mode, saved with the conversation
HostedOmnara Cloud runs everythingCloudflare or Vercel run the servers; you set up the host and build the product around it
In your own cloudThe whole platform on your Postgres, Redis, and S3-compatible storage, or deployed and managed by Omnara's team; add workers to scaleOne Node process for a single server; across servers, you build ownership, routing, and wake-ups, or use durable-harness on Postgres
What costs grow withActive work (Cloud), or your servers and databaseTime each object is awake (Cloudflare), or your servers
StatusIn production on Omnara Cloud, with regular releasesExperimental library; Cloudflare's integration is in beta

What "Durable" Does and Doesn't Promise

Both 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, 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. Neither can bring back data the storage itself lost.

They 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". Otherwise it tells the model the call was interrupted.

Omnara never runs a tool again after its worker dies, so there's nothing to mark per tool. It tells the model the outcome is unknown instead. Either way, the model may simply call the tool again.

In a test by the One CLI team, 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.

Which One to Pick

Pi Durable fits when you want to own every piece of a custom agent app. Its durable tasks and Code Mode save your own workflow steps in the same transaction as the conversation. In exchange, you take on an experimental library whose API changes without notice. Whichever host you pick, you build the host, access control, approvals that survive a restart, and fleet visibility yourself.

For agents other people use in production, or more agents than one server can handle, choose Omnara. 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.

For the wider checklist of running agents for real users, see How to Deploy an AI Agent to Production. For the difference between a harness like Pi and a runtime that hosts it, see Four Ways to Build an AI Agent.

FAQ

What is Pi Durable?

Pi 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.

Is Pi Durable production ready?

Earendil 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." Expect to keep up with changes. For durable agents in production, use Omnara, which has access control and approvals already built.

How much does it cost to run Pi agents on Cloudflare?

On 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.

Can I run Pi Durable without Cloudflare?

Yes. 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.

Does Pi Durable work with Postgres?

Not 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.

What's the difference between Pi Durable and Cloudflare's PiHarness?

Pi 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.

Is Omnara built on Pi?

No. Omnara runs its own agent loop and keeps its state in Postgres. It doesn't use Pi or Pi Durable. The loop is serverless, so there's no Durable Object or long-running process per agent to keep alive.

On Terminal-Bench 4.0, Omnara matched the pass rates of Claude Code and Codex on the same models. It ran 12% faster than Claude Code and 11% cheaper than Codex. Its 69.6% with Claude Opus 5.5 is the top score. Terminal-Bench's own runner graded every run. Every trace and the harness are public, so you can rerun it yourself.