Skip to content

fix(shim): remove rpath which segfault on PIE glibc binary#1016

Open
xhebox wants to merge 2 commits into
boxlite-ai:mainfrom
xhebox:boxlite-fix
Open

fix(shim): remove rpath which segfault on PIE glibc binary#1016
xhebox wants to merge 2 commits into
boxlite-ai:mainfrom
xhebox:boxlite-fix

Conversation

@xhebox

@xhebox xhebox commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Changes

How to verify

Risks / rollout

Summary by CodeRabbit

  • New Features
    • None
  • Bug Fixes
    • Improved --rm container cleanup to ensure boxes/directories are removed deterministically, even on non-zero exits.
    • Fixed handling of --rm so it no longer affects lifecycle auto-deletion behavior.
    • Sandbox-launched processes now run with a sanitized, predictable environment.
  • Documentation
    • Updated C SDK quickstarts, reference guides, and examples to use simpler static-library build/link commands and updated runtime environment guidance.
  • Tests
    • Added coverage for sandbox environment sanitization and improved --rm cleanup validation.

@xhebox
xhebox requested a review from a team as a code owner July 22, 2026 12:17
Copilot AI review requested due to automatic review settings July 22, 2026 12:17
@boxlite-agent

boxlite-agent Bot commented Jul 22, 2026

Copy link
Copy Markdown

📦 BoxLite review — couldn't complete

claude exited 1

stdout:
{"type":"result","subtype":"success","is_error":true,"api_error_status":403,"duration_ms":339,"duration_api_ms":0,"num_turns":1,"result":"Your organization has disabled Claude subscription access for Claude Code · Use an Anthropic API key instead, or ask your admin to enable access","stop_reason":"stop_sequence","session_id":"7603b3f7-3519-4769-836b-074b13df228a","total_cost_usd":0,"usage":{"input_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"inference_geo":"","iterations":[],"speed":"standard"},"modelUsage":{},"permission_denials":[],"terminal_reason":"api_error","fast_mode_state":"off","uuid":"7b3d8136-bdb1-44d9-a62e-1e3707d7b49c"}

stderr:
<empty>

powered by BoxLite

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The C SDK release workflow now prepares symbol-fixed static archives through make dist:c. Examples, quickstarts, and documentation use static linking. macOS library-path handling, Seatbelt shim environment inheritance, and CLI --rm cleanup are also updated and tested.

Changes

C SDK distribution and linking

Layer / File(s) Summary
Archive preparation and runtime library paths
.github/workflows/build-c.yml, make/*.mk, src/boxlite/src/util/mod.rs
C SDK builds now delegate archive preparation to make dist:c, apply Go symbol fixes, and set macOS DYLD_LIBRARY_PATH from joined library directories.
Static-linking examples and guidance
examples/c/*, apps/dashboard/src/lib/quickstart/interfaces.json, docs/getting-started/quickstart-c.md, docs/reference/c/README.md, sdks/c/README.md
C examples, quickstarts, and documentation now link directly to libboxlite.a and remove obsolete shared-library RPATH setup where applicable.

Seatbelt environment sanitization

Layer / File(s) Summary
Sanitized sandbox process environment
src/boxlite/src/jailer/sandbox/seatbelt.rs
Seatbelt child processes now receive fixed PATH and HOME values plus entries from shim_process_env(), with coverage for inherited-variable exclusion.

CLI --rm cleanup

Layer / File(s) Summary
Explicit run cleanup and validation
src/cli/src/cli.rs, src/cli/src/commands/run.rs, src/cli/tests/run.rs
Attached runs now explicitly remove boxes after execution, distinguish cleanup failures from primary run results, and verify box directories are removed.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is only the untouched template and lacks the required summary, changes, verification, and risk details. Fill in the template with a brief summary, key changes, at least one verification step, and risks/rollout notes or remove the section.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: removing the shim rpath to fix PIE glibc segfaults.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DorianZheng DorianZheng added the e2e-local Triggers the local (in-process) E2E suite on the self-hosted runner label Jul 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
src/boxlite/src/jailer/sandbox/seatbelt.rs (1)

389-430: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Make the test exercise inherited-environment clearing.

SHOULD_NOT_SURVIVE is set on the discarded command, so it would disappear even without env_clear(). Test the rewritten command with a known process-level variable and an allowlisted variable to verify both filtering and preservation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/boxlite/src/jailer/sandbox/seatbelt.rs` around lines 389 - 430, Update
test_apply_sanitizes_env to set SHOULD_NOT_SURVIVE through the process
environment rather than only on the discarded Command, and add a process-level
allowlisted variable to verify it is preserved. Keep assertions covering removal
of the arbitrary variable and retention of the allowlisted variable after
SeatbeltSandbox::apply.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/reference/c/README.md`:
- Around line 1178-1190: Update the shared-library CMake example following
target_link_libraries in the “Shared library” section to document running the
built executable with the appropriate platform-specific DYLD_LIBRARY_PATH or
LD_LIBRARY_PATH pointing to BOXLITE_LIB_DIR, matching the direct-compilation
example’s runtime setup.

In `@examples/c/README.md`:
- Around line 17-18: Use the prepared-archive workflow for all local C examples:
in examples/c/README.md lines 17-18, replace the raw cargo build prerequisite
with make dist:c or explicitly run fix-go-symbols.sh afterward; in
examples/c/CMakeLists.txt lines 14-15, update the missing-library guidance to
invoke the same prepared-archive workflow.

In `@src/boxlite/src/jailer/sandbox/seatbelt.rs`:
- Around line 119-124: Update the sandbox command environment setup around
shim_process_env() to explicitly restore the validated runtime DYLD_LIBRARY_PATH
produced by configure_library_env() after env_clear(). Keep the existing fixed
environment and shim variables, and do not inherit the host’s DYLD_LIBRARY_PATH.

In `@src/boxlite/src/util/mod.rs`:
- Around line 124-127: Update the library-path setup around std::env::join_paths
to handle its error explicitly instead of calling expect. When joining lib_dirs
fails because an entry contains the platform separator, skip setting
DYLD_LIBRARY_PATH or propagate a clear configuration error, while preserving the
existing environment assignment and debug logging for successful joins.

---

Nitpick comments:
In `@src/boxlite/src/jailer/sandbox/seatbelt.rs`:
- Around line 389-430: Update test_apply_sanitizes_env to set SHOULD_NOT_SURVIVE
through the process environment rather than only on the discarded Command, and
add a process-level allowlisted variable to verify it is preserved. Keep
assertions covering removal of the arbitrary variable and retention of the
allowlisted variable after SeatbeltSandbox::apply.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9f06af75-05c5-46ad-8e1e-ff8efbd9fa71

📥 Commits

Reviewing files that changed from the base of the PR and between 9c251a9 and 4edbc2d.

📒 Files selected for processing (12)
  • .github/workflows/build-c.yml
  • apps/dashboard/src/lib/quickstart/interfaces.json
  • docs/getting-started/quickstart-c.md
  • docs/reference/c/README.md
  • examples/c/CMakeLists.txt
  • examples/c/README.md
  • make/dev.mk
  • make/dist.mk
  • sdks/c/README.md
  • src/boxlite/src/jailer/sandbox/seatbelt.rs
  • src/boxlite/src/util/mod.rs
  • src/shim/build.rs
💤 Files with no reviewable changes (1)
  • src/shim/build.rs

Comment thread docs/reference/c/README.md
Comment thread examples/c/README.md
Comment thread src/boxlite/src/jailer/sandbox/seatbelt.rs
Comment thread src/boxlite/src/util/mod.rs
DorianZheng added a commit that referenced this pull request Jul 22, 2026
## Why

actions/checkout v5.1.0 (2026-07-20) refuses to fetch fork PR code in
`pull_request_target` workflows unless the step opts in via
`allow-unsafe-pr-checkout: true`. Every fork PR now fails e2e at the
Checkout step (first hit: #1016, run 29919073197):

> Refusing to check out fork pull request code from a
'pull_request_target' workflow. … set 'allow-unsafe-pr-checkout: true'
on the actions/checkout step.

## What

Opt the e2e-tests Checkout step in. The mitigations the gate asks for
already exist in this workflow: fork runs are gated on the
maintainer-applied `e2e-local` label pinned to the approved head SHA
(re-label per push), the job holds no secrets, and the token is
`contents: read` with `persist-credentials: false`.

Note: actionlint ≤1.7.11 flags the input as unknown — stale bundled
schema; the input is defined in action.yml at the SHA `v5` resolves to.

**After merge:** remove and re-add the `e2e-local` label on #1016 to
re-run e2e against the fixed workflow definition (pull_request_target
reads the workflow from main, so the fix takes effect only once merged).

https://claude.ai/code/session_019NzYgutK3RsJupnSe16M1w

Co-authored-by: tester <[email protected]>
Copilot AI review requested due to automatic review settings July 22, 2026 12:45

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@G4614
G4614 enabled auto-merge July 22, 2026 12:54
@G4614

G4614 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

can

@DorianZheng DorianZheng added e2e-local Triggers the local (in-process) E2E suite on the self-hosted runner and removed e2e-local Triggers the local (in-process) E2E suite on the self-hosted runner labels Jul 22, 2026
# Fix Go runtime symbol conflicts in the static library
bash scripts/build/fix-go-symbols.sh target/release/libboxlite.a
# Build and prepare the C FFI libraries through the local entrypoint.
make dist:c

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

let mut new_cmd = Command::new(sandbox_cmd);
new_cmd.args(sandbox_args);
new_cmd.env_clear();
new_cmd.env("PATH", "/usr/bin:/bin:/usr/sbin:/sbin");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why add these envs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

align with bwrap

Copilot AI review requested due to automatic review settings July 22, 2026 15:20
auto-merge was automatically disabled July 22, 2026 15:20

Head branch was pushed to by a user without write access

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cli/src/cli.rs (1)

785-798: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

--rm needs an explicit --detach policy. ManagementFlags::apply_to forces auto_delete = Some(0), and run() only calls rt.remove on the foreground path, so boxlite run --rm -d … leaves the box behind (src/cli/src/cli.rs#L785-L798, src/cli/src/commands/run.rs#L78-L123). Reject that combination or add a detached cleanup path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/src/cli.rs` around lines 785 - 798, The --rm option currently leaves
detached boxes behind because ManagementFlags::apply_to sets auto_delete without
enforcing a detach policy, while run() only removes foreground boxes. Update
src/cli/src/cli.rs lines 785-798 and src/cli/src/commands/run.rs lines 157-158
to either reject the --rm --detach combination or add detached cleanup, ensuring
every accepted --rm invocation removes the box.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/cli/src/cli.rs`:
- Around line 785-798: The --rm option currently leaves detached boxes behind
because ManagementFlags::apply_to sets auto_delete without enforcing a detach
policy, while run() only removes foreground boxes. Update src/cli/src/cli.rs
lines 785-798 and src/cli/src/commands/run.rs lines 157-158 to either reject the
--rm --detach combination or add detached cleanup, ensuring every accepted --rm
invocation removes the box.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: acfe82c1-0acc-4e06-8af0-5191b53e00d1

📥 Commits

Reviewing files that changed from the base of the PR and between 5f99558 and 4c6affd.

📒 Files selected for processing (3)
  • src/cli/src/cli.rs
  • src/cli/src/commands/run.rs
  • src/cli/tests/run.rs

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

Labels

e2e-local Triggers the local (in-process) E2E suite on the self-hosted runner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants