Repository navigation
fix(hooks): keep the opened project off sys.path in session hooks - #1769
Merged
Merged
Conversation
The magpie-setup session-start hook and the container-gateway hook run `python3 -m <package>` with the project being opened as their working directory. `-m` puts that directory on sys.path ahead of PYTHONPATH, so a `setup_preflight/` or `container_gateway/` package committed to the project ran in place of Magpie's own, outside the sandbox, as soon as a session started. The container-gateway hook's trust model already says it never runs code from the repository being opened; this makes that hold. Run both with `python3 -P`, which leaves the working directory off sys.path and keeps PYTHONPATH. Both packages already require Python 3.11, where `-P` was added. Add a test that runs check-upgrade.sh from a project carrying a planted `setup_preflight` package (it fails without the fix), and assert `-P` in the container-gateway hook's dry-run command. Generated-by: Claude Code (Opus 5.5)
potiuk
enabled auto-merge (squash)
October 23, 2026 08:57
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.
Two session hooks run
python3 -m <package>with the project being opened as their working directory:plugins/magpie-setup/hooks/check-upgrade.sh(setup_preflight.isolated session-start)tools/agent-isolation/container-gateway-hook.sh(container_gateway serve/stop)python3 -mputs the working directory onsys.pathahead ofPYTHONPATH. Asetup_preflight/orcontainer_gateway/package committed to the opened repository therefore ran instead of Magpie's own copy. It ran outside the sandbox, as soon as the session started. The container-gateway hook's header already says it "executes only code from locations the operator installed or pinned, never from the repository being opened". Until now, that promise didn't hold for the working directory.The fix runs both hooks with
python3 -P. That keeps the working directory offsys.pathand keepsPYTHONPATH.-Iwould also have droppedPYTHONPATH, which both hooks rely on. Both packages already declarerequires-python = ">=3.11", and 3.11 is the version that added-P.Tests:
tools/setup-preflight/tests/test_session_hook.pyrunscheck-upgrade.shfrom a project that carries a plantedsetup_preflightpackage. The test fails onmainand passes with this change.-Pin the dry-run command for bothstartandstop.The isolated-setup doctor probe (
probe-3-container-gateway.sh) also usespython3 -mfrom the project directory. It is out of scope here: it runs inside the agent's sandboxed session against in-repo sources by design, not as a hook outside the sandbox.Generative AI disclosure: this change was prepared with Claude Code (Opus 5.5) and reviewed by me before submission.
🤖 Generated with Claude Code