A Worker is a request handler that uses the Cloudflare Workers API. workerd runs each Worker in a V8 isolate, as Cloudflare does. In a cluster, every instance runs the same Worker, so a load balancer can send a request to any instance. Read the handlers documentation for the API.
Example
The hello example returns a text response from a
fetch handler.
export default {
async fetch(request, env) {
return new Response("Hello from workerd! url=" + request.url, {
status: 200,
});
},
};{ "name": "hello", "main": "index.js", "compatibility_date": "2026-01-01", "no_bundle": true }npx workerd serve ./hello/wrangler.json
curl http://localhost:8787/workerd listens on localhost:8787, as wrangler dev does. To listen on
another address, pass -s http=ADDRESS, for example -s http=*:8080.
The examples set "no_bundle": true, so they do not need esbuild. Without
it, workerd bundles main with esbuild, as Wrangler does. The workerd
npm package does not include esbuild. Install it with
npm install -D esbuild.
workerd will soon support worker.config.json, the file of the cf
command, in place of wrangler.json. See
Upcoming changes.
Differences from Cloudflare
- A
wrangler.jsonproject serves plain HTTP. To serve HTTPS, put a proxy in front of workerd, or use anhttpssocket in aconfig.capnp. workerd does not manage a custom domain. - workerd refuses a Wrangler field that it does not support, such as
aifor Workers AI. It also refuses fields that apply only to a deploy to Cloudflare, such asobservability,routes,account_id, andworkers_dev. Remove these fields before you serve the project.
See also Cloudflare compatibility.
Python Workers
workerd runs
Python Workers
on Pyodide, as Cloudflare does. A wrangler.json cannot name a .py file
as main, so the Python example uses a
config.capnp, the native workerd configuration format. The Worker returns
the SHA-256 and the word count of the request body.
using Workerd = import "/workerd/workerd.capnp";
const config :Workerd.Config = (
services = [(name = "main", worker = .worker)],
sockets = [
(name = "http", address = "localhost:8787", http = (), service = "main"),
],
);
const worker :Workerd.Worker = (
modules = [(name = "entry.py", pythonModule = embed "src/entry.py")],
compatibilityDate = "2026-01-01",
compatibilityFlags = ["python_workers"],
);# POST text to get its SHA-256 and its word count.
import hashlib
from workers import Response, WorkerEntrypoint
class Default(WorkerEntrypoint):
async def fetch(self, request):
text = await request.text()
return Response.json({
"sha256": hashlib.sha256(text.encode()).hexdigest(),
"words": len(text.split()),
})npx workerd serve ./python/config.capnp
curl --data 'hello from python' http://localhost:8787/- A Python Worker needs the
python_workerscompatibility flag. The compatibility date selects the Pyodide and Python versions, as on Cloudflare. - workerd downloads the Pyodide bundle, about 17 MB, when it starts. To
keep a copy on disk, pass
--pyodide-bundle-disk-cache-dir DIR. - From compatibility date
2026-04-21, theworkersSDK is not built in. To use the built-in SDK with a later date, add thedisable_python_external_sdkflag. - workerd does not read
pyproject.tomlor scanpython_modules/. Aconfig.capnpnames each module, sopywrangler syncadds no package. The example uses the standard library and the built-inworkersSDK, because its compatibility date is before2026-04-21. - A Python Worker works in a cluster. To join one, pass
--experimentaland--cluster-addr. Theconfig.capnpmust also have a writablediskservice nameddo-storage.