Skip to content

feat(box): add opt-in policy checks for native file operations on macOS - #112

Merged
kevin-orellana merged 5 commits into
strands-agents:mainfrom
kevin-orellana:keorel/native-filesystem-core
Oct 16, 2026
Merged

kevin-orellana merged 5 commits into
strands-agents:mainfrom
kevin-orellana:keorel/native-filesystem-core

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR targets main. The upstream branch feature/native-filesystem-core mirrors this PR for review of #113 and #114.
Keep that branch synchronized with this PR when core changes. After this PR merges, move both dependent PRs to main before merging them.

An agent or tool can open files directly without a Dogwood policy check. Box's sandbox restrictions still apply.

This new feature adds Dogwood checks to native file operations: open, create, remove, rename, and truncate.
It is available in experimental mode. Truncate means shorten a file.
It uses Box's existing policy engine and history.

Enable the native-filesystem-policy Cargo feature when building Box, then add this to box.toml:

[experimental-features]
native-filesystem-policy = true

The build needs the macOS 27 Software Development Kit (SDK) and Apple's Endpoint Security entitlement.
That entitlement permits Box to receive and answer kernel authorization requests.
Run it on macOS 27 or later. Standard Box releases do not include this feature yet.
See the build and signing guide.

Approval for the configuration change

Kevin Orellana explicitly approved the new experimental-features configuration key and saved-record format version 22 during development. He reconfirmed that approval on October 16, 2026.
This records author approval. Maintainer approval remains subject to PR review.
Without the feature, saved records remain at version 21. Enabling it uses version 22, which older binaries reject.

FAQ

Can I enable this through TOML alone?

Only with a compatible signed build. The Cargo feature includes the code. The TOML setting enables it.
An absent setting or false keeps it disabled.

What happens if my build or operating system cannot support it?

Box refuses to start the workload. It leaves the stored configuration unchanged.

Does this replace sandbox restrictions?

No. The sandbox still limits which paths the workload can access.
Dogwood adds policy decisions, including rules that depend on earlier events. Both checks must allow access.

Does it check every read and write?

No. A file descriptor is a process's handle to an open file.
Later access through that handle can occur without another policy check. This feature does not revoke existing handles or check every filesystem operation.

Does an allow decision prove that the file changed?

No. It means Box allowed the request, not that the operation completed.
The history records that uncertain result as indeterminate.
When Box denies a request, the program receives an operating-system error. Box logs explain the policy denial.

Does this change policy history or reuse earlier decisions?

History still persists on disk across restarts. Each intercepted request gets a fresh policy decision.
Reusing an earlier allow could miss a change in policy history. Repeated checks add processing and storage work.

What happens to child processes?

Box registers each workload before letting it run. Children retain its checks after creating another process or executing another program.
Normal shutdown terminates tracked children, including detached children. Enforcement after a sudden Box crash still needs validation.

Can I return to an older Box binary?

Enabled boxes use stored configuration version 22. Disabled boxes retain version 21.
Older binaries refuse versions they do not support.
Set the feature to false, then run once with the compatible build before returning to a version-21 binary.
That run retains policy history. Per-workload settings and version 23 belong to #113.

Why keep startup, file checks, and shutdown in one PR?

Box must track a workload before it runs and keep checking it until shutdown.
Startup, file checks, and shutdown must merge together.
Separate upstream PRs add per-workload settings and agent tests.

Related Issues

Split from #107. The unrelated socket shutdown test fix remains outside these three feature PRs.

Type of Change

New feature, available in experimental mode.

Testing

The branch includes current main and its macOS signing metadata. The signed build and receipt were refreshed after that merge.

On October 16, the revised signed build passed 16 native integration tests plus one bridge test target on macOS 27.0.1.
The receipt matches the current production code and relevant test sources.

Commands, results, and remaining limits
  • cargo test --manifest-path test-native-filesystem/Cargo.toml --locked -- --test-threads=1, with STRANDS_BOX_SIGNED_TEST_BINARY set: 17 tests passed.
  • Bridge target: nine C cases cover queue overflow, expired deadlines, shutdown errors, and signed device identifiers.
  • cargo test --release --locked -p strands-box --all-features --bin strands-box macos_enforcement: 16 passed.
  • cargo test --release --locked -p strands-box --all-features --bin strands-box record::config::: 133 passed.
  • Startup tests: three passed with the feature and three without it.
  • cargo test --release --locked -p strands-box-containment --all-features launch_gate: one passed.
  • Receipt tests: seven passed. Native test package Clippy passed with all targets, all features, and -D warnings.
  • cargo fmt --all and standalone package formatting passed. Changed Box packages passed Clippy with the existing CI allowances.

The bridge tests substitute operating-system responses. They do not prove real kernel behavior under overload or process failure.
A negative-device regression test fails against the previous bridge and passes after the conversion fix.
A local callback probe observed 2,048 events from 16 children, with at most one callback active. This does not establish a universal API guarantee.
Remaining kernel tests and explicit descendants-client guarantee confirmation are tracked in #117.

The full workspace test suite and live model runs were not repeated. Earlier testing found an intermittent catalog-scaling timing failure.
Local Linux cross-compilation stopped in the ring dependency because aarch64-linux-gnu-gcc is unavailable. Linux CI remains necessary.
CI now also runs for PRs targeting feature/native-filesystem-core. Signed runs remain manual. CI checks the receipt's source hashes.

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

Formatting passed. The exact workspace Clippy command ran and failed on existing warnings, including chunks_exact_to_as_chunks in containment and vendored Shell warnings.
The containment failure also reproduces at base commit bd85785. The flagged Shell source is unchanged from that base.
The checkbox remains unchecked. Changed Box packages pass with the repository CI workflow's existing lint allowances.

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 under the repository lint configuration

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

…acOS

## Problem

Direct filesystem calls inside contained workloads bypass Dogwood policy. Filesystem reach grants cannot apply history-based rules to these calls.

## Solution

This adds global, explicit native filesystem policy selection on macOS. Selected open, create, unlink, rename, and truncate requests use the existing policy engine and durable history. Containment remains a separate restriction.

Enable the Cargo feature `native-filesystem-policy`, then set:

```toml
[experimental-features]
native-filesystem-policy = true
```

The feature requires macOS 27, its SDK, and a signed executable with Apple's Endpoint Security entitlement. Standard release artifacts exclude it. Missing support refuses startup before workload launch or record changes.

The trusted launcher waits until Box registers the workload's process identity. Trusted bootstrap reads stay outside workload policy. Descendants remain tracked across forks and executable changes. Shutdown terminates tracked descendants and bounds callback draining.

Disabled records retain version 21. Enabled records require version 22. Older binaries reject unsupported records. Disable the feature using a compatible build before returning to a version-21 binary.

This is the core part of strands-agents#107. Per-workload selection and real-agent workloads are separate dependent drafts. The unrelated socket shutdown test fix remains outside these three feature changes.

The adapter, trusted launch path, startup refusal, lifecycle cleanup, and signed tests stay together because they establish one enforcement boundary. Splitting these pieces would expose an incomplete safety contract.

Limits remain explicit: already-open descriptors and mapped memory are not checked on every read or write. Kernel denials expose an operating-system error; structured details appear in Box diagnostics. This adds no asynchronous history writes or durability option.

## Tests

Fresh macOS 27 validation passed: 13 signed integration tests, 16 adapter tests, 133 configuration tests, 11 native unit tests, three startup tests, one launcher handshake test, and 11 policy path tests. The receipt verifier's three tests passed.

`trusted_launcher_reads_are_not_workload_requests` fails against the old defective signed binary and passes against this build. `direct_open_truncate_and_grandchild_obey_dogwood` covers direct and descendant denial. `native_history_changes_the_next_decision_without_a_cached_allow` covers history-sensitive decisions.

Formatting and clippy passed for the changed Rust packages and standalone signed test package. Clippy used the repository's established allowances.

The checked-in receipt records this candidate's full signed suite and source hashes. Continuous integration checks receipt freshness; it does not run Apple's signed enforcement tests.

The full workspace suite was not rerun for this split. Earlier strands-agents#107 testing found an intermittent catalog-scaling timing failure. This PR does not claim that the full suite is green. Linux and older macOS runtime tests were not rerun locally.
@kevin-orellana kevin-orellana changed the title feat(box): add experimental native filesystem policy enforcement on macOS feat(box): add opt-in policy checks for native file operations on macOS Oct 15, 2026
@kevin-orellana
kevin-orellana marked this pull request as ready for review October 15, 2026 06:29
@github-actions

Copy link
Copy Markdown

Issue: The security-critical fail-closed paths in the bridge — the queued >= 1024 overflow deny (bridge.c) and the deadline-miss / ES_DEADLINE_MISS_MODE_FAIL_CLOSED behavior — have no automated coverage, and the signed integration suite cannot run in CI. The PR description itself flags queue-overload, missed-deadline, and shutdown-error tests as "remain necessary before production use."

Suggestion: This is acceptable for an experimental, feature-gated path, but please file a tracking issue (or reference #113/#114) for these deny-path tests and gate any promotion out of experimental on them, since a silent regression here would fail open.

Comment thread crates/box/src/record/config/mod.rs Resolved
@github-actions

Copy link
Copy Markdown

Issue: The repository's stated pre-push gate (README/just check) is cargo clippy --workspace --all-targets --all-features -- -D warnings, but the checklist item for it is unchecked and the description notes it was not run for this revision. Since the native-filesystem-policy feature now participates in --all-features, the full gate is exactly the one that exercises the new C-bridge build and Rust adapter together.

Suggestion: Run the workspace all-features clippy on macOS (where the bridge compiles) and confirm it is clean before merge, so the new code is covered by the same lint bar as the rest of the workspace.

@github-actions

Copy link
Copy Markdown

Review Summary

Assessment: Comment

Well-engineered, carefully cfg-gated feature with thorough unit/config tests, a sound fail-closed design (double identity verify(), ES_DEADLINE_MISS_MODE_FAIL_CLOSED, the launch-gate handshake), and clear documentation. My one blocking concern is process-level: this touches surfaces that AGENTS.md declares frozen, so it needs explicit maintainer sign-off and the API-review label before merge.

Review themes
  • Interface freeze (blocking): New 9th box.toml top-level key and RECORD_VERSION 22 are frozen surfaces requiring explicit approval; the PR lacks the api/needs-review label and box/AGENTS.md's stated contract is now stale. See inline comment on config/mod.rs.
  • Concurrency (please confirm): Non-atomic sequence/delivered bookkeeping inside the ES handler block — correct only if the handler is invoked serially. See inline comment on bridge.c.
  • Test gaps: Security-relevant deny paths (queue overflow, deadline miss) and the signed suite are not covered by CI; acceptable while experimental if tracked.
  • CI gate: Workspace --all-features clippy was not run this revision.
  • Minor: dev/ino width asymmetry in the bridge; add a comment or match widths.

The split rationale (startup + file checks + shutdown as one atomic unit, with #113/#114 deferred) is reasonable despite the overall size. Nice work on the enforcement model and its documentation.

Comment thread crates/box/src/run/contain/supervise.rs Resolved

@ferdingler ferdingler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great overall! Left a minor comment about improving the launch protocol so that supervise.rs owns the entire set of registration steps rather than making the call sites own some of them.

@github-actions

Copy link
Copy Markdown

Re-review Summary (updated)

Assessment: Comment — only the governance gate remains.

The author has addressed every code-level item from my earlier review, verified against the latest revision:

Item Status
dev/ino width asymmetry in bridge.c ✅ Fixed — all four st_dev casts now uint64_t, with negative-value test coverage
Launch-seam consolidation (ferdingler) ✅ Done — spawn_registered() owns the full per-workload protocol
ES handler data-race / serial-delivery assumption ✅ Reasonably dispositioned — SDK citation + signed probe, tracked in #117
Untested fail-closed deny paths (queue overflow, deadline miss, crash, shutdown) ✅ Tracked in #117 as a release gate
AGENTS.md frozen-surface contract (nine keys) ✅ Updated in both files to match the code

Remaining blocker (not resolvable by the author): the frozen-surface expansion — the 9th box.toml top-level key and RECORD_VERSION 22 — still needs explicit maintainer sign-off per AGENTS.md. The author correctly recorded their own approval, declined to self-grant maintainer approval, and didn't invent a label. That's the right posture; it just means a maintainer must make the call. @ferdingler, this is the one item left for your explicit approval.

Nice turnaround on the fixes, and #117 is a thorough release-gating checklist for the experimental surface.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

The review fixes are pushed. The description records the exact tests and current limitations.

In response to the missing failure tests, the bridge now has controlled-response tests for overflow, expired deadlines, and shutdown errors. Real kernel overload, process failure, and API-guarantee confirmation remain tracked in #117. These remain requirements before proposing standard release support.

I ran the requested workspace Clippy command. It fails on existing containment and vendored Shell warnings. The containment warning reproduces at base bd85785, and the affected Shell files are unchanged. Changed Box packages pass with the repository CI workflow's existing allowances. The strict checkbox stays unchecked.

The configuration approval note records author approval, not maintainer approval. The repository does not define the suggested api/needs-review label. Maintainer review remains necessary.

The CI trigger now includes the review staging branch. The main merge also preserves the new embedded signing metadata from #109 alongside native bridge compilation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants