Skip to content

docs(sandbox): bwrap isolation limits; test that kill commands stay inside the exec - #6544

Open
stephencge wants to merge 1 commit into
mainfrom
stepheng/bwrap-followups
Open

stephencge wants to merge 1 commit into
mainfrom
stepheng/bwrap-followups

Conversation

@stephencge

Copy link
Copy Markdown
Contributor

What does this PR do?

Follow-ups from the review of #6279 (bwrap sandbox provider). None of them changes the provider's behaviour.

Docs (nemo_gym/sandbox/providers/bwrap/README.md and the bwrap docs page):

  • One exec is one pid namespace. Processes outside an exec are out of reach, but a harness that runs inside the
    sandbox as one long exec shares its namespace with its own tool commands. Points to the supervisor's stop policy
    and codex_agent's tool_pid_namespace (feat(agents): supervisor stop policy and Codex tool pid namespace #6280).
  • network: host is not an isolation boundary. It shares loopback with host-local control planes.
    With Ray enabled, the head Gym starts serves its dashboard and Jobs API on 127.0.0.1:8265 without
    authentication, so sandboxed code can submit a Ray job that runs as the Gym uid outside every namespace (checked,
    see below). Recommends network: none where no network is needed.
  • No resource limits. No cgroup or rlimit bounds; a fork bomb or memory blow-up counts against the Gym
    server's uid and job cgroup.

Test: test_kill_commands_cannot_reach_processes_outside_the_exec (real bwrap). A sandboxed pkill -f finds
the exec's own sleep 61.7777 and kill -9 -1 runs, but a host sleep 61.7777 with the same command line
survives. The pattern is built inside the shell so the exec's own sh -c argv cannot match it.

CI: install_test_dependencies.sh lifts kernel.apparmor_restrict_unprivileged_userns only when
NEMO_GYM_REQUIRE_BWRAP=1, which the sandbox job now sets for the whole job instead of one step. The other jobs
keep the default, even on a reused runner. Their bwrap tests are unaffected: they run as root, which the AppArmor
restriction does not cover.

Validation

Ubuntu 24.04 host, Debian 12 container, bwrap 0.8.0, non-root user, NEMO_GYM_REQUIRE_BWRAP=1:

  • tests/unit_tests/sandbox/test_bwrap_integration.py and test_bwrap_provider.py: 43 passed, including the new
    kill test.
  • Ray probe (ray.init() as initialize_ray does without a head address, then a bwrap sandbox posting to
    http://127.0.0.1:8265/api/jobs/ with entrypoint touch /tmp/<random>; the sandbox's /tmp is private):
    • network: host: the job was accepted, and the file appeared in the host's /tmp.
    • network: none: connection refused, no file.
  • pre-commit run passes on the changed files; bash -n on the CI script.

🤖 Generated with Claude Code

…nside the exec

Follow-ups from the #6279 review:
- README and docs: one exec is one pid namespace, so a harness running as one long exec is not
  protected from its own tool commands (points to the supervisor and codex_agent's tool_pid_namespace);
  network: host shares loopback with host-local services such as the Ray head's Jobs API; the provider
  sets no cgroup or rlimit bounds.
- A real-bwrap test: pkill and kill -9 -1 in a sandbox reach the exec's own processes but not a host
  process with the same command line.
- CI: lift the AppArmor user-namespace restriction only in the sandbox job, which now sets
  NEMO_GYM_REQUIRE_BWRAP for the whole job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Stephen Ge <[email protected]>
@stephencge
stephencge requested a review from a team as a code owner November 20, 2026 12:23
@copy-pr-bot

copy-pr-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@stephencge

Copy link
Copy Markdown
Contributor Author

/ok to test f909e04

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 20, 2026 12:28
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP

One non-blocking NOTE: the new test leaves its host child running if sandbox startup fails.

I inspected all five changed files and traced the affected CI, provider execution and harness contracts. The delegated documentation report was unavailable, so I checked that topic directly. This was a source-only review; I did not execute tests or reproduce the reported Ray probe.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

# The property the provider exists for: an agent's pkill or kill -9 -1 stays inside its exec's pid namespace.
# The pattern is built in the shell, so the exec's own `sh -c` argv does not match it.
host = subprocess.Popen(["sleep", "61.7777"])
sandbox = await AsyncSandbox(provider).start(SandboxSpec(workdir="/workspace"))

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.

NOTE, suggestion: Could you include sandbox startup in the host child's cleanup scope? If start() raises, this test never enters its finally, so the host sleep runs until its 61.7777-second duration expires without an explicit kill or wait. The provider's readiness probe can raise.

Replace the setup at lines 124–126 with:

    sandbox = AsyncSandbox(provider)
    host = subprocess.Popen(["sleep", "61.7777"])
    try:
        await sandbox.start(SandboxSpec(workdir="/workspace"))

Keep the existing test body and finally. This restores the invariant that every path after successful Popen reaches host cleanup. Calling stop() before startup completes is supported by the facade's handle guard.

Acceptance checks, proposed and not executed: inject BwrapCreateVerificationError from provider.create and verify the captured host child is terminated and reaped. Retain the real success assertions: stdout is ["inner 143", "survived"], the host child is alive at the isolation assertion, and the subsequent sandbox exec returns zero.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added docs Documentation-only updates or documentation debt area:sandbox Sandbox providers, isolation, and sandbox runtime contracts needs-review PR is ready for code review and waiting on a reviewer labels Nov 20, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 23, 2026
@stephencge

Copy link
Copy Markdown
Contributor Author

@hemildesai @yaoyu-33 — this is the follow-up to Hemil's notes on #6279 (pid-namespace scope, network: host vs the Ray dashboard on loopback, no resource limits, a real-bwrap kill test, AppArmor relaxed only in the sandbox job). Docs and one test, no behaviour change; CI is green apart from the non-blocking harness-conformance checks. Could one of you take a look when you have a moment?

This branch has not been deployed

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

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts docs Documentation-only updates or documentation debt needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants