Agents · Guides · Workers-based platform

Cloudflare agent sandbox

Cloudflare's agent platform at the level of system architecture, data flow, and cost — the second platform we are evaluating as a managed home for our Agno workflow layer. No code, no file paths, just the picture.

Runtime Durable Object + SQLiteSDK TypeScript-firstBaseline $5 / monthStatus Core GA · Think preview
ac-python-apiHTTPS → Agent.run()·Durable ObjectWSS frames back
00

At a glance

Cloudflare Agents is a TypeScript SDK plus a runtime: each agent is a Durable Object backed by SQLite, alarms, and WebSockets, with optional Workflows for long-running orchestration. We supply the LLM — either Workers AI for managed inference, or BYO Claude / OpenAI through AI Gateway.

1:1
Durable Object per agent
isolated SQLite each
$5
Per month baseline
Workers Paid + metering
$0
Cost while hibernating
DO evicted from memory
TS
SDK-first language
Python on Workers is beta
!The single biggest gotcha

The Agents SDK is TypeScript-first. Python on Workers is open beta. Migrating our Python tool layer means either rewriting in TypeScript or running Python in Cloudflare Sandboxes (Linux containers, GA 2026) and orchestrating from a TS Agent. Core SDK + Durable Object SQLite went GA at Agents Week 2026; "Project Think" (durable execution + sub-agent facets) is in preview.

01

What it is

Cloudflare Agents is a stateful agent SDK that runs on Workers. Each agent instance is backed by a Durable Object — isolated SQLite, alarms, WebSockets. Orchestration of multi-step durable work uses Cloudflare Workflows. Inference comes from Workers AI or any external provider through AI Gateway.

KEYAn addressable object on the edge

An agent is a long-lived addressable object on the edge that wakes on an event, runs briefly, persists state to its SQLite, and hibernates until the next event. Cost while hibernating is zero. The Agent class and the Durable Object underneath are inseparable: each agent instance lives or dies as a single DO.

02

Core primitives

What each building block gives us. The eight that matter for a migration.

Agent class

Base TypeScript class. Methods decorated @callable() become typed RPC endpoints.

AIChatAgent

Subclass with chat-history persistence and streaming over WebSocket.

Durable Object

One DO per agent. Isolated SQLite, alarms for scheduling, WebSocket hibernation, in-place state.

Workflow

Durable multi-step orchestration with automatic replay and retries. The Celery replacement.

Workers AI

Managed inference on Cloudflare GPUs, billed per Neuron.

AI Gateway

LLM proxy with caching, observability, rate limiting, fallback, guardrails. Works with any provider.

Vectorize

Vector database for RAG and semantic memory.

R2 · KV · Queues

Object storage, eventually-consistent KV, durable message queues.

03

System architecture

Cloudflare's WebSocket Hibernation API is what makes the cost story work: the socket stays open from the client's perspective while the DO is evicted from memory, paged in only when the next message arrives. Toggle the boundary to see which side of the wall each piece lives on.

The agent loop and any tool methods you write live inside the Durable Object. External LLM calls route through AI Gateway. Replay-safe long-running steps live in a Workflow.

Agent (Durable Object)one DO per agent instance
Per-agent SQLiteisolated, durable across restarts
Alarms / scheduleswake the DO on a timer
WebSocket hibernationsocket open while DO evicted
Workflow (durable steps)automatic replay + retries
AI Gateway → Claude / GPTcaching · observability · billing
04

Data flow

A typical agent run. DO SQLite captures per-agent state throughout, and the Hibernation API keeps the socket cheap between messages.

1

POST /workflows/runs client → api

The frontend kicks off a run against FastAPI. Nothing edge-side has happened yet.

2

HTTPS → Agent.run() api → DO

FastAPI calls into the Worker, which addresses the agent's Durable Object and opens a WebSocket.

3

Prompt + tools to AI Gateway DO → gateway

The agent sends the prompt and tools through AI Gateway, which proxies to Claude, GPT, or Workers AI.

4

Tool call → execute loop

The model emits a tool call. The DO runs a local method, a Workflow step, or fetches our HTTPS endpoint.

5

WSS frames back DO → api

Final response streams back over WebSocket. DO SQLite captures per-agent state along the way.

6

Persist to Supabase api → supabase

FastAPI writes the run into Supabase and re-streams the user-visible subset (SSE / WS) to the frontend.

05

State and memory

Per-agent state lives in three places, all owned by Cloudflare. AIChatAgent persists conversation history to the agent's SQLite automatically.

1 · durable across hibernation

Durable Object SQLite

Local to the agent, durable across restarts, deploys, and hibernation. Schema is whatever we define. The agent's working memory.

2 · auto-syncs to clients

Synced KV state

A live key-value store inside the DO that auto-syncs to connected clients via the SDK's React hooks. Useful for UI mirrors of agent state.

3 · optional · external

Vectorize

External vector index for semantic memory or RAG. Long-term cross-agent memory has no first-class primitive — roll your own with a shared KV namespace or a Vectorize index.

06

LLM and tools

Two paths to the model. MCP is well-supported — agents can both expose and consume MCP (HTTP, SSE, RPC, with elicitation).

Workers AI

Managed, in-region

Ships a catalog (Llama, Mistral, embeddings, image models) billed per Neuron. Cheap, no separate API key. Useful for utility models, less so for frontier traffic.

AI Gateway

Proxy any provider

Proxies any external provider, including Claude. Adds caching, rate limiting, fallback, observability, DLP, Logpush. New in 2026: Unified Billing routes third-party charges to the Cloudflare invoice with a convenience fee.

Workers AI pricing in token terms ranges roughly $0.05 to $5 per million tokens depending on the model — useful for utility classification, less so as a frontier-model substitute. Tool calling otherwise follows the Anthropic and OpenAI conventions through AI Gateway provider routes.
07

Pricing

Workers Paid plan, 2026. LLM tokens are billed by the underlying provider when you BYO; AI Gateway passes the cost through (plus the unified-billing convenience fee if enabled).

ResourceIncludedOverage
Baseline$5 / monthn/a
Worker requests10M / month$0.30 per million
Worker CPU time30M CPU-ms / month$0.02 per million CPU-ms
Durable Object requests1M / month$0.15 per million
Durable Object duration400,000 GB-s / month$12.50 per million GB-s
DO SQLite5 GB-mo + 25B reads + 50M writes$0.20/GB-mo · $0.001/M reads · $1.00/M writes
AI Gateway coreunlimitedfree
AI Gateway Logpushfirst 10M logs$0.05 per million
Workers AI10,000 Neurons / day$0.011 per 1,000 Neurons
Monthly cost calculatorClaude via AI Gateway · Sonnet 4.6 passthrough
Baseline (Workers Paid)$5.00
Anthropic token passthrough$3,300.00
Cloudflare metering (DO duration + requests)$0.00
Total / month$3,305.00
Effective cost / run$0.33
EGA worked example

Same Sonar run — 80k input, 6k output on Sonnet 4.6, 60s active, 90s wall-clock. Anthropic passthrough $0.33, Worker request negligible, ~5 DO requests effectively $0, DO duration 90s × 128MB = 11.5 GB-s (well inside the 400,000 GB-s tier), AI Gateway core free. Roughly $0.33 per run — same as managed agents on tokens; the Cloudflare metering is rounding error at this scale.

The Cloudflare pricing model only diverges from Anthropic-only at very high agent volume (where DO duration overage and per-request fees start to matter) or when running cheap utility models on Workers AI instead of Claude. Push the runs/month slider up to see the metering line break away from zero.
08

Setup overview

The high-level steps to bring up an agent sandbox for one of our existing workflows.

1

Provision + AI Gateway

Create a Cloudflare account, enable the Workers Paid plan, create an AI Gateway, install Wrangler locally.

2

Write the agent

A TypeScript class extending Agent (or AIChatAgent for chat). Tool methods are decorated callables; state lives in the agent's SQLite.

3

Wrap external Python tools

Either rewrite them in TypeScript (preferred for thin API wrappers), or run them in a Cloudflare Sandbox container and call from the agent over fetch.

4

Wire orchestration

Multi-step durable jobs become Workflows. The agent kicks off a Workflow, Cloudflare retries failed steps automatically, and the agent reads the final result.

5

Route LLM traffic

Through AI Gateway — choose Workers AI or an external provider (we would point Claude through AI Gateway here).

6

Bridge to FastAPI

The agent fronts HTTPS + WebSocket; FastAPI calls in to start a run and listens for results to write into Supabase. Local dev is Miniflare (wrangler dev); deploy is wrangler deploy.

09

Replacing our Agno workflow

Today: Celery → WorkflowExecutor → Agno workflow → in-process Python tools. Tomorrow: FastAPI → a Cloudflare Worker → an Agent (Durable Object) → tool methods + Workflow steps, with TS rewrites and a Python sandbox for heavy enrichment. Toggle to see what survives the move.

  • FastAPI HTTP layer and routing.
  • Supabase tables for workflow runs + run logs — the Worker reports back into them.
  • Frontend streaming consumer — the contract does not change; we still emit SSE to the client.
  • Per-tenant cost accounting in ai_usage_log — AI Gateway exposes per-request token counts we mirror.
10

Sources

AgencyCore · Agents guide · Cloudflare agent sandboxCore GA · Project Think preview