Skip to content

Let examples/prerender run trusted, and fix the claim instead - #167

Merged
jimhoyd merged 1 commit into
mainfrom
claude/prerender-trusted-default
Sep 19, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
claude/prerender-trusted-default

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Corrects #166. That PR fixed examples/prerender's false isolation claim by making the claim true — adding sandbox: true to all three routes — when the code was right and the comment was wrong.

Why the example should be trusted

docs/AI-AUTHORING.md, "Deciding when a route needs sandbox: true":

Do not add sandbox: true reflexively to every route "for safety" — it costs the route the worker-pool capacity ceiling (docs/CAPACITY.md) and the ability to use fetch, Node builtins, the filesystem or npm packages, for isolation most routes do not need.

It then names the three cases that warrant it: code nobody has reviewed, a secret whose blast radius matters, or logic complex enough that limiting a bug's reach is the safety margin wanted.

The example meets none. functions/page.mjs is:

export function page(request, {args}) {
  return new Response(args.body, {headers: {'content-type': 'text/html; charset=utf-8'}});
}

Reviewed first-party code, literal arguments from urlcode.yaml, no secret, no untrusted input, no I/O. That is the trusted default's own case. Shipping the flagship recipe with a reflexive opt-in teaches readers to cargo-cult sandbox: true and puts the example in direct conflict with the guidance page.

What changed

  • The three sandbox: true declarations are removed; the YAML comment now says why the default is right here and points at the guidance section.
  • functions/page.mjs's comment describes trusted in-process execution and says there is nothing here for sandbox: true to isolate.
  • The README leads with what the recipe is about again, and notes that a route declaring sandbox: true prerenders the same way — prerendering does not care either way. docs/PRERENDER.md already said that; the example now matches it.
  • "Guest execution" / "guest code" become "project code" where they meant the route's own handlers. Under the trusted default those run in-process as project code, not as a guest.

The check from #166 is unaffected, and points the right way

unbacked-isolation-claim requires prose and YAML to agree; it does not require a project to be sandboxed. Verified in both directions on this branch:

$ node scripts/check-trust-model-prose.ts
Trust-model prose check: 185 file(s) scanned, no stale claims.

# re-add a QuickJS claim to page.mjs:
examples/prerender/functions/page.mjs:10 [unbacked-isolation-claim]
  This runs in the QuickJS/WASM sandbox with no filesystem access.
  -> no route in this project declares `sandbox: true`, so its code runs trusted and in-process; declare it or drop the claim

So the original defect stays caught, whichever way a future edit resolves it.

Verification

  • npm run verify — 512 tests, 510 pass, 2 skipped, 0 fail
  • Recipe end to end: test passes 7 fixtures, prerender.mjs emits 3 pages, audit --expect-routes 3 passes 12/12
  • Output is byte-identical in shape to before (1748 vs 1738 bytes — the footer wording changed, nothing structural)

Compatibility and security

The example's routes now run trusted rather than sandboxed. That is a behavior change to an example project, not to the runtime, and it restores the default the runtime already applies to any route that declares nothing. No runtime, schema or API change.

  • Changes match the documented portable contract; docs/examples are updated where needed.
  • Relevant tests and package checks pass, or limitations are explained above.
  • No credentials, customer data or private project material are included.
  • Runtime/starter changes remain aligned where applicable.

🤖 Generated with Claude Code

#166 resolved this example's false isolation claim the wrong way round. The
comment in functions/page.mjs said the code "runs in the QuickJS/WASM sandbox
with no filesystem, network or host code" while no route declared
`sandbox: true`; #166 made the claim true by adding `sandbox: true` to all
three routes. The code was right and the comment was wrong, not the reverse.

docs/AI-AUTHORING.md is explicit: "Do not add `sandbox: true` reflexively to
every route 'for safety' — it costs the route the worker-pool capacity ceiling
and the ability to use `fetch`, Node builtins, the filesystem or npm packages,
for isolation most routes do not need." It then lists the three cases that do
warrant it: unreviewed code, a secret whose blast radius matters, or logic
complex enough that limiting a bug's reach is the margin wanted.

This example meets none of them. `page` is seven lines of reviewed first-party
code whose whole body is `new Response(args.body)`, with literal arguments from
urlcode.yaml — the trusted default's own case. Shipping the flagship recipe
with a reflexive opt-in taught readers to cargo-cult `sandbox: true` and made
the example contradict the guidance page.

So the three declarations come out and the prose describes what actually runs.
"Guest execution"/"guest code" also becomes "project code" where it meant the
route's own handlers: under the trusted default those are in-process project
code, not a guest. docs/PRERENDER.md already described prerendering as
mode-agnostic, and the example now matches it: the README says a route
declaring `sandbox: true` prerenders the same way.

The `unbacked-isolation-claim` check added in #166 still does its job, and does
it in the right direction — it requires prose and YAML to agree, not that a
project be sandboxed. Verified both ways: the tree passes, and re-adding a
QuickJS claim to page.mjs fails the check naming that line.

Verified: npm run verify — 512 tests, 510 pass, 2 skipped, 0 fail. The recipe
runs end to end: 7 fixtures, 3 pages rendered, audit 12/12.

Co-Authored-By: Claude Opus 5 <[email protected]>
@jimhoyd
jimhoyd merged commit 5e8d6e0 into main Sep 19, 2026
10 checks passed
@jimhoyd
jimhoyd deleted the claude/prerender-trusted-default branch September 19, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant