Add an opt-in OS-level sandbox (`compile({ sandbox: true })`) that runs each
emitter in its own isolated child process with only the permissions the user
authorized in `tspconfig.yaml`. By default an emitter is granted no access to
any system API.
- Permission model: shared types, permission-set algebra (merge/intersect/
diff), and a manifest API so libraries/emitters declare needed capabilities
(`fs-read`, `fs-write`, `network`, `env`, `exec`).
- Config grants: `permissions` block in `tspconfig.yaml`, resolved into the
effective set (requested ∩ granted, plus the emitter's always-writable
output dir).
- Sandbox runtime: child-process spawner using Node's permission model
(`--allow-fs-read/write`, `--allow-child-process`), curated env, and a
privileged broker that re-validates each request.
- Per-emitter execution: `emitSandboxed` runs each `$onEmit` in a child that
recompiles to rebuild the live `Program`; diagnostics are serialized and
re-targeted against the parent's source files.
- Ungranted requests produce a `permission-not-granted` diagnostic with a
pasteable tspconfig snippet.
Tests: unit coverage for permission-set/resolve/host/node-args plus runtime
integration and end-to-end emit (denied / granted / plain) scenarios.
Summary
Introduces an opt-in OS-level sandbox for running TypeSpec emitters, where users authorize exactly which system capabilities each emitter may use. By default an emitter is granted no access to any system API.
Enabled via
compile({ sandbox: true }). Each emitter runs in its own isolated child process with only the permissions the user approved intspconfig.yaml.How it works
$lib:tspconfig.yaml:permission-not-granteddiagnostic with a pasteable tspconfig snippet.--allow-fs-read/write,--allow-child-process), a curated environment, and a privileged broker that re-validates every request. Each$onEmitruns in a child that recompiles to rebuild the liveProgram; emit diagnostics are serialized and re-targeted against the parent's source files.Permission categories
fs-read,fs-write,network,env,exec— covering both emitters and (in a later phase) libraries.Scope of this PR
emitSandboxed)--no-sandboxCLI escape hatch + default-rollout decision, security-model docsTests
Unit coverage for permission-set / resolve / permissioned-host / node-args, plus a runtime integration test and an end-to-end emit test (denied / granted / plain emitter). All 45 permissions tests pass.
Note
Draft — opening for early feedback on the design and the OS-isolation approach.
sandboxdefaults tofalse(opt-in), so existing behavior is unchanged.