Skip to content

Make build-typescript sandbox-aware like prepareFunctionSnapshot - #148

Merged
jimhoyd merged 1 commit into
mainfrom
fix/typescript-authoring-trust-aware
Sep 19, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
fix/typescript-authoring-trust-aware

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #124.

buildTypeScriptProject (src/typescript-authoring.ts, used by urlcode build-typescript) applied the sandboxed guest's own import rules — relative imports only, no dynamic import()/bare specifiers/import.meta, the 128-module/1 MiB-per-module/4 MiB-total budget — to every function/middleware it transpiled, regardless of whether the route declared sandbox: true. Trusted (non-sandbox: true) routes get full Node access at serve time (bare/npm imports, dynamic import, no size ceiling), so this was a build-time compatibility ceiling stricter than what actually runs.

This gives buildTypeScriptProject the same per-route sandboxed/trusted branch src/policy.ts's prepareFunctionSnapshot already has:

  • A route whose YAML declares sandbox: true keeps today's exact restricted transpile and budget (relative-imports-only, size/module limits, the sandboxed guest parser/byte-limit revalidation before publication).
  • A trusted route is transpiled without those restrictions: bare/npm specifiers, dynamic import() and import.meta pass through unchanged (Node resolves them at serve time, not this build), relative imports of project .ts/.js/.mjs modules are still rewritten/recursed as before, and there is no module-count or total-size ceiling (per-file reads are still capped, generously, to bound authoring-time memory).
  • A module referenced by both a sandboxed and a trusted route now fails fast with a clear error instead of silently reusing whichever trust level visited it first.
  • The post-transpile validation step (collectFunctionSources against the emitted snapshot) now only runs for sandboxed routes, since that check is specifically the sandboxed guest's own parser/budget contract.

Still true in both modes: no application code is imported into the build process in a way that executes it, and there is no semantic type-checking — only syntax diagnostics.

Docs

docs/TYPESCRIPT-AUTHORING.md already flagged this as a known limitation; updated it to describe the sandbox-aware behavior (per-route rules, the trusted mode's lack of a budget, and that extension inference still doesn't happen in either mode).

Tests

  • Added a new test that builds a trusted route with a bare (node:crypto) and dynamic (import('./dep.ts')) import, confirms the emitted code and a live request succeed, then builds the identical source under sandbox: true and confirms it still fails.
  • Existing tests exercising the sandbox's restrictions (unsafe-import rejection, the 1 MiB oversized-source rejection, the 128-module budget) now declare sandbox: true, since trusted is the default and no longer carries those restrictions.

Verification

  • npm run typecheck — clean
  • npm run lint — clean
  • npm run verify (lint + typecheck + check + build + full test suite) — 491 passed, 2 skipped (pre-existing, unrelated TLS skip), 0 failed

🤖 Generated with Claude Code

https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr


Generated by Claude Code

buildTypeScriptProject applied the sandboxed guest's own import rules
(relative-imports-only, no dynamic import/bare specifiers/import.meta,
128-module/1MiB-per-module/4MiB-total limits) to every function/middleware
it transpiled, even for trusted (non-`sandbox: true`) routes, which get
full Node access at runtime. Give it the same per-route sandboxed/trusted
branch src/policy.ts's prepareFunctionSnapshot already has: a `sandbox: true`
route keeps today's restricted transpile and budget; a trusted route is
transpiled with bare/npm specifiers, dynamic import() and import.meta left
untouched (resolved by Node at serve time) and no module-count/size ceiling.
The post-transpile validation step now only runs the sandboxed guest's
parser/budget check (collectFunctionSources) against sandboxed routes.

Update docs/TYPESCRIPT-AUTHORING.md, which already flagged this as a known
gap, and add test coverage for a trusted route with a bare/dynamic import
that now builds successfully, alongside a `sandbox: true` route with the
same import that still correctly fails to build. Existing tests exercising
the sandbox's restrictions were updated to declare `sandbox: true` since
trusted is now the default and no longer carries those restrictions.

Fixes #124

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr
@jimhoyd
jimhoyd merged commit ac56622 into main Sep 19, 2026
10 checks passed
@jimhoyd
jimhoyd deleted the fix/typescript-authoring-trust-aware branch September 19, 2026 12:58
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.

build-typescript still enforces sandbox-only import rules for trusted routes

2 participants