Repository navigation
fix(sandbox): stop treating text arguments as paths in the bash check - #1872
Merged
Merged
Conversation
…h check gh -q/--jq filters, gh --title/--body, git commit -m messages and gh api endpoints are text the command never opens as a file, and /dev/null carries no data, so an allow-listed read-only command naming them runs without approval again instead of asking in headless runs.
3 tasks
inference-gateway-maintainer
Bot
marked this pull request as ready for review
November 15, 2026 23:29
inference-gateway-maintainer
Bot
requested a review
from a team
as a code owner
November 15, 2026 23:29
edenreich
reviewed
Nov 15, 2026
edenreich
reviewed
Nov 15, 2026
edenreich
reviewed
Nov 15, 2026
Co-authored-by: Eden Reich <[email protected]>
Drop the per-command text flag rules. They duplicated the regex allow-list and let real paths past the check. The default sandbox policy now allows reading /dev/null, so an allow-listed command naming it runs without approval while writes to it still ask.
…h check A read-only command cannot read what is not there, so a word naming no existing file passes the path check instead of asking: jq filters, commit messages and titles that start with a slash were text the check took for paths. The dot-glob rule now fires only for a component that can expand to . or .., a malformed pattern is the literal word bash passes along, and a pattern bash reads differently from Go, such as [!a] or [[:alpha:]], asks since its expansion cannot be enumerated.
bashSkipsHiddenMatch skipped every hidden match of a wildcard component, which only mirrors bash for a component without a leading dot: .??* does match .env in bash, so its matches must reach the denied check. The blanket rule that rejected every dot-leading glob used to hide this.
The hint for head ~/.aws/credentials needs the file to exist now that a missing path is text, so the test creates it under a temp HOME instead of reading the machine's.
…x on Linux A temp dir lives under /tmp on Linux, which the default policy allows, so the test now allows only its project dir.
edenreich
added a commit
that referenced
this pull request
Nov 16, 2026
Resolves #1874 Based on #1872. Docs follow-up: a `[DOCS]` ticket for the docs repository is drafted and will be filed separately. ## Summary The Bash sandbox was an approval decision only: the allow-list decides what runs without a prompt and the path check keeps an unattended command off paths its arguments name. Once a command runs, nothing confines it. In `auto` mode, or after approval, a write can land anywhere the CLI process can write. Every Bash command the allow-list runs unattended, which in `auto` mode is every command, now runs under an OS sandbox that lets it read and execute anything but write only under the writable allowed paths, the grants, the writable carve-outs, the temp dir and the build caches. A write elsewhere fails in the kernel and the tool result tells the model why. A command the user approved runs as approved, unconfined, so the approval flow for a path outside the sandbox keeps its meaning. The path check stays as the read guard, since the kernel cannot tell `gh` reading its own token from `head` reading it. ## Changes - `config/sandbox.go`: `filesystem.enforce` (default `true`). `false` turns the kernel wrapper off. - `internal/sandbox/enforce.go`: `WritePaths(cfg, mode)` lists what a Bash child may write: writable allowed entries and grants, the writable carve-outs (skills, plugins, runtime dirs, plans, insights, memory), the temp dir, the Go, cargo and npm caches, and `/dev`. Plan mode gives the project up for the scratchpad, as `ValidateWrite` does. - `internal/sandbox/paths.go`: the carve-out predicates now share list helpers with `WritePaths`. Behaviour unchanged. - `internal/sandbox/infrastructure/kernel*.go`: `Command(ctx, cfg, mode, command)` builds the confined `Child`, and `Child.Start` is the one call that goes through the package. Linux applies a Landlock ruleset on the thread that forks bash (read and execute everywhere, write under the listed paths, every right the kernel's ABI knows), so only the child inherits it and the process stays as it was. No re-exec, no hidden command, and it works under Docker's default seccomp profile. macOS runs `/usr/bin/sandbox-exec` with an allow-default profile that denies `file-write*` outside the listed paths, with each path in its written and symlink-resolved spelling since Seatbelt matches the resolved one. Other platforms run plain bash. `DeniedHint` names the policy when the output shows a refused write. - `internal/tools/bash.go`: `confines` decides per command - the allow-list runs it unattended, so the kernel wraps it, or somebody approved it, so it runs plain. A failed confined command gets the hint appended to its output. - Tests: `WritePaths` per mode, the `confines` decision per mode and allow-list outcome, the Seatbelt profile rendering and escaping, a Linux test that a confined child writes only under a listed directory while the parent keeps writing anywhere, and an e2e in auto mode that proves an outside `mkdir` is refused with the hint while an inside one lands. - Docs: configuration reference, tools reference, the sandbox context README and the AGENTS.md security note. ## Not covered - Windows has no kernel sandbox, so the path check stays the only guard there. - Denied patterns such as `*.env` are not kernel-enforced: Landlock is allow-only and cannot deny inside a granted tree. The path check and the file tools keep enforcing them for unattended commands. - A Linux kernel without Landlock runs the child unconfined with a debug log, as `enforce` promises best effort. A kernel that has Landlock but refuses the ruleset fails the command with a message naming `filesystem.enforce`. - A tool cache outside the listed ones (for example `~/.bun`) needs an `allowed` entry. ## Verification - `go test` for sandbox, infrastructure, config, cmd/sandboxexec, cmd/runtime and tools is green on macOS, with the tools tests running under Seatbelt. - `go vet` cross-compiled for Linux (`CGO_ENABLED=0`) and Windows is clean. - The new e2e passes on macOS and on the Linux CI runner. The Linux unit test also ran in Docker against a 7.0 kernel with the default seccomp profile. - `task precommit:run` is green. --------- Co-authored-by: inference-gateway-maintainer[bot] <246577062+inference-gateway-maintainer[bot]@users.noreply.github.com>
Contributor
|
🎉 This PR is included in version 0.262.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Resolves #1870
Summary
The bash auto-approval path check ran every word of an allow-listed command through the sandbox path rules, so text that merely looks like a path got the command blocked with
Blocked: Bash requires approval, fatal in headless CI runs where nobody can approve: jq filters (-q .files[].path), commit messages and titles starting with/,gh apiendpoints, and/dev/null. Three changes, each a rule rather than a per-command list:mkdir,ln) keep their write check, since their target does not exist yet by design..or..(.*,.?). A malformed pattern such as.files[].pathis literal text to bash and reaches the command as written. A pattern bash reads differently from the check ([!a],[[:alpha:]]) now asks, since its expansion cannot be enumerated. The old rule let[!a]*through on Go's reading of it./dev/nullis a read-only entry in the default sandbox policy, so reading it needs no approval while writing to it still asks.Changes
internal/sandbox/bash_paths.go:validateBashReadpasses a path that does not exist.globOutsideSandboxrejects bash-only bracket syntax, narrows the dot rule to components matching.or..(hiddenGlobReachesParent), and treats a malformed pattern as the literal word it already checked.config/sandbox.go:/dev/nullwithaccess: readinDefaultSandboxConfig.internal/sandbox/bash_paths_test.go: the fixture now holds the secret files the blocked cases name (.env.local,nested/.env.production,~/.aws/credentials), since a missing file is no longer a path. New auto-approved cases: unquoted jq filters, a/-prefixed commit message, agh pr createtitle with brackets, a nonexistent absolute path. New blocked cases:ls .?,ls .??*(matches.env),ls .[!e]*,ls .[[:alpha:]]*,git commit -m msg .env,gh pr create --body-file /etc/hosts,wc -c /dev/null /etc/hosts,mkdir /dev/null.docs/tools-reference.md,docs/configuration-reference.md: the rules and the new default.Not covered
~/.infer/sandbox.yamlthat sets its ownfilesystem.allowedlist replaces the default list and needs/dev/nulladded by hand:Verification
go test ./internal/sandbox/is green, including the new allowed and blocked cases.go vetcross-compiled for Linux and Windows is clean.task precommit:runis green.