~4m6:441 Million Sandboxes Per Second?! Dynamic Workers Are INSANE
Mar 28, 2026
Read: ~4m · You save: 3 min
1 Million Sandboxes per Second?! Cloudflare Dynamic Workers
Cloudflare Dynamic Workers: sandboxes 100x faster than containers. Create thousands of workers, run AI code, and save results to R2. Explained with examples.
Cloudflare has announced dynamic workers, a low-level primitive that an existing worker can create programmatically. According to the company, dynamic workers run 100 times faster than traditional containers and use less memory because they execute on V8 isolates. Their low cost makes it possible to launch an unlimited number of instances for running AI-generated code, development previews, custom automations, and other tasks. The company states that up to 1 million dynamic workers can be started per second. Whether their use is limited by support for JavaScript only is discussed below.
Comparison with Cloudflare Sandboxes
Cloudflare Sandboxes are short-lived Linux containers that run on top of Durable Objects. They are suited to tasks that require a full operating system container with a file system and the ability to run virtually any language and any binary.
Dynamic Workers are suited to tasks where speed, lightweight execution, and an unlimited number of parallel sandboxes matter. Their limitations are the same as those of a regular Worker.
Configuring a dynamic worker
The setup process looks as follows:
- A basic worker is created using Wrangler. TypeScript errors may occur if the
wrangler typescommand is not run. - An array
worker_loaderswith a binding is added to the Wrangler configuration file. The binding name can be any name. The example usesloader, as it is the most common. The binding allows creating and controlling other workers. - A constant
workeris added to the code. It uses theloaderbinding and accepts a set of values:- the
compatibilityDateparameter defines the runtime version; - the code that will be executed by the nested worker.
- the
- The nested code structurally resembles a regular worker. It contains a
fetchfunction with the argumentsrequestandcontext. The function returns the text "Hello World from the sandbox". - Network access for the nested worker is blocked. The
fetchfunction is called with therequestargument from the original worker, and then the result is returned.
When running locally and executing the request curl localhost, the text "Hello from the sandbox" is returned. A repeated request fails with an error, because a new worker is loaded on every call.
To fix this, the existing worker named worker1 is retrieved. The code runs as an asynchronous function. After that, repeated requests return data from the existing worker1 instance.
Advanced Capabilities
Dynamic workers support the following features:
- Custom bindings. For example, the
postmethod for a chat room creates a stub through which the worker interacts with Cap'n Web. - NPM dependencies. You can connect libraries, such as Hono, and bundle them using the
create workerfunction. - Outbound request interception. This mechanism allows, for example, adding credentials to requests.
One of the main reasons for using dynamic workers is executing code generated by AI agents.
Example: Running AI Agent Code
The example uses code from the E2B cookbook. It applies the Anthropic SDK to run the Sonnet 3.5 model with a system prompt and a custom tool. The tool executes Python code in a Jupyter notebook.
When the agent calls the tool, the code runs inside an E2B sandbox. The agent is tasked with calculating the value of π using the Monte Carlo method with 1,000 iterations. Since the E2B sandbox has access to a file system, the agent creates a file, image.png, which the user can download.
Dynamic workers do not have access to a file system. A virtual file system can be created using the cell library. Since a dynamic worker runs through a worker, it can be passed data to save the image to R2. R2 is Cloudflare's analog of S3.
The adapted version of the example works as follows:
- The system prompt and the custom tool execute Python code. Instead of a Jupyter notebook, the tool generates an SVG image.
- The worker supports execution of JavaScript and Python. The example uses the Sonnet 4.6 model.
- The agent's code runs in a sandbox. The sandbox's response is returned to the main worker. The worker extracts the SVG code from the response and saves it to R2.
- When the URL is opened, the page is assembled with information received from Claude. Assembling it takes some time.
- The SVG image is loaded from R2. It differs from the image created in E2B. The author relies on the accuracy of the information generated by Claude Sonnet.
Mass creation of dynamic workers
A parent worker can create any number of dynamic workers. To do this, it uses a for loop that creates new workers based on values from an API. Before creating each one, the code checks whether the worker already exists. If it does, the code reuses it.
For each worker, the code runs console.log and returns a response with the worker ID corresponding to the loop index.
When run locally, 50 dynamic workers were created. All of them were created instantly.
To create 10,000 workers, the parent worker was deployed to Cloudflare so as not to overload the local machine. The created workers are displayed on pages of 30 items each. The number of pages increases as you browse. For verification, worker 1156 was selected, which returns the response "hello from worker 1156".
Current Usage and Cost
Cloudflare uses dynamic workers for Code Mode. The Zite platform uses them to run applications generated by LLMs.
Dynamic workers are currently available for free, but in the future free access may be discontinued. Although it is possible to run up to 1 million dynamic workers per second, future costs should be taken into account. Without a significant budget, it may be advisable to refrain from large-scale use.
Introduction to Dynamic Workers
Dynamic Workers are lightweight workers created programmatically from an existing worker; they run on V8 isolates and are significantly faster than containers.
- Cloudflare announced Dynamic Workers — a lower-level primitive created programmatically by an existing worker
- 100 times faster and more memory-efficient than a traditional container, since they run on V8 isolates
- An unlimited number of parallel sandboxes can be run with the same limits as a regular worker
- It is claimed that up to 1 million Dynamic Workers can be launched per second
- Limitation: only JavaScript can be run on them
Comparison with Cloudflare Sandboxes
Comparison with Cloudflare Sandboxes: sandboxes are short-lived Linux containers running on a durable object, while dynamic workers are faster and lighter but come with worker limitations.
- Cloudflare Sandboxes are short-lived Linux containers running on a durable object
- Sandboxes suit a full OS container with a file system and the ability to run almost any language and binary
- Dynamic workers suit cases where speed and lightness matter, with an unlimited number of parallel sandboxes
Dynamic Worker Setup
Setup: create a Worker via Wrangler, add a `loader` binding to the configuration, and create a nested Worker with a compatibility date and code containing a fetch function.
- The Worker was created with Wrangler; TypeScript errors may occur if
wrangler typeshas not been run - The Wrangler configuration file adds a worker loaders array with a
loaderbinding (the name can be anything) - The
loaderbinding allows creating and managing other Workers - The new constant Worker uses the loader binding; the compatibility date sets the runtime version
- The nested Worker's code has a fetch function with request and context arguments and responds with "hello world from the sandbox"
- Network access is fully disabled by passing the request from the source Worker to fetch
Retrieving an Existing Worker
Uploading a new worker each time causes an error; retrieving the existing worker by the name "worker one" allows reusing the sandbox.
- Repeating curl after uploading a new worker gives an error
- Retrieving the existing worker by name worker one allows reusing it
- On a repeated request, the response is taken from the existing worker one sandbox
Dynamic Worker Capabilities
Dynamic workers support custom bindings (for example, a chat room with Cap'n Web), NPM dependencies (Hono, the create worker function), and interception of outgoing requests for credential injection.
- You can define custom bindings, for example a chat room post method to create a stub
- The stub interacts with the worker through Cap'n Web
- You can use NPM dependencies, for example Hono, and bundle them via the create worker function
- You can intercept outgoing requests, for example to inject credentials
Running AI-Generated Code
Example of running AI-generated code: Claude Sonnet via the Anthropic SDK executes Python code from the prompt "compute π using the Monte Carlo method with 1000 iterations"; the result is saved to R2.
- Uses code from the E2B cookbook with the Anthropic SDK, the Sonnet 3.5 model, and a custom tool for executing Python in a Jupyter notebook
- The tool detects the call and runs the code inside an E2B sandbox
- Prompt: compute the value of pi using the Monte Carlo method with 1000 iterations
- The E2B sandbox has a file system and creates image.png for download
- Dynamic workers have no file system, but can create a virtual one using the cell library
- Images are saved to an R2 bucket, Cloudflare's analog of S3
- The Cloudflare version uses Sonnet 4.6, and its Python tool generates SVG instead of using Jupyter
- The main worker receives the sandbox's response, extracts the SVG code, and saves it to R2
Mass Creation of Workers
Mass creation of workers: 50 are created instantly, 10,000 are deployed in Cloudflare; each can be accessed by its ID.
- A for loop creates new workers based on the value from the API and reuses existing ones
- The code outputs a console log and a response with the worker ID by index
- 50 dynamic workers are created instantly
- 10,000 workers are created through a parent worker deployed in Cloudflare so as not to overload the local machine
- The list of workers is paginated (30 per page)
- Worker 1156 responds with "hello from worker 1156"
Usage and Cost
Dynamic Workers are already used by Cloudflare for Code Mode and by Zite for running LLM-generated applications; they are currently free, but will be paid in the future.
- Already used by Cloudflare for Code Mode and by Zite for running LLM-generated applications
- Currently free, but will not remain free forever
- The announced one million workers per second may be expensive