Build and host AI agents on Cloudflare. Connect chat, voice, email, Slack, and webhooks to a durable agent, and give it tools such as a workspace, a browser, web search, MCP servers, and payments.
When you host agents on Cloudflare, each agent has a durable identity, local SQL storage, real-time connections, scheduled work, and recoverable execution.
Deploy once and Cloudflare runs your agents across its global network, scaling to tens of millions of instances. No infrastructure to manage, no sessions to reconstruct, no state to externalize.
The Lifecycle provides hooks for Capabilities to schedule durable work.
Agents on Cloudflare are composed from four parts:
- The runtime is a Durable Object, the Lifecycle, and capabilities. Each agent is a Durable Object, and routing sends each request to the right one. The Agents SDK Lifecycle runs inside the Durable Object, handles its requests, alarms, and WebSocket events, and starts the capabilities you add to it with
.use(). Capabilities includeWebSockets,State,Scheduler, andMCPClientManager. - The harness is the capability that runs the agent loop. A harness calls models, runs tools, handles tool results, streams responses, and decides whether to continue. It is the unit of compute for an agent, and the Agents SDK exists to make harnesses run well on Cloudflare. Use the Pi harness, which runs the Pi ↗︎ agent loop durably and keeps a run going after the object is evicted.
- Tools let the agent act. For a durable file system and code execution, give the agent a workspace from Cloudflare Computer. The Agents SDK also includes web fetch, web search, browser automation, sandboxed code execution, AI Search, MCP servers, payments, and Code Mode.
- Communication channels define how users and systems reach your agent, such as chat, voice, email, Slack, webhooks, and other event sources. These guides use the
Agentclass, a preset Durable Object with the Lifecycle and a set of capabilities already installed.
Agents publish structured events, such as state changes, schedules, and MCP connections, that you can use for observability.
Build your first agent with the Pi harness. The Pi harness runs the Pi ↗︎ agent loop durably in a Durable Object. It uses the Lifecycle's job queue to schedule future work, so a run continues after the object is evicted. No API keys are required. The examples use Workers AI through the AI binding.
npm i agents @earendil-works/pi-durable @earendil-works/pi-ai @earendil-works/chordyarn add agents @earendil-works/pi-durable @earendil-works/pi-ai @earendil-works/chordpnpm add agents @earendil-works/pi-durable @earendil-works/pi-ai @earendil-works/chordbun add agents @earendil-works/pi-durable @earendil-works/pi-ai @earendil-works/chordThe Pi packages are optional peer dependencies of agents, at ~1.4.0. Pi Durable is experimental and its API can change in minor releases, so each agents release supports one Pi minor version. Install the versions your package manager resolves for agents.
To start from a complete app with a browser UI, a Cloudflare Computer workspace, and code execution, deploy the Pi harness example:
To build it step by step, follow Build your first Durable Agent. To learn the Lifecycle, State, and WebSockets without a model, refer to Learn the runtime. To add the Lifecycle to a Worker you already have, refer to Add to an existing project.
The Pi agent runs on the Pi harness. The other examples build on the Agent class preset.
Build an agent on the Pi harness, with tools, sessions, and recovery after eviction.
Build a streaming AI chat agent with tools and human-in-the-loop approvals.
Build an agent that responds to Slack messages, mentions, and commands.
Build a real-time voice agent with speech-to-text and text-to-speech.
Build an agent that can inspect pages, capture screenshots, and use browser tools.
Build an agent that sends, receives, routes, and replies to email.