Self-hosted distributed Durable Objects.
workerd (pronounced "worker-dee") is the open-source JavaScript and
WebAssembly runtime behind Cloudflare Workers. Use it to
self-host Workers and Durable Objects—standalone or as an experimental cluster
over an object store bucket—develop Workers locally (it powers Wrangler), or
run a programmable HTTP proxy.
Create two files in an app/ directory:
app/wrangler.json
{
"main": "index.js",
"no_bundle": true,
"compatibility_date": "2026-10-01",
"exports": {
"Counter": {
"type": "durable-object",
"storage": "sqlite"
}
}
}app/index.js
import { DurableObject } from "cloudflare:workers";
export class Counter extends DurableObject {
increment() {
const n = (this.ctx.storage.kv.get("n") ?? 0) + 1;
this.ctx.storage.kv.put("n", n);
return n;
}
}
export default {
async fetch(request, env, ctx) {
const name = new URL(request.url).pathname.slice(1) || "world";
const counter = ctx.exports.Counter.getByName(name);
const n = await counter.increment();
return new Response(`Hello, ${name}! (visit ${n})\n`);
},
};Run it with npm or Docker:
npx workerd serve ./app/wrangler.json
# or:
docker run -p 8787:8080 -v ./app:/app cloudflare/workerdCall the object twice:
curl http://localhost:8787/alice
curl http://localhost:8787/alice
# Hello, alice! (visit 1)
# Hello, alice! (visit 2)"no_bundle": true skips esbuild; without it, workerd bundles main with
esbuild as Wrangler does. State persists in .wrangler/state/workerd/ (or
--data-dir). Pass --watch to reload on edits, -s http=*:8080 to change
the listen address, or npx workerd --help for all commands (serve, test,
bench, compile, and experimental repl).
A small named server that owns one piece of state: a user, a document, or a chat room.
- Unique. Exactly one exists per name, so every request for that name reaches the same object.
- Durable. Each object has its own SQLite database with synchronous reads and writes, stored on local disk or in the cluster's object store bucket.
- Single-threaded. Its code runs on one thread, making state easy to reason about.
- Holds WebSockets. Many clients connect to one object; it can hibernate with sockets open and wake on the next message.
- Sleeps when idle. Idle objects leave memory and wake on the next request, on any instance in the cluster.
Common uses: AI agents (one object per agent with its memory, schedule, and inbox), real-time apps (games, chat rooms, collaborative docs without locks or a message bus), and sharded apps (one object per user, tenant, or device).
Point several workerd processes at one object store bucket (s3://, such as
Cloudflare R2, or gs://) to form a cluster. Each Durable Object has one owner
at a time, any instance forwards requests to the owner, and when an owner stops
or loses its lease, another instance picks its objects up from the bucket—no
leader election or external consensus service.
Start each instance with the same 32-byte key (openssl rand -hex 32), bucket,
and that machine's private address:
export WORKERD_CLUSTER_KEY=...
export WORKERD_CLUSTER_BUCKET=s3://BUCKET/PREFIX
export AWS_ENDPOINT_URL=https://ACCOUNT_ID.r2.cloudflarestorage.com
export AWS_REGION=auto
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
npx workerd serve --experimental ./app --cluster-addr 10.0.0.1:7000Each instance answers 200 OK on GET /ready on its cluster port once ready.
- Clustering is experimental (
--experimental). Every acknowledged write waits for its bucket upload. - Stop with
SIGTERMto drain and hand off objects (8 s default);SIGINT(Ctrl-C) exits immediately and objects wait for the ~20 s lease to expire. - Peer traffic is authenticated with the cluster key but unencrypted. Run peers on a private network (VPC, WireGuard, Tailscale); public cluster addresses are refused by default.
See samples/kubernetes/README.md for a
Kubernetes manifest and workerd serve --help for all cluster options.
| Service | What it is | Status |
|---|---|---|
| Workers | Stateless request handlers | Supported |
| Durable Objects | Single-threaded actors with SQLite storage | Supported |
| Facets | Child objects inside a Durable Object | Supported |
| KV | Key-value store (single-instance only) | Experimental |
| Queues | Message queue (single-instance only) | Experimental |
| D1 | SQL database | Experimental |
| R2 | Object storage | Experimental |
| Workflows | Durable multi-step execution | Experimental |
| Cron Triggers | Scheduled handlers | Experimental |
| Static assets | Files served from a directory | Experimental |
| Cache API | The caches API, kept on disk |
Experimental |
| Secrets Store | Read-only secrets from WORKERD_SECRET_* env vars |
Experimental |
| Rate limits | Request counters, kept in memory | Experimental |
| Dynamic Workers | Workers loaded at runtime (config.capnp) |
Experimental |
| Python Workers | Workers written in Python (config.capnp) |
Experimental |
Experimental services require --experimental (except Python Workers, which
use the python_workers compatibility flag). Unknown wrangler.json fields
are errors. Run workerd -h and workerd serve -h for the full list of
supported wrangler.json fields, environment variables, and binding caveats.
Not supported: Workers AI, AI Search, Vectorize, Hyperdrive, Browser
Rendering, Images, Stream, Media Transformations, Email Workers, Containers (in
wrangler.json), Pipelines, Workers for Platforms, VPC Services, and mTLS
certificates.
For full control (TLS sockets, multiple services, Dynamic or Python Workers),
configure workerd with Cap'n Proto instead of wrangler.json; see
src/workerd/server/workerd.capnp and
samples/ (start with samples/wrangler or
samples/helloworld_esm).
workerd versions are dates matching the maximum supported
compatibility date,
so upgrading never breaks Workers configured to an earlier date. See the
launch blog post
for the runtime's design principles (web standards, capability bindings,
nanoservices).
workerd is not a hardened sandbox. It isolates Workers to their
configured bindings, but on its own lacks defense-in-depth against
implementation bugs. Run possibly-malicious code inside a virtual machine or
another secure sandbox. Cloudflare Workers
adds multiple layers of defense-in-depth.
In cluster mode, one cluster is one trust domain: bucket write access or the cluster key grants full control over every Worker and object. Report vulnerabilities via Cloudflare's bug bounty program or SECURITY.md.
- Docker:
docker.io/cloudflare/workerd(distroless, non-root,linux/amd64andlinux/arm64). See docker/README.md. - Kubernetes: Multi-pod cluster manifest with graceful rollouts. See samples/kubernetes/README.md.
- systemd: Socket activation with
--socket-fdunder an unprivileged user. See docs/systemd.md.
Prebuilt npm binaries (npx workerd ...) are tested on Linux (x86_64,
arm64, glibc 2.35+), macOS (x86_64, arm64, macOS 13.5+ with
xcode-select --install), and Windows (x86_64), requiring x86_64 SSE4.2 +
CLMUL or arm64 CRC (armv8.1-a).
Build from source with Bazelisk / Bazel:
bazel build //src/workerd/server:workerdSee docs/development.md for platform prerequisites
(Linux, macOS, Windows), release builds, local wrangler dev integration
(MINIFLARE_WORKERD_PATH), and IDE setup (docs/vscode.md).
See CONTRIBUTING.md before opening a PR. Licensed under
Apache-2.0.