Skip to content

Scope project env overlays in sandbox workers - #2171

Merged
kojiwakayama merged 1 commit into
mainfrom
fix/sandbox-env-overlay-scope
Jun 9, 2026
Merged

kojiwakayama merged 1 commit into
mainfrom
fix/sandbox-env-overlay-scope

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Summary

  • Scope per-request projectEnv overlays inside the worker script and restore prior env values after app/pages route execution
  • Add real ProjectWorker coverage for unknown request serialization and env overlay isolation across reused workers
  • Bump release metadata to 0.1.698

Verification

  • deno test --no-check --allow-all --unstable-worker-options src/security/sandbox/project-worker.test.ts
  • deno test --no-check --allow-all src/utils/version.test.ts
  • deno check src/security/sandbox/worker-script.ts src/security/sandbox/project-worker.test.ts src/utils/version-constant.ts src/utils/version.ts src/utils/version.test.ts
  • deno task verify:quick
  • pre-push hook: format, lint, typecheck, unit tests (2011 passed, 0 failed)

Refs #1989

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4cd39e6dd1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/security/sandbox/worker-script.ts Resolved
Long-lived project workers previously applied per-request projectEnv overlays directly to Deno.env without restoring prior values. That let one tenant request leave env values visible to later requests handled by the same worker. The worker script now scopes overlay keys through a snapshot/restore helper used by app and pages route execution, and real-worker tests cover unknown request errors plus env overlay isolation.

Constraint: Project workers are reused across requests, so projectEnv must be request-scoped even though Deno.env is process-like inside the worker.

Rejected: Creating a separate worker per request | too expensive and contrary to the pool design.

Confidence: high

Scope-risk: narrow

Directive: Do not write projectEnv directly to Deno.env in worker handlers without restoring it in a finally block.

Tested: deno test --no-check --allow-all --unstable-worker-options src/security/sandbox/project-worker.test.ts

Tested: deno test --no-check --allow-all src/utils/version.test.ts

Tested: deno check src/security/sandbox/worker-script.ts src/security/sandbox/project-worker.test.ts src/utils/version-constant.ts src/utils/version.ts src/utils/version.test.ts

Tested: deno task verify:quick
@kojiwakayama
kojiwakayama force-pushed the fix/sandbox-env-overlay-scope branch from 4cd39e6 to e4fc37e Compare June 9, 2026 08:23
@kojiwakayama
kojiwakayama merged commit 3972ab1 into main Jun 9, 2026
20 checks passed
@kojiwakayama
kojiwakayama deleted the fix/sandbox-env-overlay-scope branch June 9, 2026 08:35
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.

2 participants