Back to Blog
Original

Cloudflare Dynamic Workers: Why This Changes How We Build AI Agents Forever

Cloudflare's Dynamic Workers enable AI-generated code to execute in V8 isolates 100x faster than containers, combined with Code Mode that cuts token usage by 81%. This changes AI agent architecture from stateless tool calls to stateful code execution at the edge.

25 March 20268 min read
Cloudflare Dynamic Workers: Why This Changes How We Build AI Agents Forever

Cloudflare Dynamic Workers: Why This Changes How We Build AI Agents Forever

Cloudflare just made AI agent sandboxing 100 times faster. Their new Dynamic Workers feature, launched in open beta on 24 March 2026, lets AI-generated code execute in secure V8 isolates that start in milliseconds instead of the hundreds of milliseconds required by containers. Combined with their earlier "Code Mode" concept, this fundamentally changes the architecture of AI agent systems.

Here is what it means for anyone building AI agents and automation.

The Problem: Containers Are Too Slow for AI Agents

Current AI agents typically execute tasks by making tool calls. Each tool call requires the LLM to generate special tokens, the runtime to invoke the tool, and the result to be fed back through the neural network before the next step. When an agent needs to chain five tool calls together, each intermediate result passes through the LLM, wasting tokens, time, and compute.

Cloudflare identified a better approach: instead of making tool calls, have the AI write code that calls the APIs directly. This concept, called Code Mode, cut token usage by 81% in their benchmarks. But it created a new problem: executing AI-generated code safely requires a sandbox.

Containers are the standard answer, but they are heavy. A Linux container takes hundreds of milliseconds to boot and consumes hundreds of megabytes of memory. Most providers impose limits on concurrent sandboxes. For consumer-scale AI agents where every user might have their own agent writing code on every request, containers simply do not scale.

What Dynamic Workers Do

Dynamic Workers use V8 isolates, the same sandboxing technology that has powered Cloudflare Workers for eight years. An isolate starts in a few milliseconds and uses a few megabytes of memory. That is roughly 100 times faster and 10 to 100 times more memory efficient than a typical container.

The key insight is that you can spawn a fresh, isolated execution environment for every single request, run one piece of AI-generated code, and throw it away. No warm pools, no container reuse, no security trade-offs.

The API is straightforward. You pass AI-generated JavaScript code to the loader, define which APIs the code can access through RPC stubs, and optionally block all internet access. The code runs in a completely isolated environment that can only communicate through the interfaces you explicitly grant.

Code Mode: Agents Write Code, Not Tool Calls

Dynamic Workers build on Cloudflare's Code Mode concept from September 2025. Instead of exposing individual MCP tools to the LLM, you convert them into a TypeScript API definition and ask the agent to write code that calls that API.

The results were significant enough that Cloudflare's own MCP server now exposes the entire Cloudflare API (over 2,500 endpoints) through just two tools and roughly 1,000 tokens of context. Traditional MCP would have consumed over 2 million tokens for the same capability.

Why does this work? LLMs have enormous training data in JavaScript and TypeScript but relatively few examples of contrived tool call formats. When an agent needs to chain multiple API calls, writing code lets it pass data directly between calls without routing everything through the neural network. The agent only reads back the final result it actually needs.

Why This Changes Agent Architecture

This combination of Code Mode and Dynamic Workers shifts AI agent design in several fundamental ways.

From stateless tool calls to stateful code execution. Current agent frameworks (LangChain, CrewAI, AutoGen) treat each tool call as a discrete, stateless operation. Code Mode treats the agent's output as a small program that can maintain state, loop, conditionally branch, and compose multiple operations. This is a more powerful abstraction.

From token-heavy to token-efficient. When every intermediate result passes through the LLM, token costs multiply. A five-step workflow might consume five times the tokens of a single code block that does the same work. For businesses running AI agents at scale, this translates directly to cost savings.

From shared sandboxes to per-request isolation. Container-based approaches often reuse sandboxes across requests for performance, creating security risks. Dynamic Workers make it practical to create a fresh sandbox for every request with essentially zero performance penalty.

From complex tool schemas to TypeScript interfaces. Describing APIs through MCP tool schemas or OpenAPI specs is verbose. A TypeScript interface describing the same API is typically 5 to 10 times more concise. Fewer tokens in the context means more room for actual reasoning.

From edge inference only to edge execution. Most AI agents run inference on edge hardware but execute tools on centralised servers. Dynamic Workers run both at the edge, in over 300 locations worldwide, eliminating network round trips between the agent's brain and its hands.

What This Means for Building AI Automations

For teams building AI-powered automation, Dynamic Workers unlock patterns that were previously impractical.

Per-user agent sandboxes at scale. Imagine a customer support system where each user conversation runs in its own isolated code environment. The agent can execute custom scripts, access specific APIs, and maintain session state without any risk of cross-contamination between users. At container speeds, this would be prohibitively expensive. At isolate speeds, it costs almost nothing.

Rapid agent prototyping. Because sandboxes start in milliseconds, you can iterate on agent behaviour by modifying the generated code and re-running it instantly. No container build times, no deployment cycles.

Multi-tenant AI applications. SaaS products that offer AI agent capabilities to their customers can sandbox each customer's agent code completely, preventing one customer's agent from accessing another's data.

Composable API orchestration. Instead of pre-building integration workflows, an AI agent can write custom orchestration code on the fly, combining APIs in novel ways that the developer never anticipated. The TypeScript interface tells the agent what is available, and the sandbox keeps it safe.

Limitations and Considerations

Dynamic Workers have constraints worth understanding. The execution environment is JavaScript-first. While Workers technically support Python and WebAssembly, JavaScript loads and runs fastest for the small code snippets that AI agents generate. This is less of a limitation than it sounds because LLMs write excellent JavaScript and have massive training data in the language.

The sandbox model is restrictive by design: no filesystem access, no raw network access unless explicitly permitted, no native modules. This is a feature for security but means agents cannot directly access system resources. All capabilities must be exposed through RPC stubs.

Dynamic Workers are a Cloudflare-specific feature. Unlike MCP, which is an open protocol, this execution model depends on Cloudflare's infrastructure. However, the Code Mode concept of having agents write code against typed APIs is portable to any sandbox environment.

The Bigger Picture: Agents as Code Platforms

Cloudflare's trajectory reveals something important about where AI agent development is heading. The industry is moving from treating agents as chatbots with tool access toward treating them as code generation and execution platforms.

Dynamic Workers, Code Mode, and the recently announced Workers AI running large models like Kimi K2.5 at the edge all point to a vision where AI agents are not applications that call APIs, but platforms that generate and execute code. The agent is the runtime, not the program.

For businesses investing in AI automation, this has a clear implication: build your APIs and integrations as clean, typed interfaces that AI can understand and call. The agents of 2027 will not be navigating your UI or calling predefined tool schemas. They will be writing code against your TypeScript interfaces and executing it in milliseconds on edge infrastructure.

Frequently Asked Questions

What are Cloudflare Dynamic Workers? Dynamic Workers are V8 isolate-based sandboxes that allow AI-generated code to execute in milliseconds. They are 100 times faster and 10 to 100 times more memory efficient than containers, making them practical for per-request agent code execution at scale.

What is Code Mode? Code Mode is Cloudflare's approach of having AI agents write JavaScript code that calls APIs directly, rather than making individual tool calls through MCP. This reduces token usage by 81% and lets agents handle more complex multi-step workflows.

How much do Dynamic Workers cost? Dynamic Workers are available to all paid Cloudflare Workers users. Pricing follows the standard Workers model with per-request billing, significantly cheaper than container-based sandboxing due to lower memory and CPU usage.

Can Dynamic Workers run Python? Technically yes, through Workers' Python support, but JavaScript is recommended for AI-generated code snippets because it loads and runs fastest. LLMs also have more training data in JavaScript.

How does this compare to Docker-based AI agent sandboxes? Dynamic Workers start roughly 100 times faster (milliseconds vs hundreds of milliseconds), use 10 to 100 times less memory, and support unlimited concurrent sandboxes. Docker containers offer more flexibility in language support and system access but are impractical for per-request isolation at scale.

Want AI insights for your business?

Get a free AI readiness scan and discover automation opportunities specific to your business.