A proof-of-concept demonstrating Cloudflare's Dynamic Worker Loader API in local development. This allows you to spin up Worker isolates programmatically without deploying them.
- Runs a main Hono worker that serves a web interface
- Accepts custom JavaScript code from users
- Creates dynamic Worker isolates on-demand using the Worker Loader API
- Executes user code in sandboxed environments with no network access
- Persists prompt history using Durable Objects
Dynamic Worker Loaders enable several interesting patterns:
- Runtime code execution: Run user-provided scripts without deployment
- Per-tenant isolation: Spin up separate compute environments for different customers
- A/B testing: Load different code versions dynamically
- Sandbox environments: Execute untrusted code safely with
globalOutbound: null - Ephemeral compute: Create workers, use them, and let them be garbage collected
Main Worker (Hono app)
āāā Serves web interface
āāā Accepts user code + prompt
āāā Creates dynamic isolate keyed by code hash
āāā Executes user code with prompt as ?q= parameter
Dynamic Isolate
āāā Runs user's ESM code
āāā No network access (globalOutbound: null)
āāā Receives prompt via URL search params
āāā Returns response to main worker
Durable Object
āāā Stores recent prompts for easy reuse
# Install dependencies
bun install
# Start development server
bun dev
# Visit http://localhost:8787Worker Loader Configuration (wrangler.jsonc):
{
"worker_loaders": [
{ "binding": "LOADER" }
]
}Dynamic Isolate Creation:
const worker = c.env.LOADER.get(isolateId, async () => ({
compatibilityDate: "2025-06-01",
mainModule: "main.js",
modules: { "main.js": userModule },
env: { WHO: "dynamic-sandbox" },
globalOutbound: null // No network access
}));Calling the Dynamic Worker:
const endpoint = worker.getEntrypoint();
const response = await endpoint.fetch(`http://sandbox/?q=${prompt}`);Important: Dynamic Worker Loaders are currently in closed beta for production deployment.
The project deploys as-is with wrangler deploy.
You'll get this error: binding LOADER of type worker_loader is invalid [code: 10021]
Option 1: Apply for beta access at Cloudflare's beta program
Option 2: Deploy without Worker Loaders for demo purposes:
# Use the production config without worker_loaders
wrangler deploy --config wrangler.prod.jsoncThe app will work except for the code execution feature - users can still see the interface and examples.
Works immediately with Wrangler 4.x - no beta access required.
- Runtime: Cloudflare Workers
- Framework: Hono with JSX
- Bundler: Wrangler 4.x
- Styling: Tailwind CSS (CDN)
- Validation: Effect Schema
- Storage: Durable Objects
- Package Manager: Bun
- Code playground: Let users test Worker scripts without deployment
- User-defined transforms: Allow customers to write data processing logic
- Multi-tenant applications: Isolate per-customer business logic
- Dynamic routing: Create request handlers on the fly
- Compute-as-a-Service: Serverless functions with user-provided code
src/
āāā worker.tsx # Main Hono application
āāā do.tsx # Durable Object for prompt storage
āāā env.d.ts # TypeScript environment definitions
wrangler.jsonc # Wrangler configuration
MIT