Cloudflare Dynamic Workers — Stateful Serverless for the AI Agent Era

Posted on: 4/24/2026 6:10:35 PM

Table of Contents

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.

100x Faster than containers (startup)
1/10 Memory vs containers
30 min Max runtime per invocation
330+ Cities worldwide

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.kv and storage.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:

241B Tokens processed (internal)
70+ AI models available
12+ Providers integrated
40% API cost reduction via caching
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:

Dynamic Workers + Durable Object Facets
Runtime enabling AI-generated code execution with persistent state and isolated databases per instance.
Sandboxes GA
Persistent isolated environments with shell, filesystem, background processes — now production-ready.
Artifacts — Git-Compatible Storage
Versioned Git-compatible storage for agents. Supports tens of millions of repos, fork from any remote.
Unified CLI (cf)
A single CLI covering ~3,000 Cloudflare API operations. Includes Local Explorer for debugging.
Project Think SDK
AI Agent SDK with thinking, acting, and persistence — evolved from "lightweight primitives" to a "batteries-included platform".
Agent Memory Service
Managed persistent memory for agents — no need to self-manage vector DBs or KV stores.
Browser Run Enhanced
Live view, session recording, 4x concurrency for browser automation.
Voice Pipeline
Real-time voice interactions for agents in roughly 30 lines of code.

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