Skip to content

fix(linux): sanitize statfs for Codex database startup - #356

Merged
kevin-orellana merged 3 commits into
mainfrom
feature/allow-statfs-codex
Nov 9, 2026
Merged

kevin-orellana merged 3 commits into
mainfrom
feature/allow-statfs-codex

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Codex reports a damaged database and exits inside Strands Box v0.2.1 on Linux, even with a new writable data directory.

Solution: Box answers Codex's filesystem query with the metadata needed for startup while removing storage counts and identifiers. Codex stays unchanged.

Trade-off: Programs receive zero capacity and free-space counts, which some applications may treat as a full filesystem. Queries support absolute paths only, and surrounding runtimes must permit the added operations.

Description

The failure was reproduced with Codex CLI 0.167.0 (build 0.167.0.932) on Linux ARM64. Before opening SQLite, Codex calls statfs, a Linux system call that identifies the filesystem and reports its storage statistics. It uses that information to choose database behavior for network filesystems. Box v0.2.1 rejects the call with EPERM (Operation not permitted), which Codex reports as a database problem.

This Box-only change lets the unchanged Codex binary finish startup and reopen its databases. No changes to Box's command-line options or box.toml configuration are required.

What the query returns

Filesystem information Result
Filesystem type, block and fragment sizes (filesystem allocation units), maximum filename length, and mount flags (options applied to the mounted filesystem) The actual values for the resolved path.
Capacity, free space, file counts, filesystem identifier, and reserved bytes Zero.

Programs can identify the filesystem behind a visible path, but they can't use this query to measure the surrounding operating system's storage usage. Programs that interpret a zero free-space count as a full filesystem might reject an operation.

How Box answers the query

Box uses Linux's secure computing (seccomp) facility to filter system calls. As with Box's existing filters, the filter uses classic Berkeley Packet Filter (BPF) instructions. For statfs, it returns a user-notification action: Linux pauses the call and sends a request to Box's existing launcher, the process that starts the sandbox. This adds no extended BPF (eBPF) program, loader, or CAP_BPF requirement.

The launcher copies the pathname from the requesting process and resolves it inside that process's filesystem view. It uses openat2 to keep lookup within the requesting process's root directory. After querying the resolved filesystem, it copies the filtered result into the workload's output buffer with process_vm_writev, which respects read-only memory mappings. The reply completes the blocked call without executing the original statfs call.

To read and write those buffers, the launcher retains CAP_SYS_PTRACE, the kernel privilege used for process-memory access, within the sandbox's private user namespace. It drops every other capability. A user namespace limits where that capability applies; kernel checks prevent this authority from accessing memory in user namespaces in the surrounding operating system. The workload and the helper that manages its descendants still drop every capability.

Before executing a contained Linux program, Box sets up a notification listener and transfers it to the launcher. This file descriptor lets the launcher receive notifications for paused calls. Failed setup or transfer prevents the program from starting. If the query service later fails fatally, the launcher exits. Box's existing cleanup mechanism then terminates the sandboxed program and its descendants. These failure paths don't send signals using a process ID that might have been reused.

Figure 1: A filesystem query during Codex startup. Box writes filtered information into Codex's output buffer. A separate status reply completes the paused call.

Codex requests filesystem information from Linux. The kernel pauses the call and notifies the Box launcher. The launcher resolves the path within Codex's filesystem view and queries the resolved filesystem. It writes filtered information into Codex's output buffer: filesystem type, block and fragment sizes, filename limit, and mount flags retain their actual values; capacity, free space, file counts, filesystem identifier, and reserved bytes are zero. A separate success reply tells Linux to complete the call. The original statfs call does not run.

Editable draw.io source.

Linux requirements and behavior limits

Every contained Linux program installs the listener, including programs that never call statfs. The surrounding runtime must permit listener setup and notification control calls, constrained path lookup through openat2, and buffer transfers through process_vm_readv and process_vm_writev. Blocking listener setup prevents startup; blocking buffer access can make an individual query fail. Box preserves those restrictions rather than weakening the kernel's process-memory checks. It does not request CAP_SYS_PTRACE in the surrounding operating system.

These interfaces are available in Linux 6.1 and 6.12. The v0.2.1 release record documents validation on kernel 6.1.188, and the Amazon Elastic Kubernetes Service (EKS) deployment record uses 6.12.111. This change doesn't require a kernel upgrade from either tested series. Those records don't define a numerical minimum supported kernel version.

Box's Linux availability check tests only whether a user namespace can be created. It doesn't establish that the surrounding runtime permits all required operations. The query also has these limits:

  • Only absolute paths are supported. Relative paths return EOPNOTSUPP (Operation not supported). The related fstatfs call, which queries an open file descriptor, remains denied to the workload.
  • Support applies after Box executes the program. Direct containment-library callers that continue without executing a new program can encounter process-memory errors.
  • Filesystem lookup and statistics can block in the kernel and delay launcher exit handling. This change doesn't impose a deadline on those operations.

Related Issues

No Box bug report is linked. The upstream trigger is Codex's filesystem check before SQLite startup (openai/codex#56552).

Type of Change

Bug fix

Testing

The local code checks below passed for implementation commit eb552fad316ede5d0705e4f937db76699c96f9bb, based on 3eda3e2fefea748ea9d91988aa3812dfbb3508d3. They ran on Amazon Linux 2023 ARM64 with kernel 6.12.113-138.209.amzn2023.aarch64 and Rust 1.98.1. An independent agent review found no remaining concrete defect.

Check Result and scope
Unchanged Codex startup and restart Both launches reached the idle prompt with the integrated Box build and no wrapper. All five SQLite databases had schemas and passed PRAGMA integrity_check; restart reopened the same files. Hashes confirmed that the Codex binary and the tested Box binaries stayed unchanged.
Containment tests All 687 tests passed across 26 targets, including 484 library unit tests. Coverage includes filtered metadata, hidden paths, read-only buffers, child and thread inheritance, scoped launcher privileges, handoff failures, interrupted replies, original startup exit codes, and cleanup.
Deterministic containment suite All 131 applicable cases passed. The suite declared 10 macOS exclusions.
Deliberate defect checks All 15 deliberately introduced defects caused the expected test failures in a separate checkout. Restoring the implementation restored passing controls.
Workspace build, formatting, and tests Passed. scripts/test-all.sh completed the workspace tests with --no-fail-fast.
Rust lint checks (Clippy) The changed containment package passed with no warnings or warning allowances. Workspace Clippy passed with the existing allowances shown below.
Build without default features Passed. All 68 warning headers matched the clean base.
x86_64 Linux library compile check Passed; x86_64 runtime behavior was not tested.

The diagram commit changes only documentation; application code is identical to the tested implementation commit. The figure was exported with draw.io desktop 32.4.1 in the pinned container, at scale 2 with a 20-unit border. A control render matched the upstream reference PNG byte for byte. Layout checks reported no errors or warnings, and the exported image was visually reviewed.

The workspace Clippy command preserves its existing warning allowances. The separate containment-package check used none.

cargo clippy --workspace --all-targets --all-features -- -D warnings -A clippy::too_many_arguments -A clippy::only_used_in_recursion -A clippy::await_holding_refcell_ref -A clippy::explicit_auto_deref -A clippy::chunks_exact_to_as_chunks -A dead_code -A non_snake_case

Hosted checks

For implementation commit eb552fad, hosted Rust unit tests on Linux and macOS, Rust lint, and packaging tests passed, as did CodeQL code analysis.

The diagram commit has separate continuous integration and CodeQL analysis runs. The pull request remains a draft, so hosted containment and verdict jobs are skipped. The previous implementation run's CI Gate log records that these skipped draft jobs prevent the combined check from passing. The automated Strands review for the diagram commit is waiting for manual approval.

Validation limits

The Codex checks use test configuration on XFS, the filesystem on the test host, and stop after startup. They submit no model requests and don't establish that a complete coding workflow succeeds. A live network filesystem wasn't exercised. Cloud checks for Amazon Bedrock AgentCore Runtime and container environments weren't rerun for this commit. Those unrun checks are coverage limits; no compatibility failure in those environments was reproduced. Local validation was Linux-only; hosted Rust tests provide the macOS result noted above.

The workspace suite retains its existing ignored tests. The credential daemon was unavailable. The Linux checks couldn't verify that files granted execution without read permission stay unreadable through other paths. The manual software development kit tutorial wasn't run because it requires external provider access.

  • 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 helped prepare the implementation, validation, and this description.


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

## Problem

Codex probes its data directory's filesystem before opening SQLite. The
Linux syscall allowlist denies statfs, so Codex reports a damaged database
and exits even with a fresh writable directory.

## Solution

Permit statfs and update the allowlist census. Add a production-launcher
regression that compares filesystem types and preserves hidden-file and
read-only-file restrictions. Document filesystem-wide metadata exposure.

## Tests

The focused regression failed with EPERM when statfs was removed and
passed with the change. Exact Codex 0.167.0.932 reached its interactive
prompt on fresh startup and restart; all five databases passed integrity
checks both times.

Formatting, workspace build, Clippy with repository allowances, the full
workspace/examples suite, the no-default-features build, and the x86_64
library compile check passed. The deterministic containment suite passed
131 cases, with 10 declared macOS exclusions and no failures or errors.
No-default build warnings matched the clean base. Existing ignored tests
and unavailable daemon/alias checks remain; native macOS and model-backed
coding workflows were not tested locally.
@github-actions github-actions Bot added bug Something isn't working Area - Agent Containment labels Nov 6, 2026
@kevin-orellana kevin-orellana changed the title fix(linux): allow statfs for Codex database startup fix(linux): sanitize statfs for Codex database startup Nov 7, 2026
@kevin-orellana
kevin-orellana marked this pull request as ready for review November 7, 2026 04:29
@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 7, 2026 04:30
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Assessment: Comment

The mediation looks careful: path resolution stays confined, buffers are written with process_vm_writev, and the launcher holds very little authority. My main concern is how the result behaves: zero capacity turns a v0.2.1 "unknown free space" into "disk full" for best-effort free-space checks. /proc/self paths also fall outside the documented limits.

Assumptions and rules checked that held
  • RESOLVE_IN_ROOT | RESOLVE_NO_MAGICLINKS on /proc/<pid>/root keeps every lookup inside the requester's view, chroot, and nested mount namespace. Ungranted paths stay ENOENT.
  • A thread caller (/proc/<tid>/root, and process_vm_writev with a TID) and a nested-user-namespace caller both resolve correctly.
  • An invalid or read-only output buffer gets EFAULT, the same as the native call. A path near unmapped memory is read in part and still finds its NUL.
  • PID reuse can only reach processes in the sandbox user namespace. cap_ptrace_access_check refuses targets in the surrounding OS's user namespaces, and the reaper and launcher PIDs are excluded.
  • Interrupted notifications (ENOENT from ID_VALID or SEND) are handled. The listener-transfer handshake and its failure exits keep the "fail, never run the workload" rule.
  • The launcher now closes the relay-control descriptor early. The listeners are sent before the fork, and the box doesn't depend on that descriptor's EOF.
  • Cargo.lock is unchanged. The new syscall comes with measured Codex evidence, as crates/containment/AGENTS.md requires.

The new tests check that every non-approved byte is zero, which is a strong guard against leaks.

@abhisheksp abhisheksp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is definitely very involved. We should do a follow up security posture exercise

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

Merge review and remaining follow-ups

The approved revision is 40e7fcf0ab34d5dea0844257e765aa47666bef09. Its required CI Gate passed, including the completed Linux and macOS unit and deterministic containment jobs in that run.

An independent review rechecked the three automated findings against the source and existing defect-detection evidence. All six changed Rust files still match the tested implementation. No production-code change is required to address these nonblocking comments before merging this approved revision.

Review item Disposition
Zero capacity can cause a false disk-full refusal Retain the explicitly disclosed compatibility trade-off. Programs that tolerated a failed free-space query can reject the successful zero-count result. The PR's opening trade-off and returned-values section describe that consequence. Returning synthetic nonzero counts would be a separate behavior change.
Paths through /proc/self and related links Retain as a documentation follow-up. The launcher resolves paths from outside the workload's process-ID namespace, so these links do not have the requesting process's semantics. The committed design page needs this exception stated explicitly. This review does not claim that the path limitation or documentation gap is fixed.
Notification-filter and launcher guidance in the crate's AGENTS.md Retain as a maintenance-documentation follow-up. The ordering and authority restrictions are enforced in the source and described in the design page. Existing library-test mutations also detect removal of the notification filter and excess launcher capability; coverage is broader than the integration test alone. The crate guidance still needs those invariants and guarding-test references.

The two documentation items remain follow-up work for this PR. Abhishek's requested security-posture exercise also remains outstanding; its scope and owner still need assignment. Merging does not complete that assessment.

The approved source is unchanged. Resolving the three threads records these nonblocking dispositions and preserves their limitations and follow-ups above. This merge check reused existing test and mutation evidence; it did not rerun the package suites or the third-party dataset example.

@kevin-orellana
kevin-orellana merged commit 9c0bf1d into main Nov 9, 2026
32 of 34 checks passed
auto-merge was automatically disabled November 9, 2026 17:45

Pull Request is not mergeable

@kevin-orellana
kevin-orellana deleted the feature/allow-statfs-codex branch November 9, 2026 17:45
leo237 pushed a commit to leo237/box that referenced this pull request Nov 9, 2026
`permit_filter_has_112_workload_entries_and_one_installer_entry` asserts
`WORKLOAD_PERMITTED.len() == 112`, but the table holds 113: main's strands-agents#356 ("sanitize statfs for Codex
database startup") added the `statfs` entry without bumping the count. The entry is not `cfg`-gated,
so the assertion fails `left: 113, right: 112` on aarch64 Linux under `--all-features` on main
itself, and this branch inherits it by merging main. This PR is an AWS-credentials change and does
not touch containment.

The test is commented out, not corrected in place, because the right count belongs to the
containment owner; the test author was notified to restore it with the correct number and to
re-check the companion `rules.len()` assertion.

## Tests

No behaviour change; the commented-out test is the only edit. The containment crate builds, and
`cargo fmt --check` is clean.
leo237 pushed a commit to leo237/box that referenced this pull request Nov 9, 2026
…ing it

Addresses the PR strands-agents#342 re-review of c424b83. Commenting the test out dropped four still-correct
seccomp guards (`seccomp`/`pkey_mprotect` must stay out of `WORKLOAD_PERMITTED`, and `setresuid`/
`setresgid` keep one argument-scoped rule each). The real fix is two numbers: main's strands-agents#356 added the
`statfs` entry, so `WORKLOAD_PERMITTED.len()` is 113 and `build_permit_rules(...).len()` is 116.

The test is restored with the counts set to 113 and 116 and renamed to
`permit_filter_has_113_workload_entries_and_one_installer_entry`. The four guards are kept.

## Tests

The containment crate builds and `cargo fmt --check` is clean. The restored test is Linux-only
(`cfg(target_os = "linux")`); CI's aarch64 Linux job exercises it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants