Skip to content

fix(python3): accept isolation flags -I, -E, -s and -P - #789

Open
anhnt256 wants to merge 10 commits into
vercel-labs:mainfrom
anhnt256:fix/python3-isolation-flags
Open

anhnt256 wants to merge 10 commits into
vercel-labs:mainfrom
anhnt256:fix/python3-isolation-flags

Conversation

@anhnt256

@anhnt256 anhnt256 commented Dec 1, 2026

Copy link
Copy Markdown

Fixes #781

python3 -I, -E, -s and -P (alone or bundled, e.g. -Ic, -IE) failed with python3: unrecognized option, so agent-written Python using -I for untrusted files could not run at all.

The sandbox already provides what these flags promise — a fixed sys.path with no script/cwd directory or user site-packages, and PYTHONPATH never reaches sys.path — so this accepts the flags in the option parser and runs the code normally. A bundled -c/-m also accepts an attached argument now (-c'print(1)'), matching CPython.

Verification:

  • python3 -I -c 'print(1)', -Ic, -IE, -E, -s, -P, -Is, -IP → exit 0, 1
  • python3 -I script.py, python3 -I -m json.tool, python3 -I -V → exit 0
  • PYTHONPATH=/tmp/evil python3 -I -c 'import sys; print(sys.path)' → no /tmp/evil; import json still loads from /lib/python313.zip
  • --unknown, -x and -Ix still exit 2 with unrecognized option; -Ic with no argument still exits 2
  • tsc --noEmit clean, biome check clean

@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@anhnt256 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@auto-maintain

auto-maintain Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🤖 auto-maintain review

Automated, advisory triage for @anhnt256's PR. Facts below are read from the GitHub API.

Check Result
Author's merged PRs (this repo) 0 — ⚠️ first-time contributor
Account established ✅ (age 3864d · 2 followers · 71 public repos)
Commits signed/verified ⚠️ 7/10
Changeset included ✅ (.changeset/python3-isolation-flags.md)

Review panel: 🟡 medium highest severity

just-bash maintainer code review: 🟡 medium

The isolation flags parse correctly, but bundled version parsing introduces incorrect `-VV` compatibility.

  • packages/just-bash/src/commands/python3/python3.ts:120 — Bundled `-V` flags are collapsed into a boolean, so the newly accepted `-VV` prints the ordinary version. CPython defines `-VV` to include extended build details; count occurrences or continue rejecting this unsupported form.

General code review: 🟢 low

No actionable correctness or compatibility issues found in the complete diff.

Adversarial security: 🟡 medium

The PR creates a misleading isolation boundary by accepting security flags as no-ops.

  • packages/just-bash/src/commands/python3/python3.ts:117 — `-I`/`-E` are silently accepted without enforcing their security semantics. The worker still copies attacker-controlled shell variables into `os.environ`, so runtime variables such as `PYTHONBREAKPOINT` remain effective despite callers explicitly requesting environment isolation. Implement the semantics or keep rejecting these flags.

Adversarial security (second opinion): 🟢 low

Change is confined to python3 CLI option parsing plus tests and a changeset; the new bundled short-option parser preserves `--`/`-` semantics, still rejects unknown flags with exit 2, and introduces no new network, process, filesystem, dependency, or CI surface. The claim that user-supplied PYTHONPATH cannot reach sys.path is backed by the worker, which hardcodes the interpreter's PYTHONPATH to the stdlib zip at preRun and injects session env only into os.environ after startup, and each execution gets a fresh worker/MEMFS. The isolation flags being no-ops (including PYTHONBREAKPOINT still being honored) is explicitly documented in both --help and the changeset rather than silently implied. No actionable security findings.

Standard Bash and host portability: 🟡 medium

Isolation flags are portable, but bundled version handling diverges from standard Python behavior.

  • packages/just-bash/src/commands/python3/python3.ts:120 — The bundled parser collapses repeated `V` flags into one boolean. Newly accepted `python3 -VV` therefore prints only the short version, unlike standard CPython, which includes build/compiler details; diagnostic scripts relying on `-VV` lose that information.

Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call.

@privatenumber privatenumber added awaiting-review Maintainer review or re-review is next. Does not imply approval or merge readiness. commands Behavior of, or support for, individual commands enhancement New feature or request p2 Normal backlog action. Priority is not acceptance or a delivery promise. labels Dec 1, 2026

@privatenumber privatenumber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Pushed follow-ups to tighten option parsing and docs:

  • Validate remaining bundled flags and operands before returning version (-IVZ, -IVc).
  • Handle -h/--help sequentially in parseArgs so -IVZ --help rejects -Z and script/module --help is passed through.
  • Clarify in --help and the changeset that -I/-E/-s/-P are accepted as compatibility no-ops without modifying sys.flags, PYTHONBREAKPOINT, or runtime sys.path.
  • Simplified the parser and expanded python3.isolation.test.ts.

Python3 WASM tests, typecheck, and lint all pass. Looks good to merge.

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

awaiting-review Maintainer review or re-review is next. Does not imply approval or merge readiness. commands Behavior of, or support for, individual commands enhancement New feature or request p2 Normal backlog action. Priority is not acceptance or a delivery promise.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python3: accept the isolation flags -I, -E, -s and -P

2 participants