These instructions are for a coding agent. They install workerd on this machine and run a first application.
Run each command yourself. Ask the user only where a step tells you to.
- Check the machine
- Install workerd
- Run a hello-world Worker
- Run a Durable Object with storage
- Run the user’s project, if there is one
- Tell the user what you did
Check the machine
-
Operating system. Run
uname -sm. On Windows, check the processor architecture. Theworkerdnpm package supplies binaries for Linux x86-64, Linux ARM64, macOS, and Windows x86-64. On any other platform, stop. Tell the user that the npm package has no binary for it. -
An existing project. Check the current directory for
wrangler.jsonc,wrangler.json, andwrangler.toml.wrangler.jsoncorwrangler.json: workerd reads this file. Do the hello-world steps in a scratch directory. Then go to Run the user’s project.- Only
wrangler.toml: workerd does not read this file. Tell the user. Ask before you convert it towrangler.jsonc. - None: work in a new, empty directory.
workerd will soon support
worker.config.json, the file of thecfcommand, in place ofwrangler.json. See Upcoming changes. -
Port 8787. workerd listens on
localhost:8787. Make sure that no other process, for examplewrangler dev, listens on this port. If the port is in use, add-s http=localhost:8788, or another free port, to eachnpx workerd servecommand below. Use the same port in eachcurlcommand.
Install workerd
-
If the project directory has no
package.json, runnpm init -y. -
Install workerd and esbuild in the project directory. workerd bundles
mainwith esbuild, as Wrangler does.npm install -D workerd esbuildInstead, esbuild can be on
PATH, orWORKERD_ESBUILDcan name its executable.
Run npx workerd serve -h to list the flags of serve in the installed
version.
This setup does not use these other ways to get workerd:
- Docker. The image
cloudflare/workerdrunsworkerd serve /appon port 8787. It has no esbuild, so the project must set"no_bundle": true. Readhttps://workerd.dev/docs/cluster/index.md#run-in-docker. - Releases. The releases are at
https://github.com/cloudflare/workerd/releases. The documentation does not describe the release files.
Run a hello-world Worker
Create a hello/ directory with these two files. The Worker 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 }Start workerd as a background process. It runs until you stop it.
npx workerd serve ./hello/wrangler.jsonSend a request to it:
curl http://localhost:8787/The response is Hello from workerd! url=http://localhost:8787/. Stop
workerd, because the next step uses the same port.
Run a Durable Object with storage
A Durable Object is a single-threaded actor with its own SQLite database. On
one machine, workerd keeps the database across restarts, in
.wrangler/state/workerd beside the configuration.
Create a counter/ directory with these two files. The Worker gives each
name its own counter. It reaches the class through ctx.exports.Counter,
so it needs no binding.
export class Counter {
constructor(state, env) {
this.state = state;
}
async fetch(request) {
let n = (await this.state.storage.get("n")) ?? 0;
n++;
await this.state.storage.put("n", n);
return Response.json({ n, url: request.url });
}
}
export default {
async fetch(request, env, ctx) {
const name = new URL(request.url).searchParams.get("name") ?? "default";
const id = ctx.exports.Counter.idFromName(name);
return ctx.exports.Counter.get(id).fetch(request);
},
};{
"name": "counter",
"main": "index.js",
"compatibility_date": "2026-01-01",
"no_bundle": true,
"exports": {
"Counter": { "type": "durable-object", "storage": "sqlite" }
}
}Start workerd in the background. Then send the same request two times:
npx workerd serve ./counter/wrangler.jsonc
curl 'http://localhost:8787/?name=alice'
curl 'http://localhost:8787/?name=alice'The responses have "n":1 and "n":2. Stop workerd and start it again.
Send the request once more. The response has "n":3, because the state
survived the restart.
The exports map in the configuration declares each Durable Object class.
"storage": "sqlite" gives the class a SQLite database. ctx.exports
needs a compatibility date of 2025-11-17 or later.
Run the user’s project
If the user has no Wrangler configuration, skip this section.
workerd is not a hardened sandbox. Do not run untrusted code outside a virtual machine or another secure sandbox.
Before you start the project, compare its configuration with what workerd accepts:
- Run
npx workerd -h. Compare the fields in its Config section with the top-level keys of the project’s configuration. - A top-level key that the help does not list stops startup, for example
routes,services, orcontainers. Tell the user which keys stop startup. Ask before you remove them. - If the project uses a field that the help lists under
--experimental, add--experimentalto the command. - If the project uses Containers, Workers AI, Vectorize, Hyperdrive, Browser Rendering, or Email Workers, tell the user. workerd does not implement these services.
Dynamic Workers, Python Workers, and service bindings between Workers need
a config.capnp. A Wrangler configuration cannot declare them.
Start the project. If the file is wrangler.json, use ./wrangler.json.
npx workerd serve ./wrangler.jsoncworkerd does not read .dev.vars or .env. If the project keeps local
values in these files, tell the user. To rebuild and restart workerd on a
change, add --watch. Add .wrangler/ to .gitignore.
workerd does not migrate stored state. After a configuration change, an
error that looks unrelated can come from old state in
.wrangler/state/workerd. Tell the user that a delete removes local data.
Then delete the directory to start from an empty state.
When you finish, tell the user:
┌─ workerd Agent Setup Complete ───────────────────────┐
│ ✓ workerd <version from npm ls workerd> │
│ ✓ hello http://localhost:8787/ │
│ ✓ counter n survived a restart │
│ ✓ project <path, or "none"> │
└──────────────────────────────────────────────────────┘Next steps
Each service page, listed at https://workerd.dev/docs/index.md#services,
has an example and the differences from Cloudflare.
Do not start a cluster unless the user asks for one. To run several
instances as a cluster on one object store bucket, read
https://workerd.dev/docs/index.md from “Run a cluster” on. Then read
https://workerd.dev/docs/cluster/index.md.
For the supported APIs and services, read
https://workerd.dev/docs/cloudflare-compat/index.md. For the operational
limits, read https://workerd.dev/docs/limitations/index.md.
You can read these instructions again at
https://workerd.dev/docs/agent-setup/prompt.md.