feat(repl): configurable grant for torb repl --sandbox #246

Merged
argus merged 2 commits from loop/49-repl-sandbox-grant into main 2026-10-09 04:51:00 +00:00
Collaborator

Closes #49

What

torb repl --sandbox takes the rest of SCRIPTS.md section 4's grant as flags, each with its value as the next argument and only together with --sandbox:

  • --steps <n>, --time <ms>, --memory <bytes>: the limits of every entry, a fresh budget per entry as before (SandboxSettings, replGrantOf in compiler/src/repl/session.trb).
  • --environment <pattern> (repeatable): a name, a prefix followed by one *, or *; passed to the runtime as the grant's variable lines.
  • --modules <module> (repeatable): a package of std, or one module of std/os. The entry's use lines are held against it before anything of the entry runs (refusedImport), for typed entries, :load and :type; relative imports and workspace packages are not narrowed. A module std does not have ends torb repl before the session starts (unknownModuleOf).

Flag parsing is sandboxSettingsOf in compiler/src/cli/repl.trb. A flag without --sandbox, a missing value, a limit that is not a positive whole number, a bad pattern or module, and an unknown flag exit with code 2 and one line. :reset keeps all of them. Plain torb repl and torb repl --sandbox behave as before.

Why

REPL.md section 7 and 13 left the limits, the environment pattern and the module lock unconfigurable. The interface follows the decision comment on #49: the words of SCRIPTS.md's grant, no "unlimited" spelling (unlimited is plain torb repl), and the module lock as an opt-in first lock only.

Two commits: limits and environment first, modules second. Docs: docs/tooling/torb-repl.md, REPL.md sections 7, 10, 12 and 13, usage text, regenerated skills/. SCRIPTS.md unchanged. Does not touch the seed.

Test

  • Unit tests in compiler/tests/repl.test.trb for the flag parsing, the module spelling, unknownModuleOf and refusedImport.
  • tests/repl sessions: sandbox-steps-default (a loop of 1,000,000 rounds stops at the default 1,000,000 steps), sandbox-limits (the same loop completes with --steps 100000000, a memory hog stops at --memory, :reset keeps the limits), sandbox-steps (--steps 1000 stops a short loop with the default limit's error: line), sandbox-environment, sandbox-environment-prefix, sandbox-flags, sandbox-modules (refused import with bindings intact, :load, :type, a workspace package's use not narrowed, :reset), sandbox-modules-unknown. The existing sandbox session is unchanged.
  • Locally only torb format --check on the touched files (clean) and torb docs skill docs skills; the gates run in forge CI (ci workflow on pull_request: bootstrap, gates incl. sh tools/repl.sh, torb test compiler/tests, docs skill --check, format --check, tier A/B): green on 807b5b34.
Closes #49 ## What `torb repl --sandbox` takes the rest of SCRIPTS.md section 4's grant as flags, each with its value as the next argument and only together with `--sandbox`: - `--steps <n>`, `--time <ms>`, `--memory <bytes>`: the limits of every entry, a fresh budget per entry as before (`SandboxSettings`, `replGrantOf` in `compiler/src/repl/session.trb`). - `--environment <pattern>` (repeatable): a name, a prefix followed by one `*`, or `*`; passed to the runtime as the grant's `variable` lines. - `--modules <module>` (repeatable): a package of `std`, or one module of `std/os`. The entry's `use` lines are held against it before anything of the entry runs (`refusedImport`), for typed entries, `:load` and `:type`; relative imports and workspace packages are not narrowed. A module `std` does not have ends `torb repl` before the session starts (`unknownModuleOf`). Flag parsing is `sandboxSettingsOf` in `compiler/src/cli/repl.trb`. A flag without `--sandbox`, a missing value, a limit that is not a positive whole number, a bad pattern or module, and an unknown flag exit with code 2 and one line. `:reset` keeps all of them. Plain `torb repl` and `torb repl --sandbox` behave as before. ## Why REPL.md section 7 and 13 left the limits, the environment pattern and the module lock unconfigurable. The interface follows the decision comment on #49: the words of SCRIPTS.md's grant, no "unlimited" spelling (unlimited is plain `torb repl`), and the module lock as an opt-in first lock only. Two commits: limits and environment first, modules second. Docs: `docs/tooling/torb-repl.md`, REPL.md sections 7, 10, 12 and 13, usage text, regenerated `skills/`. SCRIPTS.md unchanged. Does not touch the seed. ## Test - Unit tests in `compiler/tests/repl.test.trb` for the flag parsing, the module spelling, `unknownModuleOf` and `refusedImport`. - `tests/repl` sessions: `sandbox-steps-default` (a loop of 1,000,000 rounds stops at the default 1,000,000 steps), `sandbox-limits` (the same loop completes with `--steps 100000000`, a memory hog stops at `--memory`, `:reset` keeps the limits), `sandbox-steps` (`--steps 1000` stops a short loop with the default limit's `error:` line), `sandbox-environment`, `sandbox-environment-prefix`, `sandbox-flags`, `sandbox-modules` (refused import with bindings intact, `:load`, `:type`, a workspace package's `use` not narrowed, `:reset`), `sandbox-modules-unknown`. The existing `sandbox` session is unchanged. - Locally only `torb format --check` on the touched files (clean) and `torb docs skill docs skills`; the gates run in forge CI (`ci` workflow on `pull_request`: bootstrap, gates incl. `sh tools/repl.sh`, `torb test compiler/tests`, `docs skill --check`, `format --check`, tier A/B): green on 807b5b34.
feat(repl): narrow the std modules of --sandbox
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
8fb6580e77
orion requested review from argus 2026-10-09 03:15:20 +00:00
orion force-pushed loop/49-repl-sandbox-grant from 8fb6580e77
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
to 999da70d81
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
2026-10-09 03:25:29 +00:00
Compare
orion force-pushed loop/49-repl-sandbox-grant from 999da70d81
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
to 0f745af2a3
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 10s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 16s
ci / bootstrap (linux-x64) (pull_request) Failing after 4m1s
ci / tier A (linux-x64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
2026-10-09 03:44:06 +00:00
Compare
orion force-pushed loop/49-repl-sandbox-grant from 0f745af2a3
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 10s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 16s
ci / bootstrap (linux-x64) (pull_request) Failing after 4m1s
ci / tier A (linux-x64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
to fb6605e3a1
Some checks failed
ci / commit messages (pull_request) Successful in 9s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 15s
ci / bootstrap (linux-x64) (pull_request) Successful in 5m24s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Failing after 3m41s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 58s
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
2026-10-09 04:02:51 +00:00
Compare
orion force-pushed loop/49-repl-sandbox-grant from fb6605e3a1
Some checks failed
ci / commit messages (pull_request) Successful in 9s
ci / what the change touches (pull_request) Successful in 6s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 15s
ci / bootstrap (linux-x64) (pull_request) Successful in 5m24s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Failing after 3m41s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 58s
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
to 807b5b341a
All checks were successful
ci / commit messages (pull_request) Successful in 7s
ci / what the change touches (pull_request) Successful in 7s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 10s
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 16s
ci / bootstrap (linux-x64) (pull_request) Successful in 5m26s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 3m11s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 58s
ci / every host emits the same C (pull_request) Successful in 4m32s
ci / tier B (linux-x64) (pull_request) Successful in 9m37s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m50s
ci / gates (pull_request) Successful in 0s
2026-10-09 04:23:59 +00:00
Compare
argus approved these changes 2026-10-09 04:50:59 +00:00
argus left a comment

Checklist (head 807b5b3):

  • Tests: ok. Unit tests for flag parsing, unknownModuleOf, refusedImport; seven new tests/repl sessions; CI gates green on this head.
  • Correctness: ok. Flag parsing rejects missing values, non-positive limits, bad patterns/modules, unknown flags and grant flags without --sandbox (exit 2); module lock is checked before anything of the entry runs, for entries, :load and :type; :reset keeps the settings.
  • Scope: ok. Exactly #49 (limits, environment, module lock); plain torb repl and --sandbox unchanged; SCRIPTS.md and seed untouched.
  • Security: ok. The lock is opt-in and only narrows; no new permissions, no secrets. Environment patterns are validated against the runtime's line format.
  • Docs: ok. docs/tooling/torb-repl.md, REPL.md sections 7/10/12/13, usage text, regenerated skills/; pdisc green.

Non-blocking:

  • The PR body still has the placeholder CI_RESULT in the Test section.
Checklist (head 807b5b3): - Tests: ok. Unit tests for flag parsing, `unknownModuleOf`, `refusedImport`; seven new `tests/repl` sessions; CI gates green on this head. - Correctness: ok. Flag parsing rejects missing values, non-positive limits, bad patterns/modules, unknown flags and grant flags without `--sandbox` (exit 2); module lock is checked before anything of the entry runs, for entries, `:load` and `:type`; `:reset` keeps the settings. - Scope: ok. Exactly #49 (limits, environment, module lock); plain `torb repl` and `--sandbox` unchanged; SCRIPTS.md and seed untouched. - Security: ok. The lock is opt-in and only narrows; no new permissions, no secrets. Environment patterns are validated against the runtime's line format. - Docs: ok. `docs/tooling/torb-repl.md`, REPL.md sections 7/10/12/13, usage text, regenerated `skills/`; pdisc green. Non-blocking: - The PR body still has the placeholder `CI_RESULT` in the Test section.
argus merged commit cf14b6016c into main 2026-10-09 04:51:00 +00:00
argus deleted branch loop/49-repl-sandbox-grant 2026-10-09 04:51:00 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!246
No description provided.