Repository navigation
docs(sandbox): bwrap isolation limits; test that kill commands stay inside the exec - #6544
stephencge wants to merge 1 commit into
Conversation
…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]>
|
/ok to test f909e04 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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.
|
@hemildesai @yaoyu-33 — this is the follow-up to Hemil's notes on #6279 (pid-namespace scope, |
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.mdand the bwrap docs page):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: hostis 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:8265withoutauthentication, so sandboxed code can submit a Ray job that runs as the Gym uid outside every namespace (checked,
see below). Recommends
network: nonewhere no network is needed.server's uid and job cgroup.
Test:
test_kill_commands_cannot_reach_processes_outside_the_exec(real bwrap). A sandboxedpkill -ffindsthe exec's own
sleep 61.7777andkill -9 -1runs, but a hostsleep 61.7777with the same command linesurvives. The pattern is built inside the shell so the exec's own
sh -cargv cannot match it.CI:
install_test_dependencies.shliftskernel.apparmor_restrict_unprivileged_usernsonly whenNEMO_GYM_REQUIRE_BWRAP=1, which the sandbox job now sets for the whole job instead of one step. The other jobskeep 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.pyandtest_bwrap_provider.py: 43 passed, including the newkill test.
ray.init()asinitialize_raydoes without a head address, then a bwrap sandbox posting tohttp://127.0.0.1:8265/api/jobs/with entrypointtouch /tmp/<random>; the sandbox's/tmpis private):network: host: the job was accepted, and the file appeared in the host's/tmp.network: none: connection refused, no file.pre-commit runpasses on the changed files;bash -non the CI script.🤖 Generated with Claude Code