Repository navigation
refactor(sandbox): extract the sandbox into its own bounded context and sandbox.yaml - #1473
Conversation
The path and bash policy lived as methods on config.Config, next to the YAML schema. It now lives in internal/sandbox: the domain holds the denial contract, the process-wide grants and the SandboxAccess approval name, the root package applies the configured policy and carve-outs through ValidateRead, ValidateWrite and IsBashCommandAllowed, and the infrastructure package persists an always grant to the userspace config. config cannot import internal/sandbox back, so every caller moves to the new functions in the same change. Grants stay process-wide behind their RWMutex and never feed the system prompt, which keeps it byte-stable.
Adds the context README, lists sandbox in the context inventory and the canonical aliases, and points the security notes at the new package.
The allowed directories and protected paths leave config.yaml for .infer/sandbox.yaml, with the project file replacing the userspace one. The field is excluded from the main viper, so infer config set cannot reach the policy, and ValidateWrite refuses both sandbox.yaml locations whatever protected_paths says. The agent therefore cannot widen its own sandbox through the tools it runs. An always grant now persists into the userspace sandbox.yaml, and an empty INFER_TOOLS_SANDBOX_DIRECTORIES is ignored instead of lifting the restriction. infer init seeds the file with the defaults.
sandbox.yaml is now two lists. allowed holds the paths tools may use, each a string or a map with access read or write. denied holds the paths they never may, each a string or a map with on_violation block or approval. Denied wins over allowed, the first matching entry in each list wins, and a path outside allowed or a write into a read-only entry asks the user through the existing SandboxAccess approval. A grant records the exact path and access that was approved and only unlocks what approval could have, so a granted directory still respects denied.
…atch dir The default policy no longer denies .infer/ outright. It is a read-only allowed entry, so the agent can read its own configuration but every write asks the user. ~/.infer/tmp and /private/tmp join the allowed list. Narrower entries come first because the first match wins.
…yaml The policy now reads filesystem.allowed and filesystem.denied, so a later section such as networking can sit beside it without reshaping the file. The Go schema mirrors that with a FilesystemPolicy field on SandboxConfig.
A project .infer/sandbox.yaml is no longer loaded, so a checked-out repository cannot widen the sandbox of whoever opens it. The only policy file is ~/.infer/sandbox.yaml, which infer init seeds and the file tools refuse to write.
|
@infer can you review this PR ? is it read for merge? use /ponytail:ponytail-review /go /go-concurrency /clean-architecture /clean-code /domain-driven-design |
|
Model: Todos
Pull Request✅ Infer Result: SuccessThe review is complete. Here is my full assessment of PR #1473. Review: refactor(sandbox): extract the sandbox into its own bounded context and sandbox.yamlShort answer: this is a high-quality, well-sliced refactor and everything I ran is green, but I would not approve-as-is. There is one approval-scoping question worth deciding before merge, plus a few small follow-ups. What I verified
Lens verdicts
Findings1 (main): an "always" approval can silently unlock the agent's own control plane. Trace on the default policy: a write to 2: the legacy 3: 4: test names still speak the old API ( 5 (ponytail): Everything else - the sandbox.yaml format, defaults, round-trip marshal, userspace-only loading, init seeding, docs ( Model: Tokens: 2,617,787 in · 32,711 out · 2,650,498 total (23 requests) Tool calls: 44 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
|
@infer can you address all the review comments? use /ponytail:ponytail |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll five threads resolved and all work is pushed. Finalizing the todo list: All five review threads are addressed, resolved, and pushed. Final summary for the PR: All 5 review threads addressed - 3 commits pushed, threads resolved1. Config-dir grants can no longer widen the control plane (PRRT_kwDOPaypV86oUi38, main finding) -
2. Legacy
3. Relative
4. Test names speak the new API (PRRT_kwDOPaypV86oUi4M) -
5.
Verification: Model: Tokens: 6,824,615 in · 57,621 out · 6,882,236 total (58 requests) Tool calls: 84 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
Renames TestValidatePathInSandbox_* to TestValidateRead_*/TestValidateWrite_* and removes the write-only-in, read-only-out AccessNone constant per review.
sandbox.GrantFor falls back from the GrantDir handback to the exact denied path when that handback would sit inside the userspace or resolved config dir, and PersistGrant refuses any grant anchored inside a config dir so such grants stay session-only. An always-approval can no longer widen a future session's control plane.
…andbox dirs A legacy tools.sandbox block in config.yaml now logs a warning pointing at the userspace sandbox.yaml instead of dying silently, and bare relative INFER_TOOLS_SANDBOX_DIRECTORIES entries are anchored to the working directory via the exported sandbox.IsAnchored so they keep their old cwd-anchored meaning.
|
Warning was removed. |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll done. Let me close out the todo list. The follow-up refactoring request is filed and linked. No code changes were needed for this ask, so the working tree is clean and the PR's head is untouched. Done
The warning itself stays in place until that window, as you asked. Model: Tokens: 788,663 in · 18,874 out · 807,537 total (17 requests) Tool calls: 23 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…r access sandbox.yaml now loads over the defaults, so an empty file or one that only lists denied entries keeps the default allowed list instead of opening the whole filesystem. A file that fails to parse or validate stops infer from starting rather than falling back to the defaults. Sidecar files are saved through a temp file and a rename, so a worker that starts while another persists a grant never reads a torn policy. The config dirs move from a silent read-only allowed entry to a denied entry with on_violation approval, so tokens in channels.yaml, config.yaml or mcp.yaml are never read without asking. A blocking denied entry now wins over an approval entry whatever its position. A persisted read grant is appended so it can no longer shadow a write entry, and an approval granted for a denied entry stays session-only because denied would win over anything persisted. The legacy tools.sandbox warning is gone. The process-wide grant set and the filesystem lookups move out of the domain package into the sandbox package, DeniedError.Grant folds into GrantFor, and the dead ~/.infer/tmp and /private/tmp defaults are dropped since the carve-outs and symlink resolution already cover them.
|
@infer can you review this PR ? is it read for merge? use /ponytail:ponytail-review /go /go-concurrency /clean-architecture /clean-code /domain-driven-design |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll verification is complete - everything came back green. The last discrepancy is also resolved: commit Full review concluded, all verification green. Here is the complete review (this final message is what posts to the PR): Review of PR #1473 - sandbox bounded contextShort answer to "is it ready for merge?" - Yes. Once the two pending CI checks (e2e, test) go green, this PR is safe to merge. Everything below is evidence and the two non-blocking comments I left inline. Verification I ran tonight (all exit 0)
I also cross-checked the five commits: domain-driven-design - 9/10
clean-architecture - 9/10
clean-code - 9/10Names reveal intent throughout ( go (idiom) and go-concurrency - pass, no findings
ponytail-review (over-engineering only)The extraction is a net deletion, which is the best kind of PR: the policy vacates Notes on deliberate behavior (awareness, not defects)
The two inline findings below are optional polish - neither blocks the merge. Model: Tokens: 3,160,581 in · 31,207 out · 3,191,788 total (26 requests) Tool calls: 50 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…ve-outs The carve-out skip only matched the literal .infer and .infer/ rule. A user who wrote ./.infer/ or .infer/* in sandbox.yaml was asked before every skill, plan or plugin read inside it.
83f5071 to
b947692
Compare
|
🎉 This PR is included in version 0.222.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
The path and bash policy lived as methods on
config.Config, next to the YAML schema, and the policy itself lived inconfig.yaml. It now lives ininternal/sandbox, a bounded context with one chokepoint every tool and the agent go through. The policy lives in its ownsandbox.yamlunder afilesystemsection with two lists.sandbox.yaml
/abs,~/x,.,./x) or patterns matched at any depth (dir/,*.glob,name).allowedor a write into a read-only entry goes through the existingSandboxAccessapproval. An emptyallowedlist is no boundary.channels.yaml,config.yamlandmcp.yamlcan hold tokens. Skills, plans, plugins, memory and runtime output stay open through the built-in carve-outs, whether the config-dir rule is spelled.infer/,./.infer/or.infer/*.inferfrom starting rather than falling back to a wider policy.denied. An "always" answer persists the grant into the userspacesandbox.yaml, a write grant first and a read grant last so it never shadows a write entry. A grant for a denied entry stays session-only.~/.infer/sandbox.yamlis read. A project.infer/sandbox.yamlis ignored, so a checked-out repository cannot widen the sandbox of whoever opens it. The field is excluded from the main viper, soinfer config setcannot reach the policy, andValidateWriterefuses the file whatever the lists say. The agent cannot widen its own sandbox through the tools it runs.INFER_TOOLS_SANDBOX_DIRECTORIES, the list the desktop and per-threadsandbox_directorieshand a worker, addsfilesystem.alloweddirectories.infer initseeds the file with the defaults. Atools.sandboxblock inconfig.yamlis ignored.Bounded context
internal/sandbox/domain: the policy value objects (Allowedwith anAccess,Deniedwith aViolation), the denial contract (DeniedError,ParseDenial) and theSandboxAccessapproval name as a constant.internal/sandbox:ValidateRead,ValidateWrite,AllowedDirectories,GrantFor, the process-wideGrantedset behind an RWMutex,IsBashCommandAllowed,BashAllowedCommands,BashCommandRejectionHint,IsUnrestricted, all free functions over*config.Config.internal/sandbox/infrastructure: persists a grant. No viper left ininternal/.configkeeps the schema (SandboxConfig,LoadSandbox,SaveSandbox), defaults,CanonicalPath,RealPathand the runtime directory names.Design notes
Shape informed by NVIDIA OpenShell's policy model: policy as its own reviewable file, explicit read/write access, an immutable base policy with an append-only grant set that never feeds the system prompt, one typed denial with its parser beside it, and a named human-in-the-loop proposal. Audit logging and kernel-level enforcement are out of scope and would slot in under
infrastructure/behind the same verbs.Verification
task precommit:runpasses with zero lint issues.go test ./...passes.go test -raceoninternal/sandbox,config,cmd/runtime, the agent and the tools is clean.infer initin a scratch HOME writes the two-listsandbox.yamlshown above.config.yaml, a projectsandbox.yamlignored, the userspace file unwritableDocs
sandbox.yamlon the docs site and drops thetools.sandboxkeys.