DEV Community

Shivam Kumar
Shivam Kumar

Posted on

Your Python Interpreter Was the Attack Surface: What the agent-framework PyPI Poisoning Means for Your Next pip install

Your Python Interpreter Was the Attack Surface: What the agent-framework PyPI Poisoning Means for Your Next pip install

On November 17, 2026, two poisoned versions of Microsoft's agent-framework package hit PyPI — 1.26.1 at 20:35 UTC and 1.26.2 at 21:08 UTC. Both were quarantined within the hour. The last clean version is 1.26.0.

Here's the part that should change how you think about pip install: the malware never needed your code to import the package. It ran every time Python started.

A one-line .pth file did all the work

Python executes .pth files in site-packages at interpreter startup, before your code runs and regardless of what it imports. Each malicious wheel dropped a one-line .pth file — import agent_framework_meta in 1.26.1, import af_runtime_diag in 1.26.2 — that launched a credential stealer. It fired on python, pytest, IDE language servers, container entrypoints, even pip itself. The collector wrote no lockfiles or markers, so every launch exfiltrated again.

The second release was sneakier than the first: 1.26.1 appended a telemetry call to __init__.py, which a diff would catch; 1.26.2 restored that file byte-for-byte and moved the payload into a separate module. Diffing the package code between 1.26.0 and 1.26.2 finds nothing wrong.

The attacker's tooling called itself "Cairn", an open-source AI pen-testing framework. Wiz reported the attacker appears to have compromised a client certificate and private key for Microsoft's ESRP release pipeline. JFrog's forensics add a twist: ZIP headers show the wheel was repacked locally at 20:26 UTC, nine minutes before upload, on a host with a UTC+8 clock. The publishing credential was real; the build was not.

What it took

  • Environment variables matching 31 keywords (TOKEN, SECRET, PASSWORD, KEY, AZURE, AWS, GITHUB, OPENAI, HF_…) from the current process and up to 300 other processes via /proc/*/environ.
  • Credential files — up to 60 in 1.26.1, 80 in 1.26.2: Azure CLI state, .npmrc, pip.conf, .netrc, .git-credentials, Docker config, Hugging Face tokens, .env files.
  • Fresh tokens, not just stored secrets: Azure managed-identity tokens for 12 resources, Azure DevOps OIDC tokens, and in 1.26.2, GitHub Actions OIDC tokens when workflows had id-token: write.
  • Everything went out as one zlib-compressed, base64-encoded JSON POST to a webhook.site URL.

OIDC and managed-identity tokens are minted live — you can't find them by scanning old files, and they carry the exact cloud permissions your CI pipeline holds.

The exposure math (my calculation)

The package gets ~190,000 downloads a month (Orca), ~41,000 a week (Wiz) — roughly 6,300 a day, 264 an hour. Spread evenly across the 41-minute window, that implies ~180 installs of the poisoned versions. An estimate, not a reported count — but it frames the scale: not thousands of machines, a short, sharp exposure of developers who install first and ask questions later.

Per host it gets worse. A CI runner invoking Python 100 times a day sent roughly 100 exfiltration posts a day until the environment was rebuilt. And the cleanup bill: a small team (five devs, three CI runners) faces eight environments at 10–20 secrets each — 80 to 160 credentials to rotate, two to four hours per environment, 16 to 32 engineer-hours total. That is the real cost of a 41-minute window.

Check your environment now

  1. pip show agent-framework — 1.26.1 or 1.26.2 means exposed. Pin to 1.26.0.
  2. Assume compromise. Rotate every credential the environment could see and review cloud audit logs from November 17 onward.
  3. Delete the hooks — agent_framework_meta.pth / af_runtime_diag.pth and their modules — uninstalling alone may not remove them.
  4. Pin and hash everything. Lockfiles with hashes (pip-compile --generate-hashes, Poetry, uv lock) are the only thing that catches a repacked wheel. A version pin alone would not have saved anyone here — 1.26.1 looked like a legitimate bump.
  5. Scan site-packages for .pth files in CI. There should be almost none, and every one should be explicable.

The agent era concentrates risk: the frameworks every AI builder installs first run on machines holding cloud keys and production credentials. Treat pip install with the same suspicion you give a stranger's shell script — as November 17 proved, that is exactly what it can be.

Sources: Wiz, JFrog, Orca Security (Nov 2026); exposure estimates are my own calculations. By Shivam Kumar, VisionQuantech.

Top comments (1)

Collapse
 
mateo_ruiz_6992b1fce47843 profile image
Mateo Ruiz •

The most concerning part here is that the attack moved below the application layer. Most dependency reviews focus on what a package imports or executes when a particular function is called. A malicious .pth hook changes that assumption because the payload runs at interpreter startup, including in tools developers may not associate with the compromised dependency.

I'd add one important step to the recovery process: treat every affected CI runner as compromised infrastructure, not just a machine with a bad package. Rebuild it from a clean image after rotating credentials, then review cloud audit logs for token usage and unexpected identity activity. Otherwise, removing the package and its hooks can leave behind an already-stolen credential with valid permissions.

This also makes least-privilege CI identities and short-lived credentials especially important. An OIDC token is convenient, but if a compromised process can request one, its permissions and trust conditions determine the blast radius.

Hash-locked dependencies help prevent unexpected artifacts, but they need to sit alongside trusted publishing, artifact provenance, isolated build environments, and outbound network monitoring. Supply-chain security can't stop at verifying the package version; it has to account for what the installation process is allowed to execute and access.