Repository navigation
Make build-typescript sandbox-aware like prepareFunctionSnapshot - #148
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #124.
buildTypeScriptProject(src/typescript-authoring.ts, used byurlcode build-typescript) applied the sandboxed guest's own import rules — relative imports only, no dynamicimport()/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 declaredsandbox: 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
buildTypeScriptProjectthe same per-route sandboxed/trusted branchsrc/policy.ts'sprepareFunctionSnapshotalready has:sandbox: truekeeps today's exact restricted transpile and budget (relative-imports-only, size/module limits, the sandboxed guest parser/byte-limit revalidation before publication).import()andimport.metapass through unchanged (Node resolves them at serve time, not this build), relative imports of project.ts/.js/.mjsmodules 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).collectFunctionSourcesagainst 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.mdalready 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
node:crypto) and dynamic (import('./dep.ts')) import, confirms the emitted code and a live request succeed, then builds the identical source undersandbox: trueand confirms it still fails.sandbox: true, since trusted is the default and no longer carries those restrictions.Verification
npm run typecheck— cleannpm run lint— cleannpm 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