Cloudflare Dynamic Workers — Stateful Serverless for the AI Agent Era
Posted on: 4/24/2026 6:10:35 PM
Table of contents
- Table of Contents
- 1. Introduction: Why Stateful Serverless?
- 2. What are Dynamic Workers?
- 3. Durable Object Facets: A Database per Agent
- 4. Supervisor — Facet Architecture
- 5. Sandboxes GA: Persistent Isolated Environments
- 6. Workers AI: 70+ Models, 12+ Providers via One API
- 7. Agents Week 2026 Full Roundup
- 8. Comparison: Dynamic Workers vs AWS Lambda vs Azure Durable Functions
- 9. Practical Code Examples
- 10. Pricing and Free Tier
- 11. Conclusion
Table of Contents
- Introduction: Why Stateful Serverless?
- What are Dynamic Workers?
- Durable Object Facets: A Database per Agent
- Supervisor — Facet Architecture
- Sandboxes GA: Persistent Isolated Environments
- Workers AI: 70+ Models, 12+ Providers via One API
- Agents Week 2026 Full Roundup
- Comparison: Dynamic Workers vs Lambda vs Durable Functions
- Practical Code Examples
- Pricing and Free Tier
- Conclusion
1. Introduction: Why Stateful Serverless?
Serverless computing transformed how we build applications — no server management, automatic scaling, pay only when your code runs. But it has a fundamental limitation: stateless by default. Every function invocation starts fresh. Need to persist anything? Call an external database, adding latency and cost.
With the AI Agent explosion in 2026, this problem became urgent. An AI Agent needs:
- Persistent state — remember conversation context, store intermediate results
- Dynamic code execution — run code generated by AI on the fly
- Isolation — secure es that don't affect each other
- Long-running tasks — operations lasting minutes, not just seconds
Cloudflare answered this challenge at Agents Week 2026 (April 13–17, 2026) with Dynamic Workers — a major leap from stateless serverless to stateful serverless.
2. What are Dynamic Workers?
Dynamic Workers is an isolate-based runtime that enables AI Agents to execute dynamically generated code in secure ed environments. Unlike traditional Workers (deploy fixed code ahead of time), Dynamic Workers receive code at runtime and execute it immediately.
The Core Difference
Traditional Workers: you deploy code → Cloudflare runs it. Dynamic Workers: an AI Agent generates code → sends it to Cloudflare → runs immediately in an isolated isolate with its own storage, its own database, completely isolated from other agents' code.
Technical Characteristics
- Isolates, not containers — V8 isolates start in milliseconds, no OS or runtime boot required
- Unlimited auto-scaling — from 0 to millions of concurrent instances, no configuration needed
- Built-in persistent state — state survives across invocations and even new deployments
- Native integration with D1 (SQL), R2 (Object Storage), KV (Key-Value), Queues
- Network control — can completely block network access (
globalOutbound: null)
3. Durable Object Facets: A Database per Agent
Durable Object Facets is the game-changing feature of Agents Week 2026. The idea: each AI-generated app gets its own isolated SQLite database, running on the edge server closest to the user, with zero-latency access since data lives on local disk.
graph TD
A[Client Request] --> B[Supervisor
Durable Object]
B --> C{Facet exists?}
C -->|Yes| D[Forward to Facet]
C -->|No| E[Create new Facet]
E --> F[Load Dynamic Worker Code]
F --> G[Initialize Durable Object Class]
G --> D
D --> H[Facet handles request]
H --> I[(SQLite DB
Facet)]
B --> J[(SQLite DB
Supervisor)]
style A fill:#f8f9fa,stroke:#e94560,color:#2c3e50
style B fill:#e94560,stroke:#fff,color:#fff
style D fill:#4CAF50,stroke:#fff,color:#fff
style I fill:#2c3e50,stroke:#fff,color:#fff
style J fill:#2c3e50,stroke:#fff,color:#fff
Request flow in the Supervisor — Facet architecture
Dual Storage Model
Each Durable Object contains two separate SQLite databases:
- Supervisor DB — stores logs, metrics, billing, system configuration. Only the supervisor can access it.
- Facet DB — stores the agent's application data. Only the facet can access it.
Why SQLite instead of a centralized database?
SQLite runs on the same machine as the Durable Object → no network round-trip. Queries execute with near-zero latency. Each agent has its own DB → no contention. Cloudflare handles replication and backup automatically.
4. Supervisor — Facet Architecture
The two-tier Supervisor — Facet architecture is the central design pattern of Dynamic Workers:
Supervisor (Parent Durable Object)
- Receives the initial request from the client
- Handles cross-cutting concerns: logging, metrics, billing, rate limiting
- Decides which facet will handle the request
- Controls resources: limits storage, CPU, network
Facet (Child Durable Object)
- Contains the business logic — AI-generated code or user-uploaded code
- Has its own SQLite database, accessed via
storage.kvandstorage.sql - Fully isolated — cannot access the supervisor's or other facets' databases
- "Disposable" — can be created to run a few lines of code and then thrown away
sequenceDiagram
participant C as Client
participant S as Supervisor
participant F as Facet
participant DB as SQLite (Facet)
C->>S: HTTP Request
S->>S: Log request, check rate limit
S->>F: this.ctx.facets.get("app")
Note over F: Load Dynamic Worker code
if not initialized
F->>DB: storage.sql.exec("SELECT...")
DB-->>F: Query results
F-->>S: Response
S->>S: Log response, update metrics
S-->>C: HTTP Response
Sequence diagram: Request flow through Supervisor → Facet
5. Sandboxes GA: Persistent Isolated Environments
Alongside Dynamic Workers, Cloudflare also announced General Availability for Sandboxes — persistent isolated environments where AI Agents can:
- Shell access — run terminal commands like a real VPS
- Filesystem — read/write files, install packages
- Background processes — run servers, watchers, build tools
- State persistence — resume from previous state when returning
Dynamic Workers vs Sandboxes — when to use which?
Dynamic Workers: for lightweight code, fast request handling (API handlers, data transforms), needs ultra-fast startup (sub-ms). Sandboxes: for complex tasks requiring a full environment (building projects, installing dependencies, running test suites), needs real shell access.
6. Workers AI: 70+ Models, 12+ Providers via One API
Cloudflare's AI Gateway has evolved into a unified inference layer for the entire AI ecosystem:
Featured Models on Workers AI
| Model | Parameters | P50 Latency | Use Case |
|---|---|---|---|
| Llama 4 Scout | 109B | 45ms | Chat, reasoning, code generation |
| Mistral Medium 3 | 73B | 62ms | Multilingual, analysis |
| SDXL Turbo | — | 890ms | Image generation |
| Whisper Large V3 | 1.5B | ~200ms | Speech-to-text |
AI Security Suite
Cloudflare simultaneously launched a comprehensive AI security suite:
- AI Firewall — detects prompt injection with 96.3% accuracy, false positive rate below 0.1%
- AI WAF — integrates prompt injection detection into the Web Application Firewall
- AI Gateway — proxy between applications and AI providers: caching, rate limiting, cost control
Q1/2026 statistics: 78% of attacks were prompt injection, 12% data exfiltration, 7% model abuse.
7. Agents Week 2026 Full Roundup
Agents Week 2026 (April 13–17, 2026) was Cloudflare's biggest announcement week for the AI Agent platform:
8. Comparison: Dynamic Workers vs AWS Lambda vs Azure Durable Functions
| Criteria | Dynamic Workers | AWS Lambda | Azure Durable Functions |
|---|---|---|---|
| Cold start | Sub-millisecond | 100ms – 10s (runtime dependent) | 1–5s |
| Stateful | Built-in (Durable Objects) | No (requires DynamoDB/S3) | Yes (via orchestration) |
| Dynamic code | Yes (core feature) | No | No |
| Max duration | 30 minutes | 15 minutes | Unlimited |
| Built-in database | SQLite (co-located) | No (needs RDS/DynamoDB) | No (needs Azure SQL) |
| Edge deployment | 330+ PoPs automatic | Specific region selection | Specific region selection |
| Egress cost | $0 (free) | $0.09/GB | $0.087/GB |
| AI Agent support | Native (Facets, Memory, Think) | Build your own | Build your own |
Assessment
Dynamic Workers don't replace Lambda or Durable Functions in every scenario. But for AI Agent workloads — where you need dynamic code execution, persistent state, and edge latency — it's currently the most integrated solution on the market, especially with zero egress costs.
9. Practical Code Examples
9.1 Basic Supervisor + Facet
// Supervisor — manages Facet lifecycle
export class AppRunner extends DurableObject {
async fetch(request) {
// Get or create facet
let facet = this.ctx.facets.get("app", async () => {
// Load Dynamic Worker code (could be from AI-generated source)
let worker = this.#loadDynamicWorker();
let appClass = worker.getDurableObjectClass("App");
return { class: appClass };
});
// Forward request to facet
return await facet.fetch(request);
}
}
// Facet — business logic with persistent state
export class App extends DurableObject {
async fetch(request) {
// Each facet has its own SQLite DB
let counter = (await this.ctx.storage.get("counter")) || 0;
counter++;
await this.ctx.storage.put("counter", counter);
return new Response(JSON.stringify({
message: `Request number ${counter}`,
timestamp: new Date().toISOString()
}), {
headers: { "Content-Type": "application/json" }
});
}
}
9.2 Workers AI — Calling models via AI Gateway
export default {
async fetch(request, env) {
const { messages } = await request.json();
const response = await env.AI.run(
"@cf/meta/llama-4-scout-17b-16e-instruct",
{
messages,
max_tokens: 1024,
temperature: 0.7
}
);
return Response.json(response);
}
};
9.3 wrangler.toml configuration for Dynamic Workers
name = "my-agent-platform"
main = "src/index.ts"
compatibility_date = "2026-04-15"
[durable_objects]
bindings = [
{ name = "APP_RUNNER", class_name = "AppRunner" }
]
[[migrations]]
tag = "v1"
new_classes = ["AppRunner"]
[ai]
binding = "AI"
10. Pricing and Free Tier
| Plan | Price | Worker Requests | Includes |
|---|---|---|---|
| Free | $0 | 100K/day | Workers, KV, R2 (10GB), D1 (5GB), basic WAF |
| Pro | $20/month | 10M/month | + Enhanced WAF, Analytics |
| Business | $200/month | 50M/month | + 100% Uptime SLA |
| Enterprise | Custom | Custom | + Dedicated support, custom SLA |
Notable Free Tier
100K requests/day for free is enough for prototypes and side projects. Combined with D1 (5GB free), R2 (10GB free, $0 egress), KV (100K reads/day free) — you can build a complete AI Agent platform at zero cost.
11. Conclusion
Agents Week 2026 marks a pivotal moment for Cloudflare: from CDN + WAF → full-stack cloud platform for AI Agents. Dynamic Workers solve the problem that traditional serverless has struggled with for years — running dynamically generated code with persistent state, in secure environments, at the edge closest to users.
With Durable Object Facets, each AI Agent gets its own database, fully isolated, with zero-latency access. With Sandboxes GA, agents have full environments to build, test, and deploy. With Workers AI + AI Gateway, agents access 70+ models through a single API.
If you're building AI Agents or a platform for AI Agents, Cloudflare Workers deserves serious consideration — especially when the free tier is already powerful enough for most prototype and small production use cases.
References
- Durable Objects in Dynamic Workers: Give each AI-generated app its own database — Cloudflare Blog
- Agents Week 2026 Updates and Announcements — Cloudflare
- Project Think: building the next generation of AI agents on Cloudflare — Cloudflare Blog
- Cloudflare Launches Dynamic Workers and AI Security — Cloudswitched
- Cloudflare Agents Week 2026: Every Release Explained — Lushbinary
DevSecOps — Integrating Security into Modern CI/CD Pipelines
Feature Flags & Progressive Delivery: Safe Release Strategy for Production
Disclaimer: The opinions expressed in this blog are solely my own and do not reflect the views or opinions of my employer or any affiliated organizations. The content provided is for informational and educational purposes only and should not be taken as professional advice. While I strive to provide accurate and up-to-date information, I make no warranties or guarantees about the completeness, reliability, or accuracy of the content. Readers are encouraged to verify the information and seek independent advice as needed. I disclaim any liability for decisions or actions taken based on the content of this blog.