workerd / per_isolate
AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub
Per-isolate JavaScript/TypeScript bootstrap: scripts that run synchronously at context creation, before any user code. Gated by the per-isolate-javascript-bootstrap autogate (config: workerd-autogate-per-isolate-javascript-bootstrap). C++ entry point: src/workerd/io/per-isolate-bootstrap.c++. - Scripts are compiled as functions with a context-extension object — the pseudo-globals require, module, exports, compatFlags, autogates, primordials, utils are in scope but NOT on globalThis (see per_isolate-env.d.ts). - Module system is bootstrap CommonJS: require('webstreams/queue') + module.exports = {...}. The src/node/ ESM-only rule does NOT apply here. Circular requires are a FATAL startup error…
Trending
Quiet since August.thin dataabout the whole repository
Who's talking about cloudflare/workerd
- A Hacker News story“OS Workerd, Cloudflare's JavaScript/WASM Runtime”Hacker News · Sep 27, 2022 · 27 points
- withastro/astro“Cloudflare adapter returning [object Object]”GitHub · Oct 10, 2025 · 18 reactions
- supabase/supabase-js“The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers”GitHub · Mar 28, 2024 · 16 reactions
- nodejs/node“src: improve buffer.transcode performance”GitHub · Aug 1, 2024 · 13 reactions
- NixOS/nixpkgs“Package request: workerd”GitHub · Nov 12, 2024 · 12 reactions
The biggest 5 of 12 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 12
Talked about on GitHub, Bluesky and Hacker News (12 times).
On GitHub · 6
- Oct 10, 2025Cloudflare adapter returning [object Object] — withastro/astro18 reactions · 15 comments
- Mar 28, 2024The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers — supabase/supabase-js16 reactions · 24 comments
- Aug 1, 2024src: improve buffer.transcode performance — nodejs/node13 reactions · 26 comments
- Nov 12, 2024Package request: workerd — NixOS/nixpkgs12 reactions · 8 comments
- Feb 19, 2024Add Curve25519 — w3c/webcrypto9 reactions · 16 comments
1 more on GitHub
- Nov 3, 2025Optimize TextEncoder::encode — nodejs/performance7 reactions · 33 comments
On Bluesky · 4
- Mar 24, 2026workerd : le runtime JavaScript/Wasm open source de Cloudflare Workers — @news.humancoders.com4 likes and reposts
- Aug 22, 2026Current status: trying to build github.com/cloudflare/w... on various sandbox providers — @jeremymorrell.dev1 likes and repost
- Mar 24, 2026workerd : le runtime JavaScript/Wasm qui propulse Cloudflare Workers est maintenant open source. Basé sur les standards web, il permet… — @humancoders.com1 likes and repost
- Nov 5, 2024Technically workers are open source github.com/cloudflare/w... — @userops.bsky.social1 likes and repost
On Hacker News · 2
- Sep 27, 2022OS Workerd, Cloudflare's JavaScript/WASM Runtime27 points · 2 comments
- Oct 5, 2023Cloudflare workers is adopting Ada URL parser2 points
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository61 other files it gives its agents.
- AGENTS.mdAGENTS.md
- build/AGENTS.mdAGENTS.md
- src/cloudflare/AGENTS.mdAGENTS.md
- src/node/AGENTS.mdAGENTS.md
- src/per_isolate/crypto/AGENTS.mdAGENTS.md
- src/per_isolate/webfs/AGENTS.mdAGENTS.md
- src/per_isolate/webstreams/AGENTS.mdAGENTS.md
- src/pyodide/AGENTS.mdAGENTS.md
- src/rust/AGENTS.mdAGENTS.md
- src/rust/cxx/AGENTS.mdAGENTS.md
- src/tests/node/AGENTS.mdAGENTS.md
- src/tests/node/http-client/AGENTS.mdAGENTS.md
- src/tests/node/http-server/AGENTS.mdAGENTS.md
- src/tests/node/net/AGENTS.mdAGENTS.md
- src/tests/node/stream/AGENTS.mdAGENTS.md
- src/tests/streams/AGENTS.mdAGENTS.md
- src/tests/streams/cache/AGENTS.mdAGENTS.md
- src/tests/streams/compression/AGENTS.mdAGENTS.md
- src/tests/streams/digest/AGENTS.mdAGENTS.md
- src/tests/streams/encoding/AGENTS.mdAGENTS.md
- src/tests/streams/formdata/AGENTS.mdAGENTS.md
- src/tests/streams/htmlrewriter/AGENTS.mdAGENTS.md
- src/tests/streams/identity/AGENTS.mdAGENTS.md
- src/tests/streams/inspect/AGENTS.mdAGENTS.md
- src/tests/streams/iocontext/AGENTS.mdAGENTS.md
- src/tests/streams/piping/AGENTS.mdAGENTS.md
- src/tests/streams/r2-patterns/AGENTS.mdAGENTS.md
- src/tests/streams/readable/AGENTS.mdAGENTS.md
- src/tests/streams/readable-byte/AGENTS.mdAGENTS.md
- src/tests/streams/scaling/AGENTS.mdAGENTS.md
- src/tests/streams/sockets/AGENTS.mdAGENTS.md
- src/tests/streams/strategies/AGENTS.mdAGENTS.md
- src/tests/streams/transform/AGENTS.mdAGENTS.md
- src/tests/streams/writable/AGENTS.mdAGENTS.md
- src/workerd/api/AGENTS.mdAGENTS.md
- src/workerd/api/crypto/AGENTS.mdAGENTS.md
- src/workerd/api/node/AGENTS.mdAGENTS.md
- src/workerd/api/streams/AGENTS.mdAGENTS.md
- src/workerd/io/AGENTS.mdAGENTS.md
- src/workerd/jsg/AGENTS.mdAGENTS.md
- src/workerd/server/AGENTS.mdAGENTS.md
- src/workerd/util/AGENTS.mdAGENTS.md
- types/AGENTS.mdAGENTS.md
- bazel-test-hygieneSkill
- commit-categoriesSkill
- dad-jokesSkill
- find-and-run-testsSkill
- identify-reviewerSkill
- investigation-notesSkill
- kj-styleSkill
- markdown-draftsSkill
- parent-project-skillsSkill
- pr-review-guideSkill
- receiving-code-reviewSkill
- rust-reviewSkill
- ts-styleSkill
- update-v8Skill
- wd-test-formatSkill
- workerd-api-reviewSkill
- workerd-safety-reviewSkill
- The first 60 shown.
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
Primordials discipline: no bare prototype lookups on builtins after bootstrap captures.
- Distinctive: line 78
Use captured references whenever bootstrap code operates on built-in objects whose prototypes are reachable by user code:
- Very specific: line 102
Type identification: Never use instanceof or .constructor for type checks — both are user-controllable.
- Very specific: line 114
User-provided iterables / async iterables: When an API accepts an Iterable or AsyncIterable from user code (e.g., …
- Very specific: line 124
User-provided objects generally: When reading properties from user-provided objects (e.g., the init bag in new Request(url, init)), normal …
- Very specific: line 150
Use captured constructors (primordials.Map) only when you need new but will access the instance exclusively through captured uncurried …
- Distinctive: line 198
strictly internal: Never assign them as properties on any object reachable by user code.
- Very specific: line 205
Never return a SafePromise to user code — wrap with PromiseResolve() to return a regular Promise.
- Distinctive: line 207
Never store a Safe\* wrapper on a user-visible object property.
- Very specific: line 208
Never expose captured constructors (e.g., primordials.Map) as API return values or properties.
- Distinctive: line 218
NEVER: add a runtime require cycle between bootstrap scripts.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
src/per_isolate/
Per-isolate JavaScript/TypeScript bootstrap: scripts that run synchronously
at context creation, before any user code. Gated by the
per-isolate-javascript-bootstrap autogate (config:
workerd-autogate-per-isolate-javascript-bootstrap). C++ entry point:
src/workerd/io/per-isolate-bootstrap.c++.
EXECUTION MODEL
- Scripts are compiled as functions with a context-extension object — the
pseudo-globals
require,module,exports,compatFlags,autogates,primordials,utilsare in scope but NOT onglobalThis(seeper_isolate-env.d.ts). - Module system is bootstrap CommonJS:
require('webstreams/queue')+module.exports = {...}. Thesrc/node/ESM-only rule does NOT apply here. Circular requires are a FATAL startup error — keep modules acyclic (e.g.,webstreams/ring-bufferis a leaf, andwebstreams/nativerequires nothing else). - TypeScript
import type/export typeare used freely for type plumbing (fully erased; the loader only seesmodule.exports). main.tsinstalls the real stream globals (ReadableStream et al.) when thetypescript_implemented_streamscompat flag is enabled, plus the internal-testingReadableStreamDrainingReaderunderexpose_draining_reader.- Files are auto-discovered (
BUILD.bazelandtsconfig.jsonboth glob**/*.ts). No registration needed for new files. - Local convention: no copyright headers in this directory's bootstrap scripts (deviation from the repo-wide new-file rule; keep consistent).
CONVENTIONS
- Primordials discipline: no bare prototype lookups on builtins after
bootstrap captures; no
for...ofover patchable iterables. Capture methods/getters at module scope viauncurryThis. See the PRIMORDIALS USAGE section below for the full guide. - JSG property capture trap: readonly JSG properties live on the
PROTOTYPE only under modern compat
(
workers_api_getters_setters_on_prototype, default-on 2022-01-31). Under older dates JSG usesSetNativeDataPropertyon the INSTANCE template — an own native DATA property per instance; no getter function exists anywhere to capture. UsecaptureJsgGetterin theprimordials.ts: prototype-accessor capture with a plain-read fallback (an own data property read never consults the patchable prototype chain). The bootstrap runs for every worker regardless of compat date — both layouts must work. JSG methods are always on the prototype. - Internal cross-module surfaces are exported as a single namespace
object (
internalsForPipe,nativeStreamInternals), never re-exported to users. - Internal class dispatch uses private-brand
inchecks, NEVERinstanceof(classes reachable from the global have user-reachableSymbol.hasInstance).
PRIMORDIALS USAGE
Bootstrap code shares an isolate with user code. After bootstrap runs,
user code can replace or patch any global constructor, prototype method,
or well-known symbol accessor. Primordials are pre-user-code captures of
built-in functions and constructors that remain trustworthy regardless of
subsequent mutation. The captures are in primordials.ts; the primordials
pseudo-global is injected into every bootstrap script's scope.
What primordials guarantee — and what they do not. Primordials are
an internal correctness mechanism, not a security sandbox. The hard
security boundary is the V8 isolate: separate address spaces, no shared
mutable state between tenants. Within a single isolate, primordials
ensure that the runtime's own implementation (bootstrap code, built-in
API polyfills, internal bookkeeping) continues to function correctly even
when user code mutates built-in prototypes — whether by accident (sloppy
polyfills, test mocks) or by design (legitimate metaprogramming).
Without primordials, a user doing Array.prototype.push = () => {} or
Promise.prototype.then = badFn could break internal runtime code that
calls those methods, leading to silent data corruption, spec-violating
behaviour, or crashes. Primordials prevent that class of failure.
When primordials ARE required
Use captured references whenever bootstrap code operates on built-in objects whose prototypes are reachable by user code:
- Method calls on built-in types.
array.push(v)dispatches throughArray.prototype.push— useArrayPrototypePush(array, v). This applies to Map, Set, Promise, ArrayBuffer, TypedArray, DataView, String, and every other built-in with a mutable prototype. - Constructor calls.
new Map()uses the globalMap— usenew primordials.Map()(ornew SafeMap()when you also need safe method dispatch — see below). - Static methods.
Promise.resolve(v)uses the globalPromise— usePromiseResolve(v). - Iteration of internal collections.
for...ofcalls[Symbol.iterator]()on the target, which is patchable on built-in prototypes. For arrays, useSafeArrayIteratoror index-based loops. For Map/Set, useSafeMap/SafeSet(whose[Symbol.iterator]is overridden) or iterate with captured methods andSafeMapIterator/SafeSetIterator. - Metadata reads on views at trust boundaries.
view.buffer,view.byteOffset,view.byteLength,view.lengthare prototype accessors that user code can shadow or redefine. Use the captured getters:TypedArrayPrototypeGetBuffer(view),TypedArrayPrototypeGetByteLength(view), etc. Same for DataView equivalents. - Type identification. Never use
instanceofor.constructorfor type checks — both are user-controllable. UseTypedArrayPrototypeGetSymbolToStringTag(value)for typed arrays (returns the internal[[TypedArrayName]]orundefined) and private-brand#field in objchecks for internal classes.
When primordials are NOT required
Primordials protect bootstrap code from mutations to built-in prototypes. They are not needed — and actively wrong — when the goal is to invoke user-defined behaviour:
- User-provided iterables / async iterables. When an API accepts an
IterableorAsyncIterablefrom user code (e.g.,ReadableStream.from(userIterable)), you MUST call the user's[Symbol.iterator]()/[Symbol.asyncIterator]()— that is the API contract. UsingSafeArrayIteratorwould bypass the user's iterator and break semantics. Standardfor...of/for await...ofis correct here. - User-provided callbacks. Callbacks passed by user code (e.g.,
underlyingSource.pull,transformer.transform, strategysize()) are user-defined functions — call them normally. - User-provided objects generally. When reading properties from
user-provided objects (e.g., the
initbag innew Request(url, init)), normal property access is correct — you are consuming the user's API surface, not a built-in prototype. - Spread /
Array.fromon user iterables.[...userIterable]andArrayFrom(userIterable)both invoke the user's iteration protocol, which is correct when the spec requires consuming a user iterable.
The bright line: primordials protect built-in prototype chains from third-party mutation. If the object is user-provided and you are intentionally invoking user-defined protocols, use normal JS operations.
Captured constructors vs Safe wrappers
The exports include both raw captured constructors and Safe wrappers. These are NOT interchangeable:
primordials.Map(=MapCtor): the originalMapconstructor, captured before user code runs.new primordials.Map()creates a real Map, but method calls on it (.get(),.set(), etc.) still dispatch throughMap.prototype— which user code can patch.SafeMap: extendsMapCtorwith every method overridden to dispatch through captured primordials.new SafeMap()is safe for both construction and subsequent method calls. Same forSafeSet,SafeWeakMap,SafeWeakSet.
Use captured constructors (primordials.Map) only when you need new
but will access the instance exclusively through captured uncurried
methods (e.g., MapPrototypeGet(map, key)). Use Safe wrappers when you
want normal map.get(key) call syntax with pollution resistance.
Promise patterns
SafePromise: species-protected for the promises it creates;.then()/.catch()/.finally()use captured methods andSymbol.speciesis pinned. Static helpers (SafePromise.resolve,.reject,.all, etc.) are bound toSafePromise. Use for internal-only promise chains where species hijacking would be a concern. Converting an ordinary promise into one adds a microtask.PromiseResolve/PromiseReject/PromiseWithResolvers: captured statics bound to the originalPromiseconstructor. Use for user-facing promises — the returned promise is a regularPromise, which is what spec algorithms and user code expect.PromisePrototypeThen/PromisePrototypeCatch/PromisePrototypeFinally: captured prototype methods. Use when chaining on an existing promise (internal or external) without relying on the prototype chain. They are the realPromise.prototype.thenand friends, so on an ordinary promise they still run the species lookup (promise.constructor, thenPromise[Symbol.species]); only thethenproperty lookup itself is bypassed. JS has no species-freethen(V8's C++Promise::Thenhas one), so this exposure is accepted rather than worked around with extra promise hops.
Accepted exposures
Two prototype-pollution classes are deliberately not defended against, because every defense costs microtasks or a C++ call on the per-chunk path, and the same pollution breaks the user's own code in every engine:
Promise[Symbol.species]/Promise.prototype.constructorreachingPromisePrototypeThenon ordinary promises (above).Object.prototype.thenintercepting a promise resolved with a plain object, notably the spec-mandated{ value, done }read results. Internal code that consumes those results through the same promise (pipes, drain fallbacks) is exposed alongside the user's read.
Internal-only records should still be null-prototype
({ __proto__: null, ... }) wherever nothing requires the
Object.prototype chain.
Never expose primordials to user code
Primordial captures, Safe* classes, and captured constructors are
strictly internal. Never assign them as properties on any object
reachable by user code. If user code can reach a Safe* class instance,
it can traverse Object.getPrototypeOf() to reach the Safe class and
then the original captured constructor — potentially mutating it and
affecting all code that references it.
Consequences:
- Never return a
SafePromiseto user code — wrap withPromiseResolve()to return a regularPromise. - Never store a Safe* wrapper on a user-visible object property.
- Never expose captured constructors (e.g.,
primordials.Map) as API return values or properties.
The module.exports object from primordials.ts is ObjectFreeze-d
to prevent accidental mutation by downstream bootstrap scripts.
ANTI-PATTERNS
- NEVER assume a JSG readonly property has a capturable getter (see the capture trap above).
- NEVER add a runtime require cycle between bootstrap scripts.
See also webstreams/AGENTS.md for streams-specific architecture and
anti-patterns.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

