Wiki / Use
Python environments#
For Python work the agent keeps everything in a virtual environment inside the project, never in your global Python.
What happens#
- The agent calls the
venvtool withaction: "create". PortCode runspython3 -m venv .venvin the project (after you approve it). - From then on, every
bashcommand runs withVIRTUAL_ENVset and.venv/binfirst onPATH, sopython,pipandpytestmean the project's own. - The agent installs packages with
venvandaction: "install", which runspip installinside.venv.
The tool has three actions:
| Action | Does |
|---|---|
status (default) | says whether .venv exists and which Python it has |
create | creates .venv; does nothing if it exists |
install | installs the listed packages into .venv |
{"action": "install", "packages": ["numpy", "pytest>=8"]}
Safe by construction#
- Package names must be plain requirements (
pytest>=8,requests[socks]==2.32.0). Flags, URLs and anything with shell characters are refused, so the model cannot pass--index-urlor a git URL. - Creating the environment and installing both ask for permission.
- The project's API-key variables are removed from the environment of these commands.
Turning it off#
It is on by default. Set "venv": false in portcode.json, or use /venv off for the running session (/venv on to bring it back). When it is off, create explains that and bash keeps your normal PATH.
If creation fails, the error says whether Python 3 or, on Debian and Ubuntu, python3-venv is missing.