Skip to content

fix(policy): enforce shell working-directory restrictions - #296

Merged
kevin-orellana merged 10 commits into
mainfrom
feature/sbox24-cwd-policy
Nov 11, 2026
Merged

kevin-orellana merged 10 commits into
mainfrom
feature/sbox24-cwd-policy

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: A working-directory rule could allow a command it was meant to deny. Policy could compare /home/alex/project against ~/project, even though both identify the same directory. It could also check the caller's directory before launching a program in a different, configured tool workspace.

Solution: Box selects the program's launch directory before checking policy, then carries that absolute path into execution. If launch validation resolves a different directory, Box doesn't start the program and returns status 126. For ordinary shell policy decisions and new history, paths under the operator's home use ~/…. The caller's shell directory stays unchanged.

Trade-off: After upgrade, existing deny rules based on previous shell operations can silently stop denying commands if they match absolute paths under the operator's home. Box doesn't rewrite existing history records. Migration that preserves accumulated rule counts and an accurate upgrade warning remain Priority 1 follow-ups.

Description

Example: deny a launch from a protected directory

Assume the operator's home is /home/operator and /usr/bin/printf is an ordinary external program governed by Box's shell:spawn action. The following policy permits external-program launches except from ~/project. The context.input.cwd field identifies the launch directory.

permit(principal, action == Box::Action::"shell:spawn", resource);

@id("protected_directory")
forbid(principal, action == Box::Action::"shell:spawn", resource)
when { context.input.cwd == "~/project" };
Launch directory Before this fix After this fix
/home/operator/project Allowed: policy received /home/operator/project, so the forbid condition did not match. Denied: policy receives ~/project, so the forbid condition matches.
/home/operator/project-sibling Allowed: the forbid condition does not match. Allowed: policy receives ~/project-sibling, which does not match.

Box still launches permitted programs with an absolute directory path. Only the path spelling supplied to policy changes in this example. The exact-match condition covers ~/project itself; the regression test separately checks descendant matching with like "~/project/*".

This example covers the external-program policy decision. Other operations and tool-specific grammar actions need their own applicable permissions.

Check the directory used for execution

Strands Shell is the shell interpreter used by Box. For an external program launch, Box selects the tool and resolves the launch directory. Selection keeps the existing rules for tool workspaces, invoked aliases, longest command-prefix matching, and fallback to the agent specification.

Box checks policy once for the selected launch. Policy receives a reported copy of the directory: paths under the operator's home use ~/…; other paths stay absolute. If policy allows the command, Box stores the original absolute directory in a command permit, the approval object passed to execution.

The following diagram shows an ordinary program launch evaluated through Box's shell:spawn policy action. It assumes tool selection and directory resolution succeed:

%%{init: {"flowchart": {"rankSpacing": 30, "nodeSpacing": 35}}}%%
flowchart TB
    accTitle: Box checks the directory used to launch a program
    accDescr {
      Box selects the tool and absolute launch directory. Policy checks a reported copy: paths under the operator's home use a tilde; other paths remain absolute. A denial prevents execution. An approval creates a permit that retains the selected absolute directory, without converting it to the reported spelling. Strands Shell passes that directory to Box's launcher. After existing launch validation succeeds, Box compares the launch directory with the checked path. A match permits program startup in that directory; a mismatch prevents startup and returns status 126. The dashed arrow carries directory data, not permission to execute.
    }
    select["Box selects the tool<br/>and absolute launch directory"]
    policy["Box checks policy<br/>using the reported directory"]
    permit["Approval object retains<br/>the checked absolute directory"]
    validate["Box validates the launch,<br/>then compares directory paths"]
    run["Start the program<br/>in the checked directory"]
    denied["Do not execute<br/>the command"]
    mismatch["Do not start the program<br/>Return status 126"]

    select -->|"Reported copy: ~/… under home;<br/>absolute elsewhere"| policy
    policy -->|Allow| permit
    policy -->|Deny| denied
    select -. "Retain absolute directory" .-> permit
    permit -->|"Strands Shell passes the directory"| validate
    validate -->|"Paths match"| run
    validate -->|"Directory mismatch"| mismatch

    classDef refusal fill:#fff1f0,stroke:#b42318,color:#7a271a
    class denied,mismatch refusal
Loading

Figure 1. Policy checks the reported directory; execution uses the retained absolute directory. The dashed arrow carries directory data. It doesn't bypass the policy decision. Tool-specific grammar actions, local Model Context Protocol server startup, and other launch errors are outside this diagram's scope.

Strands Shell passes the permit's directory to Box's launcher. After the existing launch validation succeeds, Box compares the launch directory with the checked path. A mismatch prevents program startup and returns status 126. Each pipeline stage carries its own checked directory.

If tool selection or directory resolution fails, Box checks and retains the caller's directory, then follows the existing dispatch path. Missing commands retain status 127.

Carry approval into execution

The Strands Shell EffectPermit interface tracks an approved operation through completion. Its new default method, EffectPermit::spawn_working_directory() -> Option<&Path>, supplies the directory for program execution. It returns None for existing implementations, preserving use of the caller's directory.

Shell reads the method once. If the method returns a relative path, Shell doesn't execute the command and returns status 125. Box's permit wrapper preserves completion and cancellation accounting.

Keep policy decisions and history consistent

The change reuses the existing path-reporting and policy-loading checks for two ordinary shell policy actions: shell:exec for commands handled by Strands Shell, and shell:spawn for resolved external programs. Box records the same reported directory and request identifier for the policy decision and the command outcome.

Some tools map parsed commands to tool-specific policy actions through a grammar. Those actions retain absolute working-directory (cwd) values. If Box rejects a program's grammar binding, it records a refused shell:spawn request using the reported directory.

Local Model Context Protocol (MCP) server startup keeps its separate preparation path.

Compatibility and scope

Existing rules can include conditions based on previous operations. For ordinary shell actions, conditions that match absolute paths under the operator's home still load without a warning, but miss new home-relative events. Editing a rule starts it with empty state, even if the edited rule matches both spellings.

The contributor accepted this migration risk and approved the default permit method. The approval and the change to the vendored Strands Shell interface are recorded in crates/shell/UPSTREAM.md. Grammar-action spelling and historical migration remain outside this repair.

The launch check compares paths. It doesn't retain a directory's filesystem identity if another directory replaces it at the same path.

Configuration keys, stored-record formats, broker-protocol fields, dependencies, and lockfile entries remain unchanged.

Related Issues

No public issue is linked. Migration that preserves rule counts and upgrade warnings remain separate Priority 1 follow-ups.

Type of Change

Bug fix

Testing

November 10 merge

Revision a393234 incorporates main 8cfdddc, including configured-tool name selection, absolute MCP commands, per-tool history recovery, and support for incoming TCP connections. The conflict resolution retains both the configured executable and its checked launch directory.

Main added ingress to Box's ProcessSpec Rust struct but omitted the field from an existing command-selection test fixture. The first hosted build failed before workspace tests ran. This revision supplies an empty list because the fixture exposes no incoming connections. The correction changes only the test fixture.

The explicit-workspace regression now launches the tool by its full path and by its bare name, native-pwd. Both permitted launches must execute in the configured directory. Both protected launches must return status 126, and all four decision records must identify the selected directory and the applicable policy rule.

Check Result
Local Linux workspace before the ingress update (ec715e5) 5,316 passed, 18 ignored, zero failed across 163 targets with standard summaries. One nested result is excluded; the custom box_library target also passed.
Directory and integration coverage All 15 Box directory tests, seven policy directory tests, three Shell directory-permit tests, and five declared-program tests passed. The configured-tool, absolute-server-command, denied-startup, and restart-history integration cases also passed.
Deliberate-defect control Removing only the broker's configured-tool-map assignment made the extended test fail when the permitted bare command returned status 127. Restoring the candidate passed the same test.
Deterministic containment 131 passed, ten declared macOS-only exclusions, zero failures or errors. All 141 cases were accounted for.
Policy with default features 428 passed, six ignored, zero failed. Clippy passed with -D warnings and no allowances.
Build, lint, and documentation Workspace all-target/all-feature build, final formatting, Linux output audit, and workspace Clippy passed. Builds with default features disabled and strict policy documentation passed. All 27 site-manifest tests passed against main's manifest baseline.
Latest local validation (a393234) All 21 command-selection tests, 15 Box directory tests, and 17 tool-grammar tests passed, with zero failures, ignores, or reported fixture skips. Formatting, Box all-target/all-feature Clippy, and matching launcher builds also passed.
Hosted Linux and macOS workspace tests Both jobs passed. Each platform passed all 15 Box directory tests, including the full-path and bare-name tool regression, with zero failures, ignores, or reported fixture skips in that target.
Hosted deterministic containment Linux: 131 passed and ten platform exclusions. macOS: 129 passed and 12 platform exclusions. Both accounted for all 141 cases, reported zero failures or errors, and passed the full coverage gate.
Other hosted checks CI Gate, workspace lint, packaging, site manifest, cloud examples, and CodeQL all passed.
Automated review The final review of a393234 found no new issues. Its sandbox could not run the tool-launch tests; the hosted results above cover those tests.
Human review GitHub dismissed the previous revision's approvals after the source update. Renewed reviews are requested from the same reviewers, and squash auto-merge remains enabled.

GitHub tested merge commit 5590636, which combines PR head a393234 with main c8cdbd1. The shared-file changes from that main revision were reviewed; no working-directory enforcement issue was found.

The full local validation ran on Amazon Linux 2023 ARM64 against source tree 66ec942e92c32289e43811d29eb98d302c26169c (ec715e5). The final local checks cover tree 6b05579d37fc9af231297680b0fb6241e108717d, which adds the new main changes and the missing test initializer. The earlier full suite was not rerun locally for that one-field correction; hosted Linux and macOS checks cover the final revision. Workspace Clippy used the repository's seven existing lint allowances, listed with the earlier evidence. The full-workspace and Box-only all-feature builds enable different optional Shell bindings; the mutation and restored control used the same Box-only feature selection.

The earlier local namespace-mount startup failure is fixed by the incorporated main changes. Remaining local limits: the real credential daemon was unavailable, the executable-alias read assertion did not run, and the examples script found no runnable scripts. Alias write assertions ran. The live SDK tutorial and native macOS execution were not run locally. These checks do not establish history migration or release qualification.

Earlier validation on November 9, November 6, and November 4

November 9 revision

Head 0d06a52 passed hosted Linux and macOS validation. The local full-workspace run before the count correction failed for the reasons detailed below.

The merge incorporates main fbe415c. The conflict resolution preserves main's git fixture and this PR's assertions about the refused command's request identifier and directory.

A separate test correction updates main's stale syscall counts after #356 added statfs, the Linux system call that reports filesystem statistics. The test now expects 113 workload entries and 116 entries in the rule map used to construct the system-call filter. It preserves the remaining assertions and changes no production policy.

The automated review found no new behavior defect and one documentation inconsistency: the grammar-action table named the caller's shell directory instead of the program's selected launch directory. The final commit corrects that row. The final re-review confirms the correction and reports no new findings. All code, tests, and workflows are unchanged from the preceding reviewed revision.

Check Result
Hosted workspace tests at 0d06a52 Linux and macOS passed. Linux: 5,214 passed and 18 ignored. macOS: 4,831 passed and 17 ignored. Both had zero failures. Nested subprocess results are excluded from these totals.
Hosted deterministic integration at 0d06a52 Linux: 131 passed and 10 declared macOS-only skips. macOS: 129 passed and 12 declared Linux-only skips. Each platform recorded all 141 cases, with zero failures or errors and no test quarantine.
Other hosted checks at 0d06a52 CI Gate, lint, packaging, and site-manifest checks passed. Cloud-example tests and CodeQL analysis passed.
Final documentation correction All 27 site-manifest cases passed locally and on GitHub after the correction, with zero failures, ignored cases, or filtered cases. An independent documentation review confirmed the wording and link.
Conflict regression The resolved test executed and passed. Changing only its historical command predicate back to python made it fail at the intended history assertion; restoring git passed.
Syscall count correction Main's original test failed with 113 actual entries versus 112 expected. The corrected test executed and passed, with 483 other containment unit tests filtered out.
Local workspace before the count correction 4,828 passed, 386 failed, and 18 ignored across 162 targets with standard test summaries. The custom box_library target also failed. The failure analysis is described below.
Local policy with default features 418 passed, zero failed, and six ignored across 35 targets.
Local build, lint, and documentation Workspace all-target/all-feature build, formatting, workspace Clippy with repository lint allowances, default-policy Clippy, affected builds with default features disabled, and strict policy documentation passed.
Review Two independent local reviews found no merge-induced defect and confirmed the count correction. The final automated assessment reports no new findings and leaves the merge decision to maintainers. At this November 9 checkpoint, the scope and migration threads remained open. Two maintainers subsequently approved revision 0d06a52 on November 10.
Tested revisions and workspace Clippy allowances

The full local run tested merge tree 0eeb1156d221871d53aa9a3e9b6755b3e4a34f32. The count correction produced head e358c7952ac7e49517704028859f4c1e71f33e47, tree 3bfc7e534e19ba5bee2bc24a05127759602af3ca.

The preceding hosted CI run tested merge 2c1e11e57503e7cf9551ec6678e03d8082d52c0a, combining that head with main fbe415cbdfec284bf608a46f125ff8e437a99bda. Its tree exactly matches the code revision above. The automated reviewer also checked out e358c79.

The documentation correction is head 0d06a523fad5c33307e22ba6311d390725fd4d82, tree 7c56fcb19fb8455300d85fe108d6e37e74be1f13. Its only difference from e358c79 is one row in docs/user/policy/actions.md. Final hosted CI tested merge 0f87cf0146d37485612625a402da43f41f474ce9, combining 0d06a52 with main fbe415c. Its tree exactly matches the final head. The final site-manifest check used main's expected manifest and retirement files. The final automated re-review checked this documentation-only head and confirmed that the preceding code-test evidence still applies.

Workspace Clippy used -D warnings with the repository's allowances for clippy::too_many_arguments, clippy::only_used_in_recursion, clippy::await_holding_refcell_ref, clippy::explicit_auto_deref, clippy::chunks_exact_to_as_chunks, dead_code, and non_snake_case. Default-policy Clippy used -D warnings without these allowances.

November 9 validation limits

  • Local Linux startup: Main's mount-table parser rejects a Docker namespace entry on the development host, so Box stops before running a command. This accounts for 385 counted failures and the custom box_library failure. The original logs expose the error in 382 failures; isolated diagnostic runs expose it in the remaining three. The parser matches main byte for byte, and an exact-main parser control reproduces the failure. The other counted failure is the syscall test corrected in this update. The full local workspace suite was not repeated after that three-line correction; the corrected code passed hosted validation.
  • Local deterministic integration: One startup case recorded an error from the same mount-table check. The remaining 140 cases were not executed locally. The harness's coverage_gate=full field does not establish that those cases ran. The complete hosted case counts are reported above.
  • Hosted Linux omissions: The real credential-daemon test did not run because the daemon was unavailable. The executable-alias read assertion did not run; its write assertions ran.
  • Signed macOS enforcement: The native bridge check returned early because the runner lacked the macOS 27 software development kit (SDK). The full signed enforcement suite did not run, and the informational receipt-freshness check reported a stale receipt. The three startup tests and seven receipt-checker tests passed. A passing hosted job does not establish signed native enforcement coverage.
  • Other local limits: The Linux output audit reports a missing credential-daemon fixture and fails because Rust targets failed. The examples script built successfully but found no runnable example scripts. The live SDK tutorial and native macOS execution were not run locally. Builds with default features disabled emit existing inactive-code warnings; the recorded lint checks passed.
  • Evidence scope: Hosted results above apply to final head 0d06a52. The local checks retain the revision limits described above. These checks do not establish migration, performance, or release qualification.
Earlier validation on November 4 and November 6

November 6 revision

The November 6 conflict resolution is validated at head 68b527c2fd41a6900599715d24e3eb2cffc520f0. Local validation ran on Amazon Linux 2023 ARM64 with Linux support enabled and matching helper binaries.

Check Result
Local Linux workspace 5,130 passed, zero failed, and 18 ignored across 159 suites with test summaries. Nested subprocess summaries are excluded; the custom box_library executable also passed.
Hosted workspace tests Linux: 5,133 passed, zero failed, and 18 ignored. The macOS workspace also passed. All 46 retained feature cases executed and passed on both platforms.
Feature and integration regressions All 46 retained integration cases and the workspace-retarget unit test passed locally. The strengthened tests check reported directories and matching request identifiers, including commands that cannot bind to a tool-specific grammar action.
Deterministic integration Local and hosted Linux: 131 passed, with 10 declared macOS-only exclusions. Hosted macOS: 129 passed, with 12 declared Linux-only exclusions. Each run recorded all 141 expected cases, with zero failures or errors. No cases were excluded through test quarantine.
Build, lint, and documentation Workspace all-target/all-feature build, formatting, Clippy with repository allowances, default-policy tests and Clippy, affected builds with default features disabled, and strict policy documentation passed. All 27 site-manifest cases passed.
Hosted checks CI Gate, cloud-example checks, and CodeQL passed.
Review Independent review corrected the grammar-directory scope and found no remaining merge-induced defect. The automated re-review also found no new merge defects. Neither establishes maintainer approval.

Hosted validation includes newer main changes, which account for the difference between local and hosted workspace totals.

Tested revisions and lint allowances

The local tested and reviewed tree is e6c57d5d2c51a09fd8adbc3c78fad0f79f039270, with main parent 6bd1b2ff90f432dce430b0b05f5697df38237fa8.

Hosted validation tested merge 775b7b0d0e0559d8649720e04561e83386a9d8c3, which combines this PR head with main c8856a1aa60e8e024101fad06336ef52c7e9bedd.

Clippy used -D warnings with the repository's allowances: clippy::too_many_arguments, clippy::only_used_in_recursion, clippy::await_holding_refcell_ref, clippy::explicit_auto_deref, clippy::chunks_exact_to_as_chunks, dead_code, and non_snake_case.

November 6 validation limits

  • Signed macOS enforcement: The native macOS job didn't run the full signed enforcement suite. The native bridge check returned early because the runner lacked the macOS 27 software development kit (SDK). The informational receipt-freshness probe failed because its stored receipt was stale. Startup, adapter, configuration, and receipt-checker tests passed.
  • Linux omissions: The output audit passed with two known omissions. Credential-daemon cases and the executable-alias read assertion didn't run; the alias write assertions ran. Main's 20,000-submission request-identifier stress test remains explicitly ignored. This repair adds no ignored tests.
  • Examples and local macOS execution: The example entrypoint passed but found no scripted examples. The live SDK tutorial and current-revision macOS execution weren't run locally; macOS workspace evidence comes from hosted validation.
  • Optional documentation probe: The November 5 strict Box/Shell documentation probe failed on seven unchanged Shell links and wasn't repeated. The required strict policy documentation check passed.
  • Migration and release: History tests preserve existing observations; they don't demonstrate migration of an edited rule. These results don't establish performance or release qualification.

November 4 revision

Regression coverage and validation before conflict resolution

This evidence applies to f19d1b756c06e3d86806f47585c108d480934840 and its earlier baseline. It doesn't replace the current-revision results.

Validation ran on Amazon Linux 2023 ARM64 with Rust 1.98.1 and EXPERIMENTAL_LINUX_SUPPORT=TRUE.

Check Result
Full workspace 4,922 passed, zero failed, and 17 ignored across 151 standard-result targets; nested summaries aren't counted twice. The custom box_library harness also passed. This added 24 passing tests relative to the normalization-only revision.
Directory tests All 15 executed and passed on Linux and macOS, including both previous macOS native-program failures.
Deliberate-defect checks Nine broken variants compiled and failed the intended assertions. They exercised 23 new failure-detection tests; the missing-command compatibility control remained permitted.
Deterministic integration Linux: 131 passed and nine declared macOS-only exclusions. macOS: 128 passed and 12 declared Linux-only exclusions. Each platform accounted for all 140 cases with zero failures or errors. The local run excluded no cases through test quarantine.
Other checks Workspace build, formatting, Clippy with repository allowances, Box/Shell builds with default features disabled, and all 27 documentation-manifest cases passed. The examples script built successfully but found no scripted examples.

The regression cases cover tool workspaces, agent fallback, aliases, longest command-prefix selection, separate pipeline directories, concurrent calls, denied pipeline stages, relative permit rejection, and an unchanged caller directory. They also cover command-not-found behavior, completion, recording errors, abandonment, and cancellation before or during recording.

A launch test retargets a workspace symlink after policy admission and verifies refusal before the program writes its marker. Native-program fixtures use a workspace alias so macOS doesn't route the external pwd test through Shell's builtin.

The unchanged source passed cargo build --workspace --all-features --locked, cargo test --workspace --all-features --locked --no-fail-fast -- --nocapture, cargo fmt --all --check, and workspace Clippy. Box and Shell builds used --no-default-features --locked. Deterministic validation used test-integ/run.sh --locked; the examples check used scripts/test-all.sh box-examples. Source hashes and the primary deterministic executables remained unchanged through validation.

Hosted run 41797948089 tested merge 0ccdf71d656bbf2497a8471e5625f5f14596b1ce. All 17 PR file blobs matched f19d1b7; the four additional files came from main's integration-harness change in #249.

The 17 ignored tests and four existing early-return gaps were unchanged: the credential daemon, an alias helper beside a unit-test binary, removed cardinality-probe scaffolding, and the Linux alias-read assertion. The live SDK tutorial wasn't run. Three native macOS binary filters selected zero tests, and the full signed native suite didn't 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

AI assistance: Codex implemented this repair and performed code review and validation under the contributor's direction.


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

## Problem

A shell rule for ~/workspace missed commands whose working directory was
reported as an absolute path. A home-relative forbid could allow the
command it intended to deny.

## Solution

Use the existing approved-path helper for the cwd of shell:exec and
shell:spawn decisions and their request and outcome history. Retain the
actual execution directory and telemetry path. Extend the existing static
path diagnostics to cwd and document the policy spelling.

Existing history retains its original values. Changing a history rule
starts empty state. Counter-preserving migration is a Priority 1 follow-up;
this repair does not introduce a history migration or upgrade gate.

## Tests

an_exec_forbid_matches_exact_and_descendant_working_directories and
a_spawn_forbid_matches_exact_and_descendant_working_directories prove the
corrected matches and permitted sibling controls. The four configured
box_shell_cwd tests prove actual command refusal and unchanged execution
and telemetry paths. temporal_rules_distinguish_requests_and_outcomes_in_the_reported_working_directory
proves request/outcome consistency. reopened_history_preserves_old_cwd_spelling_and_records_new_spelling
proves existing predicates retain their observations, not rule migration.

All 14 new tests pass; 13 fail on the original baseline and one positive
loader control passes. Linux ARM64 workspace tests: 4,898 passed, zero
failed, 17 ignored. Deterministic integration: 131 passed, nine macOS-only
exclusions, zero failures or errors. Workspace build, formatting, and
Clippy with repository lint allowances passed. Post-rebase documentation
manifest: 27 passed. Native macOS and the SDK tutorial did not run locally;
known runtime fixture skips and ignored tests remain disclosed in the PR.
Comment thread crates/policy/src/adapters/shell.rs Resolved
Comment thread docs/user/policy.md Resolved
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The change fixes shell:exec and non-grammar shell:spawn. Two cases still give wrong results, and I confirmed both by running the code: grammar-bound programs still report an absolute cwd, and older temporal forbid rules on an absolute cwd now load silently and never fire. The change to a frozen attribute also needs recorded approval. See the inline comments.

Checks that held
  • MCP server start (host.rs::authorize_mcp_start) already reported cwd home-relative, so shell:spawn is now consistent across the shell and MCP paths.
  • With no anchored home, cwd keeps its original spelling. In the loader tests, an unanchored engine still accepts an absolute cwd.
  • Directories outside the home and sibling directories that share a prefix (/home/operator-sibling) stay absolute. strip_prefix compares whole path components.
  • Execution still uses the original directory, and the process.working_directory telemetry field stays absolute.
  • Static when literals on cwd under the home now refuse to load with the corrected ~/… spelling. That fails closed, and the docs describe it.

The tests covering exec, spawn, and recovery are thorough, and each restriction test includes a permitted sibling directory as a control.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Comment (merge decision deferred to a maintainer)

Re-review of bf04106. It changes only docs/user/policy.md and docs/user/policy/actions.md, and the code is identical to eec2a4d. Both earlier blocking threads are now documented, deliberately scoped limitations, and the PR description records the approval. What's left are scope decisions for a maintainer, not undisclosed defects. See the thread replies.

Checks that held on this head
  • The new doc claims match the code: grammar actions keep an absolute cwd, and absolute temporal cwd predicates load without a warning and miss new events.
  • when clauses that read cwd with no action scope, or under more than one action family, are refused by the existing family guard. I ran this; neither can get around the new home-spelling refusal.
  • An absolute cwd literal in a rule scoped only to shell:exec refuses to load and names ~/project, as the description says.
  • Deferring a new PolicyWarning variant is consistent with the frozen façade in crates/policy/AGENTS.md.

Select the configured launch directory before policy admission and carry
it through each spawn permit. Refuse directory drift before execution
while preserving command-not-found behavior and completion accounting.

Cover workspace precedence, aliases, pipelines, cancellation, and native
program dispatch. Record the approved Shell interface addition and retain
the accepted history-migration limits.
@kevin-orellana kevin-orellana changed the title fix(policy): report shell working directories relative to home fix(policy): enforce shell working-directory restrictions Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Assessment: Comment (merge decision deferred to a maintainer)

Re-review of f19d1b7. This commit chooses a tool's launch directory before the policy check, passes it to dispatch on the spawn permit (via the new EffectPermit::spawn_working_directory()), and refuses with 126 if the launch directory differs. I traced each case that reaches the new check and found nothing that gives a wrong result, so I'm adding no inline comments. The two open threads haven't changed: grammar actions still report an absolute cwd, now the selected launch directory, and the upgrade fail-open on older temporal rules is still documented and deferred.

Checks that held on this head
  • Tool with an explicit workspace: admission and Boundary::translate both canonicalize spec.workspace, so a caller's directory denial doesn't carry over to the tool.
  • No workspace, caller inside or outside the lists: caller_directory gives the same result at admission and at spawn. The spawn side gets the checked canonical directory, and a caller outside every list falls back to the agent workspace on both sides.
  • Selection or resolution fails at admission: the fallback checks the raw caller directory. The spawn then hits the same selection error and keeps its existing 126/127 status.
  • Every host launch goes through the checked directory: exec.rs builds HostSpawn in exactly one place, each pipeline stage gets its own permit's directory, and the script-interpreter path raises no shell:spawn.
  • Relative or non-UTF-8 directories: mediate.rs refuses a relative permit directory. ToolSelection::working_directory guarantees UTF-8, so the to_str().expect in ReachFloor can't panic.
  • Approval: approval for the new vendored Shell trait method is recorded in crates/shell/UPSTREAM.md and the PR description, as root AGENTS.md requires.
  • Tests run locally: strands-shell spawn_working_directory (3/3) and the strands-box lib tests for broker::shell and hosted (52/52) pass. box_shell_cwd.rs skipped here because the namespace launcher wasn't available, so its 15 cases still rely on the author's Linux run.

The PR is now about 2,000 changed lines and contains two fixes plus a vendored Shell interface addition. If a maintainer prefers, the launch-directory binding (f19d1b7) could merge as its own PR.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Assessment: Comment (merge decision deferred to a maintainer)

Re-review of 68b527c. Since f19d1b7 this head adds only two merges of main (d937cc4, 68b527c). I checked each conflict resolution with git show --remerge-diff and found nothing that gives a wrong result, so I'm adding no inline comments. The two earlier open threads are unchanged.

Merge resolutions and checks that held
  • hosted.rs tool_spawner: the resolution adopts main's Site refactor. The spawn closure is still main's body: approved-reach command substitution, protected_sources, native-egress telemetry, and LeafBox::run. The only addition is the checked-directory comparison. host.rs keeps both ToolSpawner and main's command_timeout.
  • Request identifiers (fix(policy): preserve request identifiers across history events #297): the policy adapter (crates/policy/src/adapters/shell.rs) passes both reported_cwd and request_id into Admitted::capture. The shell_cwd temporal test now also covers a correlated request/response pair joined on requestId with input.cwd: "~/project".
  • Tool grammars (feat(shell): connect the shell to tool grammars #327): a parsed grammar action gets the selected launch directory as an absolute cwd, which matches the merged docs. A spawn the grammar binding refuses is recorded as a shell:spawn request with the home-relative cwd, and the updated adapter test asserts input.cwd: "~/work".
  • MCP server start (into_server_start_handle): it goes through the same adapter, and its cwd spelling is unchanged from the previous head.
  • No leftovers: no conflict markers remain in the merged code or docs. UPSTREAM.md keeps both local-divergence sections.
  • Tests run locally:
    • strands-box-policy with shell-adapter: lib (233), path_spelling (21) and shell_cwd (7) pass.
    • strands-box lib broker:: and hosted::tests: 338 pass once the contain trampoline is built.
    • strands-shell spawn_working_directory: 3/3 pass.
    • box_shell_cwd.rs can't run here because the namespace launcher isn't available.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Suggestion (non-blocking): after the latest main merge, docs/user/policy/actions.md gives two different definitions of a grammar action's cwd.
Example: The tool-grammar field table that came in from main (line 260) still says cwd is "The Shell's working directory, as an absolute path." This PR's section at lines 173–176 says that for a Strands Shell launch, cwd is the selected launch directory. Those are different directories when a [tool.cargo] sets workspace, or when the Shell's directory is outside the tool's trees (caller_directory then falls back to the agent workspace). Take a Shell sitting in /tmp/scratch that runs cargo test: the program starts in the workspace, and the Tool::cargo::Action::"test"::response records the workspace as input.cwd. Someone following the table and the input.cwd pinning example in docs/user/tool-grammars.md would expect /tmp/scratch.
Suggestion: Change the line 260 row to something like "The program's launch directory, as an absolute path (see shell:spawn)". Then the page defines this field in one place.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Comment (merge decision deferred to a maintainer)

Re-review of e358c79. Since 68b527c there are two new commits: a merge of main at fbe415c (36bcfa2) and a seccomp test-count update (e358c79). Neither changes behaviour. I left one docs-consistency suggestion above.

Checks that held

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Assessment: Comment (I have no new findings; the merge decision is a maintainer's call)

Re-review of 0d06a52. Since e358c79 there is one docs-only commit, and it fixes the open suggestion about how a grammar action's cwd is defined. The field table in docs/user/policy/actions.md now calls it "the program's selected launch directory, as an absolute path" and links to #shell, an anchor that exists. That matches lines 173–176 of the same page.

Checks that held
  • One definition of grammar cwd: no other user or design doc still calls a grammar action's cwd "the Shell's working directory". The two places that still say it (actions.md:153 and shell.md:64) are the shell:exec tables, where it is correct. shell:spawn is covered by the paragraph that begins "On shell:spawn, cwd names the program's launch directory".
  • No code changes since my last review: the earlier test runs still apply.
  • Earlier note still stands: e358c79 (113 permitted syscalls) fixes a stale assertion that already fails on main, so it's worth calling out in the PR description.

zastrowm
zastrowm previously approved these changes Nov 10, 2026
Comment thread crates/box/src/run/broker/host.rs Resolved
priyasingh2111
priyasingh2111 previously approved these changes Nov 10, 2026
@github-actions

Copy link
Copy Markdown

Assessment: Comment (I have no new findings; the merge decision is a maintainer's call)

Re-review of ec715e5, a merge of main up to #388 into 0d06a52. I checked the conflict resolution with git show --remerge-diff. It keeps this PR's ToolSpawner and adds #388's host_programs to both ShellSpec and host(). In docs/user/shell.md, the [tool] table now has #388's command row and this PR's workspace row. No hunk from either side is lost.

Assumptions and rules checked that held
  • A bare declared name (fix(box): run a tool's own file for the bare name the agent types #388) gets the same directory check as a path spelling: when the agent types native-pwd, the decision's program_path is the declared file's canonical path (exec.rs host_program → declared_program). So ToolSelection::working_directory picks the same [tool] table at decision time and at spawn time. The new loop in an_explicit_tool_workspace_is_checked_before_the_tool_starts covers this for both permit and deny.
  • Decision time and spawn time read the same file name: the decision passes the bare program, and the spawn passes the absolute spelling. For bare names, path spellings and symlinked PATH entries, called.file_name() is the same on both sides, so the tie-break agrees.
  • The docs still have one definition of cwd: shell:exec keeps the Shell's working directory, and the shell:spawn and grammar actions name the launch directory. Nothing fix(box): run a tool's own file for the bare name the agent types #388 brought in contradicts this.
  • Tests: the strands-shell tests spawn_working_directory and declared_host_programs pass. The strands-box tests box_shell_cwd and tool_grammars print SKIPPED here because the namespace launcher is unavailable. Confirm they run in CI on a host where the launcher works.

@github-actions

Copy link
Copy Markdown

Assessment: Comment. I found nothing new; whether to merge is up to a maintainer.

Since ec715e5, the PR has one new commit, a393234. It merges main at 8cfdddc (#272, the ingress relay). Merging again with git show --remerge-diff shows the author changed one thing by hand: ingress: Vec::new() is now set in the ProcessSpec test fixture in crates/box/src/run/commands.rs. Every other file from #272 merged without edits.

Assumptions and rules checked that held
  • feat(ingress): ingress relay for agent tcp communication #272 doesn't change how a tool's start directory is chosen: ingress can only be set on [agent] ([[agent.ingress]], behind the experimental switch). So select_tool_with_commands, caller_directory, and the directory that shell:spawn checks still see the same [tool] specs.
  • The new field is filled in everywhere a spec is built: cargo test -p strands-box --no-run builds, so every ProcessSpec literal that feat(ingress): ingress relay for agent tcp communication #272 didn't touch has the field.
  • Tests: the unit tests in run::commands and run::broker::shell pass. I checked the run::hosted failures I saw: all of them come from strands-box-contain-trampoline not being built in this sandbox, not from this change. As before, every box_shell_cwd integration test that launches a tool skips itself here. Please confirm it passes in CI on a host where the namespace launcher works.

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.

4 participants