Skip to content

feat(box): expose run command as library - #116

Merged
gautamsirdeshmukh merged 11 commits into
strands-agents:mainfrom
gautamsirdeshmukh:gsird-task/box-library-api
Oct 20, 2026
Merged

gautamsirdeshmukh merged 11 commits into
strands-agents:mainfrom
gautamsirdeshmukh:gsird-task/box-library-api

Conversation

@gautamsirdeshmukh

@gautamsirdeshmukh gautamsirdeshmukh commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Box applications cannot call the existing Box operations through a Rust library. They must start the command as a child process. This prevents Boxy and similar Rust applications from using the same implementation directly.

This PR adds an approved public library surface for two existing operations:

let exit_code = strands_box::run(config, workload);
let exit_code = strands_box::generate_policy_schema(config, output_dir);

The command parses its own arguments and calls these functions. cli_main is not public. The run function accepts the same trailing workload arguments as the command.

A process can attempt one Box run. A second call fails, including after the first call fails or finishes. The public run path applies process hardening before it creates the async runtime or reads the configuration.

The host application must call Box before it starts threads or loads secrets. The library cannot determine whether the host already completed either action. This PR does not add process restart or reload behavior.

Related Issues

None.

Type of Change

New feature

Testing

  • 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

I ran the Box build, the workspace all-features tests, the Box clippy command, formatting checks, the no-default-features build, scripts/test-all.sh, and the deterministic containment suite. The deterministic suite passed 121 checks with 8 expected macOS skips and full coverage. The Box crate had zero owned clippy warnings.

The library test proves that the public path disables core dumps, disables Linux dumpability, and refuses a second run. Mutation checks failed when hardening or the repeat-run guard was removed. Linux CI must compile and run the Linux-only assertions because this macOS host does not have the required Linux C cross-compiler.

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.

## Problem

Boxy cannot call the Box run command from Rust because strands-box has no
library target.

## Solution

Expose run(PathBuf) -> ExitCode and cli_main() -> ExitCode at the crate
root. Keep the composition modules private. Both entry points use the
existing hardening, runtime, dispatch, and error handling through the
crate-private command::execute function.

Document one workload per host process, startup before threads or secrets,
and matching helpers beside the host executable. Keep live controls and
decision delivery for a separate change.

## Tests

The all-feature Core build, workspace formatting check, and workspace
clippy recipe passed. Existing Core test suites passed. A temporary
external Rust caller imported run(config), ran a contained workload, and
returned its exit code of 7.

The full workspace test run did not pass: an unchanged gateway recorder
test failed, then passed in its full test group. An unchanged interception
suite failed with the host Python TLS version, then passed with installed
Homebrew Python. Remaining local validation was stopped after build-cache
disk exhaustion. Linux, remaining workspace tests, and later gates are
left to GitHub CI at the operator's request.
@gautamsirdeshmukh
gautamsirdeshmukh force-pushed the gsird-task/box-library-api branch from 0ce78ce to abb8865 Compare October 16, 2026 15:54
@gautamsirdeshmukh gautamsirdeshmukh changed the title feat(box): expose the existing run command as a Rust library feat(box): expose run command as library Oct 16, 2026
@gautamsirdeshmukh
gautamsirdeshmukh marked this pull request as ready for review October 16, 2026 16:54
Comment thread crates/box/src/lib.rs Resolved
Comment thread crates/box/src/lib.rs Resolved
Comment thread crates/box/src/lib.rs Resolved
Comment thread crates/box/Cargo.toml Resolved
Comment thread README.md Resolved
Comment thread docs/design/decisions.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

This PR adds a public library target to strands-box and reverses the "Box is a process, no library target" decision. Beyond the code details, this is a frozen-interface and foundational-premise change that AGENTS.md classifies as BLOCKER-tier and requires explicit maintainer approval before code is written — the PR links no such approval, no issue, and carries no api/needs-review label. The core concern is not style but safety: embedding Box into a host process undercuts the hardening model that assumes Box is first-in-process, single-threaded, and sole owner of the address space.

Review themes
  • Freeze / approval: AGENTS.md lists "box has no library target" as an invariant and docs/conventions.md states box is [[bin]]-only. Lifting this needs maintainer sign-off and a named list of what external contract changes.
  • Safety premise: The hardening ordering guarantee ("harden before the runtime exists, single-threaded, before any secret") is enforced today by Box being first-in-process. As a library it can run after host threads/secrets exist; the README only asks callers to avoid this. The removed decision "You cannot embed Box in your own process" also now contradicts the still-present one-trusted-process-per-box rationale.
  • API design: run() returns a process ExitCode instead of a typed Result, hard-codes an empty workload (less capable than the CLI), and leaves the absolute-path requirement unenforced. Two overlapping public entry points (run, cli_main) blur the supported surface vs. the containment reference pattern.
  • Tests: No test accompanies the new public behaviour or proves hardening still applies on the library path, which AGENTS.md requires.
  • Change framing: A decision-record reversal is described as "minor docs updates"; it should arrive via an agreed decision entry, not inside a feature PR.

The underlying goal — letting an application invoke the existing run path — is reasonable, and the implementation is small and cleanly factored (execute split out from cli_main); the blocking items are about the freeze process and the safety guarantees, not the code quality.

@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.

Is the library meant to be an entry point for a dedicated worker process, or is it a module embedded in an already-running application (aka Box CLI)?

@gautamsirdeshmukh

Copy link
Copy Markdown
Contributor Author

Is the library meant to be an entry point for a dedicated worker process, or is it a module embedded in an already-running application (aka Box CLI)?

@ferdingler The plan is the latter. On the CLI side, we'll just need to enforce that Box is called before loading secrets / starting background work. Wanted to start with the simple run entrypoint before expanding the API with other operations needed by the CLI

Comment thread crates/box/src/lib.rs Resolved
Comment thread crates/box/src/lib.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of a52f837)

The previous blocking concerns are addressed. The library surface is now the two deliberate operations (run, generate_policy_schema) with cli_main made private and main.rs acting as a consumer; run accepts a workload argv; a process-wide STARTED guard refuses a second run (even after failure); hardening is still applied on the library path; and tests/box_library.rs proves the hardening and repeat-run behaviour. The PR description now also states the approval and documents the residual honestly.

Status of earlier findings
  • Frozen interface / approval — Addressed; approval now stated. Follow-up: docs/conventions.md still says box is [[bin]]-only.
  • Hardening / embedding safety — Addressed in code and tests; residual (host must call before threads/secrets) is now explicit. Follow-up: record it as a residual risk in decisions.md.
  • Public surface shape — Fully resolved.
  • API capability — workload now a parameter. ExitCode return kept as a deliberate CLI-parity choice (non-blocking).
  • Tests — run is well covered (incl. mutation testing). Gap: generate_policy_schema has no test.
  • Decision record — Partially reconciled by the one-box-per-process guard; the host-memory co-residence tradeoff should still be named in the decision.

Nice turnaround — the repeat-run guard plus the targeted hardening test close the core safety concern cleanly.

@github-actions

Copy link
Copy Markdown

Re-reviewed at ef916d8. This is a merge of upstream main into the branch; the PR's own diff is unchanged from the previous revision I reviewed (a52f837) — same lib.rs, main.rs, command/mod.rs, tests, and docs. No new code to review.

For tracking, the three non-blocking follow-ups from the last pass are still open:

  • docs/conventions.md still says box is [[bin]]-only and the lib.rs façade items don't apply — stale now that box has a library.
  • The "call before threads/secrets" precondition is still only in README prose; please record it as a residual risk in docs/design/decisions.md alongside the existing residuals.
  • generate_policy_schema still has no test.

Assessment unchanged: Comment — the blocking items are resolved; only these minor items remain.

@github-actions

Copy link
Copy Markdown

Re-reviewed at 5f54afd ("Refactor the Box library integration test"). This is the first substantive change since the original review, and the test refactor is a solid improvement.

(Note: the GitHub "files changed" view still showed the previous 79-line box_library.rs; I reviewed the checked-out working tree, which has the refactored version.)

Test refactor — looks good:

  • The repeat-run refusal is now exercised concurrently — the first strands_box::run stays alive on a thread via the marker/release handshake in box-library-probe while the second call is refused — which is a much stronger check than the old missing-config path that failed immediately.
  • Added an_invalid_configuration_is_refused_with_the_parse_error, and the suite now runs under the standard test harness and reuses the shared bounded_output/fixture helpers.
  • Dropping the old RLIMIT_CORE/PR_*_DUMPABLE assertions does not lose coverage — hardening is already unit-tested in src/run/hardening.rs and at integration level in box_inherited_handles.rs, so the removal just drops duplication.

Still open (non-blocking, from earlier passes):

  • docs/conventions.md:10 still declares box is [[bin]]-only and the lib.rs façade items "do not apply" — stale now that box ships a library.
  • The "call before threads/secrets, one workload per process" precondition is still only in README prose; consider recording it as a residual risk in docs/design/decisions.md.
  • generate_policy_schema still has no test. The new probe harness makes adding one straightforward if you think it's worthwhile.

Assessment: Comment — no blocking issues; the remaining items are minor doc/test cleanups.

@github-actions

Copy link
Copy Markdown

Re-reviewed at 299bdd1 ("Revert the Box library test refactor"). This rolls 5f54afd back: box_library.rs returns to the inline-probe form, harness = false is restored, and the box-library-probe support binary is removed. lib.rs also picked up a module-doc table (cosmetic).

No objection to reverting if the harness-based refactor was out of scope for this PR — the restored test is functionally valid and still covers the two things that matter for the library surface: hardening is applied through the public run() path (even when the config is invalid), and the repeat-run guard refuses a second call.

Worth keeping in mind (all non-blocking, carried from earlier passes):

  • Compared to the reverted version, this drops the parse-error test and the genuinely-concurrent repeat-run check (the current test exercises the "already attempted" path via a missing config rather than refusal while a first run is live).
  • docs/conventions.md:10 still says box is [[bin]]-only ("lib.rs façade items do not apply") — stale now that box ships a library.
  • The "call before threads/secrets, one workload per process" precondition remains README-only; consider recording it in docs/design/decisions.md.
  • generate_policy_schema still has no test.

Assessment: Comment — no blocking issues.

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.

4 participants