Repository navigation
Description
Describe the bug
In Copilot CLI 1.0.112, standalone Python script commands execute through the venv interpreter’s resolved symlink target rather than preserving the venv path. Python consequently runs outside the activated venv, despite PATH and VIRTUAL_ENV still identifying that environment.
This also occurs when the command explicitly specifies the absolute venv interpreter path.
I don’t know whether this rewriting is intentional execution-validation behavior or a defect. Either way, the resulting interpreter change is surprising and was not apparent to the agent from its tool instructions. It required explicit testing and inspection of the child process’s parent-shell command to understand.
Affected version
1.0.112
Steps to reproduce the behavior
- Prepare an isolated reproduction in a normal terminal
repro_dir="$(mktemp -d "${TMPDIR:-/tmp}/copilot-venv-repro.XXXXXX")"
cd "$repro_dir"
python3 -m venv .venv
source .venv/bin/activate
cat > probe.py <<'PY'
import json
import os
import subprocess
import sys
print(json.dumps({
"executable": sys.executable,
"prefix": sys.prefix,
"base_prefix": sys.base_prefix,
"VIRTUAL_ENV": os.environ.get("VIRTUAL_ENV"),
"PATH": os.environ.get("PATH"),
"sys.path": sys.path,
}, indent=2), flush=True)
subprocess.run([
"/bin/ps", "-p", str(os.getppid()), "-o", "command="
], check=True)
PY
python3 probe.py
printf 'Probe path: %s/probe.py\n' "$PWD"
printf 'Venv Python: %s/bin/python3\n' "$VIRTUAL_ENV"
Confirm that normal terminal execution reports the venv’s prefix and that sys.prefix != sys.base_prefix.
- Launch Copilot from that activated environment
copilot
- Ask the agent to execute these separately
Substitute the literal absolute paths printed above:
python3 /absolute/path/to/probe.py
/absolute/path/to/.venv/bin/python3 /absolute/path/to/probe.py
Run each as its own Bash tool call, verbatim. Do not prepend diagnostic commands or combine them into a compound shell command: command shape affects the observed behavior.
- Compare with explicit shell-wrapped execution
/bin/bash --noprofile --norc -c
'exec "${VIRTUAL_ENV:?Activate the intended venv first}/bin/python3" "$@"' _
/absolute/path/to/probe.py
For standalone script commands:
• sys.prefix == sys.base_prefix: Python is outside the venv.
• sys.path contains global rather than venv site-packages.
• VIRTUAL_ENV and PATH still identify the activated venv.
• Packages installed in the venv cannot be imported.
The probe captured its parent shell executing a rewritten command shaped like:
/bin/bash --norc --noprofile -c command '/usr/local/Cellar/python@3.13/3.13.9/Frameworks/Python.framework/Versions/3.13/bin/python3.13' '…/probe.py'
Explicit shell-wrapped execution preserves the venv and finds its installed packages. No permission or sandbox settings were disabled during this comparison.
Expected behavior
Ideally, execution validation should preserve the interpreter invocation semantics needed by Python venvs.
If this rewriting is intentional:
• Explain the behavior and supported venv invocation method in agent-facing tool descriptions or instructions.
• Expose the effective command/interpreter when it differs from the submitted command.
• Avoid leaving the agent to interpret the resulting import failure as evidence that dependencies are missing from the intended environment.
In our investigation, checking command -v python3 or running a separate python3 -c diagnostic showed the correct venv, while standalone script execution used global Python. That discrepancy made ordinary troubleshooting misleading.
Additional context
Copilot CLI: 1.0.112, build 24d885ba
macOS, Intel
Homebrew Python 3.13.9
Activated symlink-based Python venv
Activity