Multi-Tenant Worker Dispatch: Namespaces, User Workers, Routing, and Isolation
How dispatch namespaces, dynamic dispatch Workers, and user Workers run untrusted customer code with routing, bindings, and tenant isolation.
This page summarises Cloudflare Workers for Platforms documentation: building a multi-tenant product where customers (or AI) deploy their own code, each run in an isolated Worker, with a central dispatch layer routing traffic and enforcing platform policy.
Workers for Platforms: when you need customer code at scale
Section titled “Workers for Platforms: when you need customer code at scale”Workers for Platforms is for products that must run untrusted code at scale—website builders, SaaS with custom logic, AI “vibe coding” platforms, or any service where end users upload or generate application code. Each customer gets an isolated compute environment; your platform controls routing, limits, egress, and storage attachments.
Workers for Platforms lets you run untrusted code written by your customers, or by AI, in a secure hosted sandbox. Each customer runs code in their own Worker, a secure and isolated environment.
— Cloudflare, Workers for Platforms
Use it when you need unlimited per-customer scripts, strong tenant separation, programmatic routing (hostname, path, headers), per-tenant bindings (KV, D1, R2), and optional control over outbound fetch() via an outbound Worker. For fixed Worker-to-Worker calls you already know at deploy time, service bindings may suffice; dispatch namespaces are for dynamically uploaded user Workers.
| Goal | Workers for Platforms piece |
|---|---|
| Hold all customer scripts | Dispatch namespace |
| Entry point and policy | Dynamic dispatch Worker |
| Customer logic | User Worker |
| Outbound policy | Outbound Worker (optional) |
| Ops grouping | Tags |
Dispatch namespace: container for user Workers
Section titled “Dispatch namespace: container for user Workers”A dispatch namespace is the collection of user Workers your platform deploys on behalf of customers—often one production namespace for all tenants, plus a separate staging namespace for safe testing.
A dispatch namespace is a container that holds all of your customers’ Workers. Your platform takes the code your customers write, and then makes an API request to deploy that code as a user Worker to a namespace — for example staging or production.
— Cloudflare, How Workers for Platforms works
Compared with ordinary account Workers, namespaces provide an unlimited number of scripts, isolation by default (user Workers run in untrusted mode), and dynamic invocation through env.DISPATCHER.get("worker-name"). Cloudflare recommends one namespace for all customers, not one namespace per customer.
Script count for Workers for Platforms customers is described as unlimited in script limits; standard account Worker limits are separate (Workers platform limits points to Workers for Platforms when you need more).
User Worker isolation: untrusted vs trusted namespaces
Section titled “User Worker isolation: untrusted vs trusted namespaces”By default, user Workers in a dispatch namespace are untrusted—appropriate when customers control the code.
In untrusted mode: The request.cf object is not available in Workers … Each Worker has an isolated cache … caches.default is disabled for all Workers in the namespace.
— Cloudflare, Worker Isolation
Trusted mode is for internal platforms where you control all code: request.cf becomes available and Workers share cache space—only enable with cache key discipline. See Worker Isolation for the namespace API to set trusted_workers.
Bindings: per-tenant resource isolation
Section titled “Bindings: per-tenant resource isolation”Each user Worker only sees bindings explicitly attached to that script. For full data isolation, attach a unique KV namespace, D1 database, or R2 bucket per user Worker.
Each User Worker can only access the bindings that are explicitly attached to it. For complete isolation, you can create and attach a unique resource (like a D1 database or KV namespace) to every User Worker.
— Cloudflare, Bindings
Deploy metadata can include bindings and tags in one API call—see API examples.
Dynamic dispatch Worker: routing and platform logic
Section titled “Dynamic dispatch Worker: routing and platform logic”The dynamic dispatch Worker is the platform entry point: it picks the user Worker, runs auth or validation, sets limits, and may rewrite responses.
A dynamic dispatch Worker is a specialized routing Worker that directs incoming requests to the appropriate user Workers in your dispatch namespace. Instead of using Workers Routes, dispatch Workers let you programmatically control request routing through code.
— Cloudflare, Dynamic dispatch Worker
Configure a dispatch namespace binding so the dispatcher can call env.DISPATCHER.get() (binding name e.g. DISPATCHER). You can pass per-invocation context via props on get(); user code reads them from ctx.props or this.ctx.props on a WorkerEntrypoint—details in Dynamic dispatch Worker.
Request lifecycle from edge to user Worker
Section titled “Request lifecycle from edge to user Worker”The documented flow is:
- Request hits the dynamic dispatch Worker (e.g.
customer-a.example.com/api). - Dispatcher resolves the target user Worker name.
env.DISPATCHER.get("customer-a")returns the user Worker; dispatcher callsuserWorker.fetch(request).- User Worker runs; optional outbound Worker intercepts external
fetch(). - Dispatcher may modify the response before returning.
See How Workers for Platforms works — Request lifecycle.
Hostname, path, and KV routing patterns
Section titled “Hostname, path, and KV routing patterns”Path-based and subdomain dispatch
Section titled “Path-based and subdomain dispatch”Path routing maps the first path segment to a script name (example.com/customer-1 → customer-1). Subdomain routing uses the leftmost label (customer1.example.com → customer1). Examples are in Dynamic dispatch Worker and the get started template.
Hostname routing at millions of domains
Section titled “Hostname routing at millions of domains”For SaaS custom domains, Cloudflare recommends a wildcard route (*/*) on the SaaS zone to the dispatch Worker so one code path handles subdomains and vanity domains without per-hostname Workers Routes.
Configure a wildcard Route (/) on your SaaS domain … This allows you to: Support both subdomains and vanity domains … Avoid route limits … Programmatically control routing logic.
— Cloudflare, Hostname routing
Lookup tables in Workers KV (hostname → worker name) let you change routing without redeploying the dispatcher—same pattern as KV-based routing. For custom hostnames, metadata can also live in request.cf.hostMetadata when using Cloudflare for SaaS custom metadata.
Deploy and manage user Workers (API and dashboard)
Section titled “Deploy and manage user Workers (API and dashboard)”Prerequisites and deploy with bindings and tags
Section titled “Prerequisites and deploy with bindings and tags”Programmatic management needs an account ID, a dispatch namespace, and an API token with Workers permissions. The API examples show PUT to upload a script with metadata JSON (main_module, bindings, tags, compatibility_date) and the Worker module file, or the Cloudflare SDK workersForPlatforms.dispatch.namespaces.scripts.update.
Use tags (customer ID, plan, environment) for bulk operations and filtering—managed in the dashboard after Workers for Platforms dashboard improvements (namespace creation, dispatch templates, tag UI, binding visibility).
First upload readiness
Section titled “First upload readiness”Platforms that dispatch immediately after upload should rely on synchronous first-time provisioning:
With this update, first-time uploads of User Workers are now deployed synchronously. A 200 OK response guarantees the script is fully provisioned and ready to handle traffic immediately.
— Cloudflare, Workers for Platforms changelog
List scripts with GET …/dispatch/namespaces/{namespace}/scripts; delete with DELETE …/scripts/{name}—API examples.
Separately, account Workers can be created and configured before code upload, so platform teams provision settings and hand off to developers—changelog.
Static assets, egress, limits, and observability
Section titled “Static assets, egress, limits, and observability”Static assets (HTML, CSS, JS, images) can attach directly to user Workers so front ends serve from the edge with dynamic logic in the same script—Static assets, changelog.
Outbound Workers sit on customer fetch() for egress policy, secrets injection, and audit—central to enterprise designs in Enterprise AI Vibe Coding Platform and Programmable Platforms.
Custom limits on CPU time and subrequests can be applied per invocation from the dispatch Worker (tiered by plan or app class). Observability spans Tail Workers, Logpush on the dispatch Worker, GraphQL analytics by dispatchNamespaceName, and Workers Analytics Engine—see Observability and Configuration.
AI vibe coding and programmable SaaS context
Section titled “AI vibe coding and programmable SaaS context”Reference architectures describe an AI coding product stack: code generation, secure sandbox execution, fast preview loops, and Workers for Platforms to host millions of generated apps with isolation, egress control, and per-app bindings—AI Vibe Coding Platform. The dashboard can deploy a starter via VibeSDK integrated with Workers for Platforms (dashboard improvements). For governed enterprise deployments (approval pipeline, Access, Secrets Store, outbound control), see Enterprise AI Vibe Coding Platform. Broader SaaS patterns (SSL for SaaS, per-tenant D1/KV/R2) appear in SaaS platforms use cases and Enable customer code deployment.
How to check this on your site
Section titled “How to check this on your site”-
In the Cloudflare dashboard, open Workers for Platforms under Compute & AI and confirm your dispatch namespace, dispatch Worker, and at least one user Worker with expected bindings and tags visible in the UI.
-
Call the list-scripts API from API examples and verify each deployed user Worker
idand tags match your tenant records. -
Send HTTP requests through the URLs your dispatch Worker uses (path, subdomain, or custom hostname) and confirm traffic reaches the correct user Worker (404 when the script name is missing matches dispatcher error handling in Dynamic dispatch Worker examples).
-
If customers use untrusted code, confirm
request.cfis unavailable in user Workers unless you intentionally enabled trusted mode and redeployed (Worker Isolation). -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about so it can be corrected or explained.