Nexus + PyPI: Lock Down Your AI Agent's Python Dependencies
On November 17, two releases of Microsoft's official agent-framework package on PyPI, 1.26.1 and 1.26.2, shipped a credential stealer. It ran from a .pth startup hook, so it fired every time Python started, even if your code never imported the framework. It went after cloud, CI and package-registry credentials. PyPI quarantined 1.26.1, and the attacker published 1.26.2 anyway.
Now picture the morning after at a team with twenty developers, a CI fleet and a few agent containers. Which machines installed a bad version? How do you stop the next pip install from pulling it, everywhere, right now? If every machine talks straight to pypi.org, the honest answer is "we'll grep around and hope".
A private PyPI proxy gives you a better answer. Here's how to set one up with Nexus Repository, what it does and doesn't protect you from, and the two extra settings that do most of the work.
What a Proxy Actually Buys You
Let me be upfront about this: the free Nexus Community Edition is not a malware scanner. Ask it for 1.26.1 and it will fetch and cache 1.26.1. Sonatype's automatic quarantine is part of its paid Firewall product.
What you get is a single choke point, and that changes the incident response completely:
| Layer | What it gives you |
|---|---|
| Nexus PyPI proxy | One place to block a bad version for every machine, a log of who downloaded what, and cached copies of good versions if a package is yanked |
| Dependency cooldown | New releases wait a few days before your builds accept them, which is usually long enough for a poisoned release to be caught |
| Hash-pinned lockfiles | Builds install exactly the files you reviewed, nothing newer |
| Blocking direct egress to PyPI | Nobody can bypass the proxy by accident |
None of these layers is enough alone. Together they turn "hope" into a checklist.
Step 1: Create the PyPI Proxy
In the Nexus UI, go to Settings > Repositories > Create repository and pick pypi (proxy):
- Name:
pypi-proxy - Remote storage:
https://pypi.org - Blob store: default is fine to start
Save it. Your index URL is now:
https://nexus.example.com/repository/pypi-proxy/simple
If you also publish internal packages, create a pypi (hosted) repository and a pypi (group) that combines both, then point clients at the group instead.
Create a read-only user for machines instead of enabling anonymous access, so the request log tells you who pulled what.
Step 2: Point Every Client at It
For pip, set it once per machine in /etc/pip.conf or ~/.config/pip/pip.conf:
[global]
index-url = https://ci-reader:TOKEN@nexus.example.com/repository/pypi-proxy/simple
In CI, set PIP_INDEX_URL (or UV_DEFAULT_INDEX for uv) from your secret store. In Dockerfiles, don't pass the token as a build argument, because it stays in the image history. Mount the pip config as a BuildKit secret instead:
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=pipconf,target=/etc/pip.conf \
pip install -r requirements.txt
docker build --secret id=pipconf,src=$HOME/.config/pip/pip.conf .
For uv projects, you can also declare it in pyproject.toml:
[[tool.uv.index]]
name = "nexus"
url = "https://nexus.example.com/repository/pypi-proxy/simple"
default = true
Then make the proxy the only way out. Block outbound traffic from CI runners and agent hosts to pypi.org and files.pythonhosted.org, and let only the Nexus server reach them. This is the step most teams skip, and it's the one that makes everything else trustworthy.
Step 3: Block a Bad Version in One Place
When the next incident lands, go to Settings > Repository > Routing Rules, create a rule in Block mode, and add a matcher for the bad files:
.*/agent[-_]framework-1\.26\.[12][-.].*
Then open the pypi-proxy repository and select the rule under Routing Rule. Each proxy takes one rule, so keep a single "blocked releases" rule and add matchers to it over time.
Check that it works from any client:
pip download agent-framework==1.26.1 --no-deps -d /tmp/check
It should fail with a not-found error. Also search for the component under Browse and delete any cached copies, so nothing that slipped in earlier stays around.
Step 4: Find Out Who Pulled It
Nexus records every request in request.log, in the log folder of its data directory. One grep answers the question everyone will ask:
grep -E 'agent_framework-1\.26\.[12]' /nexus-data/log/request.log
Each line includes the client IP and the user. That's your list of machines whose secrets to rotate. Following the incident write-ups, also check for federated identity grants that survive a password change.
Step 5: Add a Cooldown
Most poisoned releases are caught within days. A cooldown means your builds simply don't see a release until it's a few days old. uv supports relative durations since 0.9.17:
[tool.uv]
exclude-newer = "7 days"
Commit the lockfile. uv records the resolved timestamp in uv.lock, so every machine resolves the same way. For pip, generate hashes and install with --require-hashes, which refuses anything that doesn't match the reviewed files:
uv pip compile requirements.in --generate-hashes -o requirements.txt
pip install --require-hashes -r requirements.txt
When you need an urgent security fix, exclude-newer-package lets you make an exception for one package.
Mind the Community Edition Limits
Community Edition is free but capped: 40,000 components and 100,000 requests per day since version 3.87.0. Failed requests count too. Once you go over, Nexus keeps serving what it has and stops adding new components until usage drops. A small team fits easily. A large CI fleet installing everything from scratch on every run may not, so cache dependencies in your builds. Our Nexus and Docker Hub guide covers sizing in more detail.
Running It on Elestio
Nexus Repository on Elestio starts at $30/month for the VM, with SSL, automated backups, monitoring and updates handled. One instance can proxy PyPI and Docker Hub at the same time, so the same server that saves your rate limits also guards your Python builds.
Troubleshooting
pip still downloads from pypi.org. Something sets its own index. Run pip config list and check for PIP_INDEX_URL or --index-url in scripts. Blocking direct egress turns these into visible errors.
401 Unauthorized from the proxy. The machine user lacks read access to the repository, or special characters in the token need URL encoding.
A blocked version still installs. It's cached in a local pip or uv cache on the machine. Clear it with pip cache purge or uv cache clean, and make sure the routing rule is attached to the repository clients actually use.
uv rejects exclude-newer = "7 days". Your uv is older than 0.9.17. Upgrade it, or set required-version = ">=0.9.17" so old versions fail with a clear message.
"New components are not being added." You've hit a Community Edition limit. Check the Usage Center in the UI.
Thanks for reading ❤️ See you in the next one 👋