Skip to content

feat(box): add opt-in native filesystem policy interception on macOS - #107

Closed
kevin-orellana wants to merge 8 commits into
strands-agents:mainfrom
kevin-orellana:keorel/experimental-macos-filesystem-policy
Closed

kevin-orellana wants to merge 8 commits into
strands-agents:mainfrom
kevin-orellana:keorel/experimental-macos-filesystem-policy

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Superseded by three merged PRs: #112 adds the core macOS native file checks; #113 adds selection for each workload; #114 adds native-file and agent-denial workload tests. All three merged on October 16, 2026. This combined draft is closed and remains a historical reference. The unrelated socket-shutdown test fix was excluded from the feature split.

Description

Direct filesystem operations inside contained workloads currently bypass Dogwood. Containment grants alone cannot apply Dogwood temporal policy to those operations.

This experimental feature checks selected kernel filesystem open, create, unlink, rename, and truncate requests on macOS. It uses the existing policy engine and history. Containment restrictions still apply.

Activation requires a build with the native-filesystem-policy Cargo feature and this explicit selection:

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

Per-workload selection

The global experimental setting supplies the default. Optional overrides select native filesystem mediation independently for the agent, individual tools, and local Model Context Protocol (MCP) servers:

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

[agent]
native-filesystem-policy = true

[tool.cargo]
native-filesystem-policy = false

[mcp.files]
native-filesystem-policy = true

Only selection fields appear above. Existing tables still require their command and other settings. An absent process setting inherits the global default, not the agent override. Explicit enablement requires the global gate. Remote MCP entries reject this local-process setting.

The trusted launcher holds each workload until Box registers its mode against the kernel-observed process identity. Descendants inherit the mode across forks and executable changes. Broker-launched tools receive their selected table's mode. Undeclared executables allowed by the agent's execute grants retain the agent's mode.

Disabled workloads retain sandbox restrictions and shutdown tracking. Their native file operations bypass Dogwood evaluation and history recording. History-based rules cannot rely on observing those operations. Shell and network policy checks remain active. Disabled workloads can still incur kernel event-delivery and launcher overhead.

Leveraging MacOS Endpoint Security API

This feature on the Box Core binary requires macOS 27+, the macOS 27 SDK, and Apple's Endpoint Security entitlement. Endpoint Security lets a client decide selected operating system requests. Standard Box Core release artifacts exclude this experimental feature. An absent setting or false keeps it disabled, including in all-feature builds. Unavailable support refuses startup before workload launch or stored-record changes.

Without process overrides, disabled records use version 21 and enabled records use version 22. Explicit process overrides require version 23. Older binaries reject unsupported versions. Remove process overrides and disable the global setting with a compatible build before returning to a version-21 binary.

  • Box Core startup verifies subscriptions and settings for required event delivery.
  • Shutdown terminates tracked descendants, including detached children, and bounds callback draining.
  • The kernel-event-to-policy-engine adapter records the final kernel reply. The shutdown test separately fixes an intermittent harness failure: socket closure can precede the first read.

Ordinary workspace tests require no signing identity.

Callout: File descriptor handle allows for continued file access without policy engine mediation

Existing open file descriptors can carry later access without another open request. This experiment does not revoke descriptors or intercept every filesystem operation.

Rationale: Today, there is no readily available way to close or disable file descriptor access once it's been provided to a sandboxed process. We will declare this in our documentation.

FAQ

Does this check every file access?

No. It checks selected open, create, unlink, rename, and truncate requests. An already-open file descriptor can permit later access without another policy check. The feature does not revoke descriptors or intercept every filesystem operation.

Why add policy checks when containment already exists?

Containment restricts which paths a process can reach. Dogwood adds policy decisions, including rules that depend on prior events. Both restrictions apply. A policy permit cannot expand containment grants.

Can customers enable this through TOML alone?

Only when they already have a compatible, signed build. The build needs the native-filesystem-policy Cargo feature and Apple's Endpoint Security entitlement. Activation requires macOS 27+ and explicit selection in box.toml. Standard release artifacts exclude the experiment.

What happens when selected support is unavailable?

Box Core refuses startup before the workload runs or the stored record changes. It does not silently disable the selected checks.

Why disable authorization caching?

The adapter disables kernel authorization caching so intercepted requests receive fresh policy decisions. Repeated checks add work. Reusing an earlier decision could miss changes in policy history.

Does an allow record prove that the operation succeeded?

No. Accepted authorization replies produce indeterminate outcomes. These records confirm authorization, not the filesystem result.

Can customers downgrade immediately?

Configurations without process overrides use version 22 when enabled. Explicit overrides require version 23. Remove process overrides, set the global feature to false, and run once with a compatible build before using a version-21 binary. That run retains existing durable history.

Related Issues

No closing issue reference.

Type of Change

New feature, experimental.

Testing

Review fixes validated at 9a556f4

An explicitly disabled agent or tool no longer needs filesystem policy permissions during trusted launcher startup. The temporary bootstrap exemption ends before workload execution. Unknown processes remain mediated, and stale messages cannot overwrite a newer executable's tracking state.

  • The signed macOS 27 suite passed 17 tests, with none skipped or filtered. Both new restrictive-policy tests fail against the earlier signed binary and pass against this build.
  • Native adapter tests passed 16 tests. Native-related unit tests passed 11 tests, including preservation of the policy error source. Configuration tests passed 134 tests.
  • Workload evidence tests passed 31 tests. All 7 deliberately broken evidence checks were detected. Three independent bridge-state mutations were also detected.
  • Three receipt-validator tests passed. The final receipt matches all 425 covered source files, the signed binary, and the complete test log.
  • Formatting, the default-feature compile check, and lint passed. Workspace lint used the repository's existing allowances. Standalone native-test lint passed with unmodified -D warnings. The bridge compiled against SDK 26.5 and SDK 27.

Three independent reviewers found no remaining source blocker. Their checks covered runtime behavior, test strength, contracts, and code conventions.

The CI Gate now requires the native build, adapter and configuration tests, and signed-receipt freshness check. The signed kernel run remains manual on a trusted macOS 27 host. The receipt is an attestation; it is not an independent hosted signing pipeline. Covered source or workflow changes require a fresh build and signed run. An older hosted SDK compiles the unsupported-platform code; the signed macOS 27 suite exercises the active bridge.

See the signed-run receipt and validation instructions.

Live model workloads, the full workspace suite, and Linux runtime tests were not rerun for this fix. Earlier results and their limits remain below. This PR remains a draft.

Earlier validation and workload measurements

Native agent workload smoke tests

The explicitly selected test-workload/workload-native-filesystem case passed locally with Claude Code 2.1.299 and Codex CLI 0.162.1. Each agent passed 11 host checks: an allowed edit, one protected-edit attempt, an unchanged protected file, native Dogwood denial evidence, matching policy records, and continued work after denial. Claude used Read/Edit/Write; Codex used file-change tools without command execution.

The 29 verdict/configuration regression tests passed, including false-pass mutations and compatibility checks for existing launchers. The existing run-validity and two-run harness checks passed. The final adversarial review found no remaining source blocker. These regression tests now run in the existing verdict CI job; the live model tests remain explicitly selected and require a signed macOS 27 build. Current Linux CI remains pending.

The signed runtime remains 5769dc1; commit 05f3cae changes the workload harness, tests, CI, and documentation. The logs also contain denied agent setup operations: Claude local-socket creation and Codex skills-directory/rollout access. These file-edit tests do not validate every agent feature, rollout persistence, or structured policy errors delivered to the agent.

Run the native agent workloads.

Current per-workload validation on macOS 27.0.1 (26A434):

  • The final signed native suite passed 15 tests, with none skipped. independent_agent_and_tool_modes_survive_concurrent_forks_and_exec covers mixed selections. local_mcp_selection_is_independent_of_the_agent covers local servers. a_disabled_agent_retains_containment_and_does_not_record_native_history covers disabled history and retained filesystem grants.
  • The Box and containment all-target suites passed, with six ignored tests. The final fallback-inheritance assertion and launch acknowledgment/EOF test also passed.
  • The separate containment suite passed 121 checks, with eight platform skips and no failures or errors. Its product and helper hashes match the final build receipt.
  • Default-build startup tests passed 3 tests. Workspace all-target checking, formatting, and clippy passed. Clippy used the repository's existing vendored-code allowances. The native test package passed clippy with unmodified -D warnings.
  • The native bridge compiled against SDK 26.5 and SDK 27. The example build passed. No scripted examples remain, so the SDK tutorial did not run.
  • The adversarial reviewer found no remaining source blocker. An independent mutation test rejected an invalid launch acknowledgment. A separate signed probe verified selection inheritance through posix_spawn.

For 1,000 repeated reads of one 4 KiB file, median total command times across three rotating runs were 8.69 seconds with tool mediation, 1.00 second with only that tool disabled, and 0.82 seconds with interception globally disabled. The agent was disabled in all three modes, and the policy permitted every request. Each run used a fresh box and workspace. These times include startup and shutdown. Disabling the tool was about 8.7 times faster for this test, while kernel delivery and launcher setup still added overhead. This test does not establish a Cargo build speedup or isolate internal policy/database costs.

The signed test source hashes match the final source. Linux validation remains pending. This PR remains a draft; these macOS results do not establish Linux support or every shutdown-failure behavior.

Earlier validation before per-workload selection

Local host: macOS 27.0.1 (26A434). The signed executable came from the current source. Source hashes match the test receipt.

  • Signed native suite: 12 passed, none skipped. Includes detached descendants, filesystem mutations, temporal rules, and durable history across mode changes.
  • Containment suite against the current product: 121 passed, eight platform skips, no failures or errors.
  • Adapter unit tests: 16 passed. Each also failed independently with a relevant defect restored in a private review copy.
  • Socket shutdown regression: 50 repeated passes. Restoring the shutdown defect makes the test fail.
  • Startup refusal preserves the previous record: passed in default and native-capable unsigned builds. Removing preflight makes the record-preservation test fail.
  • Full workspace first run: 4,134 passed, one failed, 16 ignored. The new fixture opened a policy outside the shared helper. It now uses that helper; the invariant test passes. The full Box rerun recorded 940 passes, one timing failure, six ignored. The existing catalog-scaling test exceeded its 3× limit. Three isolated retries produced one failure and two passes. Its intermittent timing failure remains unresolved. The full suite is not green.
  • Workspace documentation tests: 13 passed, one ignored. Default policy tests: 244 passed, five ignored. Both policy documentation builds passed.
  • Workspace release build, default release build, formatting, and lint checks passed. Workspace clippy used the repository's vendored-code allowances. The default build retains an existing containment dead-code warning.
  • Bridge compilation passed with SDK 26.5 and SDK 27. The newer process-signaling function uses a weak import and an availability check. The example build passed. No scripted examples remain, so the SDK tutorial did not run.

Reproduce ordinary tests:

cargo test --release --workspace --all-targets --all-features --locked --no-fail-fast

Build and sign according to the native filesystem guide, then run:

STRANDS_BOX_SIGNED_TEST_BINARY=/absolute/path/KernelBox.app/Contents/MacOS/strands-box \
  cargo test --manifest-path test-native-filesystem/Cargo.toml --locked -- --nocapture
  • I ran the relevant suites (just check, or cargo test --workspace --all-features). Results and remaining platform gaps appear above.
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Formatting passed. Clippy passed with the repository's lint allowances, rather than the unmodified command above.

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.

…macOS

## Problem

Direct filesystem operations inside contained workloads do not reach Dogwood.
Containment grants cannot apply history-based policy to those operations.

## Solution

Add an optional macOS 27 monitor behind kernel-policy-integration.
Route covered opens and mutations through the existing policy engine.
Start monitoring before the broker accepts requests or the workload starts.
Add PathResolver::approve_host_entry for directory-entry operations.

Include the local memory-history, policy-timing, and interception controls used
for the performance experiment. These controls are not a supported Box setting.
The public resolver addition and benchmark controls remain review items.
No configuration key, record layout, wire protocol, or dependency pin changes.

## Tests

The signed macos_file_enforcement suite passed ten tests, including
 direct_open_truncate_and_grandchild_obey_dogwood,
 native_mutations_preserve_denied_paths, and
 native_history_changes_the_next_decision_without_a_cached_allow.
The run::macos_enforcement::tests suite passed ten event-mapping tests.
Six benchmark controls and two native history controls passed.
All 72 read invocations passed.

Cargo completed 0/3 durable builds, 2/3 memory builds, and 3/3 baseline builds.
Failed builds reported Box transport timeouts.
Memory-mode restart of an existing committed box remains unsupported.
Linux native interception and later reads through existing handles are not covered.

The required review found merge blockers in test-control isolation, the public
resolver decision, signed CI setup, and unbounded native test waits. Process-global
timing counters remain diagnostic only. These findings are disclosed in the draft.
Fresh release all-feature build and formatting passed. Broader release tests and
example gates are running; full workspace and cross-platform validation are incomplete.
@kevin-orellana kevin-orellana changed the title feat(box): add experimental native filesystem policy interception on macOS feat(box): add opt-in native filesystem policy interception on macOS Oct 14, 2026
Park the observer until the peer sees closure. Shutdown can precede reads, so
queued bytes are optional; closure, joined handlers and elapsed bounds remain required.
The fixed case passes 50 repeats and fails with shutdown ordering deliberately broken.
Track descendant identities through shutdown, check default event muting, bound
callback draining, and retain failed callback storage safely. Keep policy records
durable and publish final decisions after the kernel reply.

Use the native-filesystem-policy feature name consistently and refuse unsupported
activation before changing the stored record. Enumerate actual child IDs instead
of treating the process-list buffer estimate as a child count.

Weak-link the newer process signaling function and check its availability.
Add signed descendant/history coverage and reuse the shared policy test fixture.
@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

The structured-denial criterion in filesystem interception epic #43 depends on agent/tool integration. It cannot be satisfied by this PR's kernel interception path alone.

Apple's Endpoint Security response interfaces accept an authorization decision or allowed flags, plus a caching choice. They have no field for a custom error message. The native adapter returns that decision. A refused filesystem call reports an operating-system error code, such as EPERM; the caller's runtime supplies the standard text.

The agent-facing requirement remains valid: the agent should receive the action, deciding rule, and explanation. Delivering those details requires an integration that matches a Box denial to the exact failed tool call and supplies the structured explanation to the agent. Operator diagnostics or a separate event viewer do not satisfy that requirement.

I propose treating structured agent-denial delivery as a dependent integration task under first denial epic #9, linked from #43. This PR should document the current native error behavior and its structured operator diagnostics. Completing this PR does not complete the agent-facing denial criterion or close #43.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

Closed as superseded by #112 (core native macOS file checks), #113 (selection for each workload), and #114 (native-file and agent-denial workload tests). All three replacements merged on October 16, 2026. This combined draft is retained only as historical context.

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.

2 participants