Repository navigation
Sandbox runs a granted venv's python by its own name, keeping the venv - #98
Merged
Merged
Conversation
Sandbox.wrap ran a command by its real path. A venv's bin/python is a link to its base interpreter, so the base ran without the venv, and the venv's packages failed to import. A venv's interpreter (a pyvenv.cfg beside it or one directory up) whose environment lies in a granted place (the sandbox's or the call's readable or writable, or interpreters) now runs by its own name. An ungranted one runs by its real path, as before. No pyvenv.cfg home is read for this: the base installation is shown by following the interpreter's links, as for any program. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 of 7 tasks
Review fixes for #98. Running a granted venv's interpreter by its own name must not start a program that is not there inside, where the base interpreter ran before. Such a venv now keeps the old behaviour: - one beneath a layout's root (/w), whatever grants it; - one not reachable from its grant: the walk follows the links below the outermost granting place (and /usr, shown whole), and each target must be shown too. This covers a .venv linked out of the grant, links through folders nothing shows, nested grants, and a bin/ that is a link; - one named by a spelling no grant shows; - one whose interpreter's links reach its installation through a linked directory other than the system's (uv's version alias). An ungranted venv beneath /usr also runs as before. The interpreter's link hops outside the venv are made again inside as links, not bound as copies, so a shared Python still finds libpython by $ORIGIN. A root grant works, and bind()'s /usr exclusion no longer drops /usr2. Nothing is bound from a pyvenv.cfg or from a directory's contents; an earlier attempt that bound a linked installation's lib directories was removed. ASPIRE's workaround comment, the sandbox guide, its diagram and the changelog say what the code does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Fixes #95.
Problem.
Sandbox.wrapruns a command by its real path (hermit/sandbox.py, aftershutil.which), with one exception for hermit's own interpreter. A venv'sbin/pythonis a link to its base interpreter, so a venv's python was run as the base interpreter. That interpreter finds nopyvenv.cfgbeside the path it started from, so it ran without the venv, and the venv's packages failed to import. Reproduced on main for a venv made from hermit's interpreter and one made from/usr/bin/python3, granted either for the sandbox or for one call: each was run asanaconda3/bin/pythonor/usr/bin/python3.9, andimport <module in the venv>raisedModuleNotFoundError.Behavior now.
pyvenv.cfgbeside it or one directory up) runs by its own name when the environment exists inside under that name. Concretely:readableorwritable, orinterpreters;_reachable). The check follows the links below the outermost granting place, with/usrcounted as shown whole, and each link's target must be shown too;/w);/bin,/lib).$ORIGIN./usrthat is not granted, one beneath/w, one reached through a link to a place nothing shows, and one made through uv's version alias. None of them can fail to start where it started before.pyvenv.cfgor from a directory's contents. A venv granted for one call still names no installation to show, and a test asserts it.bind()skipped every name beginning with/usr, including/usr2. A grant there is now bound.Interfaces.
hermit/sandbox.py: new helpers_venv_root,_granted_venv,_reachable,_link_hopsand_beneath, plus one branch inSandbox.wrap;bind()'s/usrtest is boundary-aware. No signature changes.hermit/adapter/remote.pypasses a benchmark venv (HA_ADAPTER_PYTHON) as a trustedinterpretersentry. That interpreter now runs as the venv, as the comment there intends.examples/aspire_robosuite/utils/agent/sim.py,confine) still works and is kept. Its comment, which said the sandbox runs a venv's python by its real path, is updated.Docs.
docs/guides/sandbox.md(Programs: when a granted venv's interpreter runs by its own name, and the exceptions).docs/_includes/sandbox-build.html(the diagram's programs row).CHANGELOG.mdunder Fixed.Validation
python -m pytest --changed --base origin/mainon 422c1ef: every group (the sandbox is shared code), 1263 passed, 98 skipped, 0 failed. The environment had no mini-swe-agent, and the integration tests ran without--integration, so both were among the skipped.tests/core/test_sandbox.pynow has 20 venv-related cases:/usr/bin/python3, and one whosebin/pythonreaches the interpreter through another link. Each imports its own package inside;/usr2bind.origin/main, the rest with their fix reverted in a throwaway copy.python -m hermit.sandbox '{"network": "isolated", "readable": ["<venv>"]}' -- <venv>/bin/python -c 'import marker95; ...', givesModuleNotFoundErroron main andthe venvwith this change.bash docs/build.sh(Sphinx,-W): passes, no warnings.ruff check: only the two E741s that are already on main (tests/core/test_sandbox.py:289-290).$ORIGINcase): checked by reading the code and by inspecting the generated command, since this machine's Python is static.Review
hermit/sandbox.py, shared by every sandbox: one branch in howwrapnames the program it runs. Only a granted venv's interpreter is affected.binds) is not counted as granted, so it runs as before.Sandbox.wrapend to end under bubblewrap, and thepython -m hermit.sandboxlauncher.docs/guides/sandbox.md,CHANGELOG.md.gpt-6.1-sol, high effort) reviewed the PR independently. It ran 10 rounds, the limit, plus an 11th at the user's request, which found nothing./usr, a root grant,/usr2, and a bound copy breaking$ORIGIN.tests/core/test_sandbox.py, the group ofhermit/sandbox.py.tmp_path.hermit/sandbox.py. The change was agreed in Sandbox.wrap runs a venv's python by its real path, which drops the venv #95, filed by the core team; see Core changes above.program_pathsas before.🤖 Generated with Claude Code