Skip to content

feat(box): expose the interpreter alias names and a read-grant check to library callers - #242

Merged
notowen333 merged 1 commit into
strands-agents:mainfrom
notowen333:feat/expose-grant-and-alias-checks
Oct 30, 2026
Merged

notowen333 merged 1 commit into
strands-agents:mainfrom
notowen333:feat/expose-grant-and-alias-checks

Conversation

@notowen333

@notowen333 notowen333 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

A library caller that writes box.toml has no way to ask Box two questions before a run: which program names a box keeps for its own interpreters, and which paths a box refuses in a grant. Without them, the caller keeps its own copy of each list, and each copy can differ from Box. This change exposes Box's own answer to library callers.

  • strands_box::INTERPRETER_ALIASES: the five names the alias image takes (zsh, bash, sh, python3, python). It is built from SHELL_ALIAS_NAMES and PYTHON_ALIAS_NAMES, and a compile-time assertion fails the build when either list grows. Box's own MCP program check now reads this constant, so the public list and the check are one list.
  • strands_box::check_read_grant(path) -> Result<bool, GrantRefused>: judges a read grant through entry_grant, the function that judges a read entry in box.toml, with the canonical operator home. Ok(true) means the path is in a credential store.

Why item 2 is a function and not the path list. A path list does not carry the decision:

  • Each row of forbidden-paths.json has a rule. An exact row (/, /usr, /var/db/SystemKey) refuses a grant on that path and allows a path inside it. An overlap row refuses a grant at, under, or above it. A list of anchors loses this, so a caller has to restate each rule.
  • entry_grant refuses more than the rows: an absent path, a link, and a spelling that is not canonical (/tmp against /private/tmp). A caller with only the list accepts these, and box run then refuses them.
  • A credential store (~/.ssh, ~/.aws) is not refused when a grant names it. Box grants it and announces it at startup. The bool tells the caller, so a caller that wants a stricter rule takes it from Box's answer.
  • A row added to forbidden-paths.json reaches every caller with no change in the caller.

This follows check_policy: Box decides, and the caller asks.

Interface change. Two additions to the strands_box library (INTERPRETER_ALIASES, check_read_grant and its error GrantRefused). Nothing breaks. The operator approved this shape before the code was written. No CLI verb, box.toml key, or containment facade changes.

Deferred. crates/box/AGENTS.md still states that the crate has no lib.rs. That is false since #116, and it is a rewrite of that section, not of this change.

Related Issues

None.

Type of Change

New feature

Testing

  • tests/library_grant_check.rs: a system tree and / are refused, an ordinary directory passes with no credential store, an absent path is refused, and a link and a dotted spelling are refused.

  • tests/library_grant_check_credential_store.rs: a path in a credential store passes with Ok(true). It is its own test binary, because it sets HOME.

  • a_program_that_collides_with_an_interpreter_alias_is_refused now iterates INTERPRETER_ALIASES.

  • cargo fmt --all --check, just clippy, and cargo test -p strands-box --all-features (1019 passed, 0 failed).

  • Not run locally: the workspace-wide just check, and Linux. Reviewed with one /code-review round; feature-critic was not run.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)

  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…to library callers

## Problem

A library caller such as `boxy` keeps two lists of its own to refuse an MCP server before it
writes `box.toml`: the program names a box keeps for its interpreters, and the paths a box
refuses in a grant. Each copy can differ from Box. The path copy already differs: it treats every
row as `overlap`, it holds 19 of the 58 rows of `forbidden-paths.json`, and it refuses a path in a
credential store, which a box grants when a grant names it.

## Solution

- `strands_box::INTERPRETER_ALIASES` holds the five names that the alias image takes (`zsh`,
  `bash`, `sh`, `python3`, `python`). It is built from `SHELL_ALIAS_NAMES` and
  `PYTHON_ALIAS_NAMES`, and a compile-time assertion fails the build when either list grows. The
  MCP program check in `record::config::mcp` now reads this constant.
- `strands_box::check_read_grant(path) -> Result<bool, GrantRefused>` judges a read grant through
  `entry_grant`, the function that judges a `read` entry in `box.toml`, with the canonical operator
  home. It refuses an absent path, a link, a spelling that is not canonical, and a path under a
  floor. `Ok(true)` means the path is in a credential store. `GrantRefused` wraps `BoxError`, as
  `CheckFailed` does.
- The check is a function and not the path list, because each row of `forbidden-paths.json`
  carries a rule (`exact` or `overlap`) and a class, and `entry_grant` refuses more than the rows.
- `docs/design/containment.md` and `docs/design/binaries.md` state the two additions.

## Tests

- `tests/library_grant_check.rs`: `a_read_grant_on_a_system_tree_or_the_whole_filesystem_is_refused`,
  `a_read_grant_on_an_ordinary_directory_passes_and_names_no_credential_store`,
  `a_read_grant_on_a_path_that_is_not_there_is_refused`,
  `a_read_grant_through_a_link_or_a_spelling_that_is_not_canonical_is_refused`.
- `tests/library_grant_check_credential_store.rs`: `a_read_grant_in_a_credential_store_passes_and_says_so`,
  in its own binary, because it sets `HOME`.
- `record::config::mcp` `a_program_that_collides_with_an_interpreter_alias_is_refused` now iterates
  `INTERPRETER_ALIASES` and asserts its five names.
- Ran `cargo fmt --all --check`, `just clippy`, and `cargo test -p strands-box --all-features`
  (1019 passed, 0 failed). Not run: the workspace-wide `just check`, and Linux locally.
@notowen333
notowen333 marked this pull request as ready for review October 30, 2026 18:26
@notowen333
notowen333 enabled auto-merge (squash) October 30, 2026 18:33
@notowen333
notowen333 merged commit 7c12900 into strands-agents:main Oct 30, 2026
22 of 30 checks passed
Comment thread crates/box/src/lib.rs

/// Check a read grant on the absolute `path` as a box checks a `read` entry, and return whether it
/// lies in a credential store, which a box grants only when a grant names it, and announces.
pub fn check_read_grant(path: &Path) -> Result<bool, GrantRefused> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important (blocks the merge, because it contradicts the stated purpose): check_read_grant returns Ok for a read grant that box run refuses: a grant that encloses box_dir or lies inside it.

Example (I ran this on Linux at fb451c5): I made <tmp>/project and wrote a box.toml with box_dir = "<tmp>/project/state" and [agent.filesystem] read = ["<tmp>/project"]. A box directory inside the project is a normal layout.

  • strands_box::check_read_grant("<tmp>/project") returns Ok(false).
  • strands-box run --config <tmp>/box.toml fails: containment config failed: grant is too broad to be authorized: <tmp>/project (the grant would expose private Box state).

After the first run creates state/, check_read_grant("<tmp>/project/state") also returns Ok(false), and the run refuses that path with "the grant would expose the Box's own directory".

The cause is that entry_grant is only half of what judges a read entry. Boundary::translate also passes every operator grant through GuardedBoxState::judge (require_private_state_absent and require_box_directory_absent), and judge_read_grant never calls it. This is the same class of gap the description uses to reject a path list: "A caller with only the list accepts these, and box run then refuses them." docs/design/containment.md also says the function judges the path "through the same function that judges a read entry". That is true for entry_grant only, not for the whole decision.

Suggestion: The narrowest fix in code is to take the box directory, check_read_grant(path: &Path, box_dir: &Path), and run require_private_state_absent and require_box_directory_absent on the resolved path in judge_read_grant. The caller writes box_dir into the same box.toml, so it already has the value. If the approved signature has to stay as it is, the doc comment and containment.md must say that the function does not judge box_dir, deny entries, or how entries interact. Also add a test for the enclosing-box_dir case either way.

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

INTERPRETER_ALIASES is correct. check_read_grant gives a different answer from box run for one common layout: a read grant that encloses box_dir, or lies inside it. I reproduced this on Linux. That breaks the promise in the description that the caller gets Box's own decision.

Review Categories
  • Correctness: judge_read_grant uses entry_grant, but it does not use the Box-state guard that Boundary::translate applies to every operator grant. Details and a fix are in the inline comment.
  • Documentation: The library section of README.md does not show the new items.
Checks that held
  • System trees and / are refused, the same as box run (/, /usr).
  • A link, a dotted spelling, a non-canonical spelling, an absent path, and a relative path are each refused, the same as box run.
  • ~/ entries in the style of docs/user/ expand against the canonical operator home, the same as judge_filesystem.
  • A path in a credential store returns Ok(true), and box run grants it and announces it.
  • INTERPRETER_ALIASES holds the same five names that strands-box-sock-alias sends to an interpreter. If either source list grows, the build fails. If either list shrinks, an index stops compiling.
  • The MCP program check now uses the public constant, so the check and the constant are one list.
  • GrantRefused keeps BoxError opaque. No new signature returns an authority object, a working directory, or a proxy port (crates/box/AGENTS.md).

Building the decision into a function, and not publishing the path list, is the right shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants