run_python_in_venv
Execute Python code within a project's virtual environment to access its installed dependencies. Each call runs in a fresh interpreter subprocess, ensuring isolation.
Instructions
Run Python code inside a project's virtual environment.
Spawns a fresh subprocess running `<venv>/bin/python -c CODE`.
No namespace carries over between calls — each invocation is a
new interpreter. Use this when the project has dependencies that
aren't installed in the MCP server's Python environment.
Args:
code: Python source to execute.
venv_path: Path to the venv directory (e.g., "/proj/.venv")
OR direct path to the python binary. `~` is expanded.
repl_id: Optional REPL to inherit cwd from. Falls back to
cwd argument, then to server's cwd.
cwd: Explicit working directory override.
timeout_seconds: Kill after N seconds (capped at 600).
env_extra: Additional env vars merged onto os.environ.
PYTHONPATH is NOT auto-set — pass it via env_extra if
the project uses src-layout and needs it.
Returns:
VenvResult dict with ok/python_path/cwd/stdout/stderr/
exit_code/duration_ms/timed_out/truncation flags/error.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | ||
| code | Yes | ||
| repl_id | No | ||
| env_extra | No | ||
| venv_path | Yes | ||
| timeout_seconds | No |