# Python dependency installs for coding agents: virtual environments, pinned hashes and wheels only

> pip install can build and run code from a source distribution on the way in. How a team can let coding agents install Python dependencies safely: a virtual environment per machine, pinned requirements with hashes, wheels only, and a rule for what the agent does when it wants a new package.

pip install can build and run code from a source distribution on the way in. How a team can let coding agents install Python dependencies safely: a virtual environment per machine, pinned requirements with hashes, wheels only, and a rule for what the agent does when it wants a new package.

December 2, 2026 · 5 min read · The Sandscale team

A coding agent working on a Python repository hits a missing import and does the obvious thing: `pip install` whatever is missing. On a laptop, with a person watching, that is a small risk. For an agent running unattended on its own branch, three things are worth deciding in advance: where the packages go, which ones are allowed, and whether an install is allowed to run code.

This post sets out a short routine for that. The pip details come from pip’s own [secure installs documentation](https://pip.pypa.io/en/stable/topics/secure-installs/), read on 2 December 2026. Sandscale commands are from CLI 1.4.1.

## Put the packages in a virtual environment, on the agent’s machine

Without a virtual environment, `pip install` writes into whichever Python it finds first, which on a shared machine may be everyone’s. With one agent per machine, that matters less, but a virtual environment still keeps the project’s dependencies separate from the machine’s tools and makes “start again” a matter of deleting a directory:

```sh
python3 -m venv .venv
. .venv/bin/activate
```

Add `.venv` to `.gitignore` so the agent never commits it.

Where the machine is the agent’s own, there is nothing else on it to damage. On Sandscale, a [workspace](https://sandscale.dev/workspaces) is a cloud machine per agent with a persistent disk, so the virtual environment survives between sessions. The environment is built once, and the next task starts with it already there.

## Two things pip can do for you

pip’s secure installs documentation names two protections that a team can turn on.

**Hash-checking mode.** Put a hash on every requirement, and pip refuses a package whose archive does not match. In the documentation’s words, it uses local hashes embedded in the `requirements.txt` file to protect against remote tampering and network issues. Three rules from the documentation shape how you use it:

- It is all or nothing. Specifying `--hash` for any requirement turns the mode on for every requirement.
- Hashes are required for all dependencies, including the indirect ones. A dependency that is not spelled out and hashed results in an error.
- Requirements must be pinned, to a URL, a filesystem path or `==`.

You can force the mode with `--require-hashes`, which the documentation notes is useful in deploy scripts and is also a convenient way to bootstrap a list of hashes, since it shows the hashes of the packages it fetched. A tool such as `pip-compile --generate-hashes` from pip-tools can produce the whole file; the pip documentation describes the file’s format, not that tool, so check pip-tools’ own docs for it.

**Wheels only.** Pass `--only-binary :all:` and pip disallows source distributions. This matters because installing a source distribution can mean building it, and building runs the package’s build code on your machine. A wheel is a built archive: pip unpacks it. (Some packages ship only a source distribution. Those will fail under this flag, which is the point: someone should decide on purpose.)

Together:

```sh
python3 -m pip install --require-hashes --only-binary :all: -r requirements.txt
```

If a package fails because it has no wheel for the machine, or a hash does not match, the agent should stop and report. It should not remove the flags to get past the error.

## The rule for AGENTS.md

```markdown
## Dependencies (Python)
- Work inside .venv. Create it with `python3 -m venv .venv` if it does not exist.
- Install only from the repository's requirements file, with
  `python3 -m pip install --require-hashes --only-binary :all: -r requirements.txt`.
- Do not run `pip install <package>` for anything not in the requirements file.
  If you think a package is missing, stop and say which package and why.
- If an install fails on a hash or because no wheel is available, report it.
  Do not drop --require-hashes or --only-binary to make it pass.
- Do not edit requirements.txt unless the task says to.
```

Like every instruction file, this is a request. If you want enforcement, a hook can rewrite or refuse a `pip install`; our post on [Claude Code hooks that route Bash to a sandbox](https://sandscale.dev/blog/claude-code-hooks-route-bash-to-a-sandbox) shows the mechanism, and its pattern already includes `pip install`.

## When the agent really does need a new package

It will happen. The task is “add a CSV export” and the library for it is not in the requirements file. The routine:

1. The agent stops and writes down the package, the reason, and the alternatives in the standard library.
2. A person decides. They look at the package’s age, maintainers and what else it pulls in, which is the work our post on [agents installing packages](https://sandscale.dev/blog/supply-chain-risk-when-agents-install-packages) describes.
3. A person updates the pinned, hashed requirements file in a commit of its own, so the diff is only the dependency change.
4. The agent then installs from the updated file.

This is slower than letting the agent install it. That is deliberate. A new dependency is a decision about code the team will run for years.

## Network and where the install runs

An install has to fetch packages, so the machine needs the network access your plan and your organization’s policy allow. An allowlist that includes the package index and nothing more is the shape to aim for; see [designing an egress allowlist](https://sandscale.dev/blog/egress-allowlist-design-for-agent-sandboxes). Running the install on the agent’s own machine means a build script that behaves badly is running next to that agent’s checkout and not next to your credentials:

```sh
sandscale workspace create --name data-2290-csv-export --template-id TEMPLATE_ID --ttl-seconds 28800
sandscale workspace ssh data-2290-csv-export
```

## What the reviewer checks

- Is `requirements.txt` (or the lock file your project uses) in the diff? If the task did not ask for a dependency change, ask why.
- If it changed, is each hash present, and does each new package match what the task needed?
- Did the agent touch `setup.py`, `pyproject.toml` build settings or a `conftest.py`? Those run code at install or test time. Our [reviewer checklist](https://sandscale.dev/blog/reviewing-an-agent-diff-checklist) covers it.

## What this does not do

Hashes prove that the archive is the one you pinned. They do not prove that the package is good. If you pinned a malicious version, the hashes match. The routine above keeps agents from changing what you pinned and from running build code unasked; it does not replace choosing dependencies with care.

**On this page**

1. Put the packages in a virtual environment, on the agent’s machine
2. Two things pip can do for you
3. The rule for AGENTS.md
4. When the agent really does need a new package
5. Network and where the install runs
6. What the reviewer checks
7. What this does not do

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [December 2, 2026 · **Auditing the MCP tool calls your team's coding agents make** · When Claude Code, Codex, Cursor or Gemini CLI call MCP tools, the record of what happened can live in three places: the client, the MCP server, and the system behind it. What each layer can see, which one to trust as the record, whether to keep arguments, and how to read Sandscale's audit log for agent calls from the CLI.](https://sandscale.dev/blog/auditing-mcp-tool-calls)
- [December 2, 2026 · **Coding agents on client projects: a team lead's checklist for one machine per agent** · Services teams run Claude Code, Codex and Cursor across several client codebases at once. When those agents share developer laptops, client code, credentials and history mix. A checklist for team leads: one machine per agent per client, secrets kept per client, who can start and stop what, the audit record a client may ask for, and a clean exit at the end of the engagement.](https://sandscale.dev/blog/client-projects-one-machine-per-agent-checklist)

---
Source: https://sandscale.dev/blog/python-dependency-installs-for-coding-agents
