Microsoft's agent-framework PyPI compromise: how a startup file ran code without an import
Two malicious agent-framework releases ran a credential stealer through Python startup files. The exact timeline, the .pth mechanism, and what the published analyses recommend.
On 17 November 2026, two malicious versions of the agent-framework package, Microsoft's open-source toolkit for building AI agents, appeared on PyPI. GitHub's advisory database and several security firms say the added credential stealer did not need the package to be imported. It ran the next time a Python interpreter started in an environment where the package was installed. This guide explains the startup mechanism behind that, what independent analyses report the code collected, and what they recommend if either version reached your machines. It is a summary of other people's published analysis. We did not install, download, run or reverse-engineer the malicious files ourselves.
The timeline, with the right anchors
- 12 November, 18:24 UTC: the last clean release, 1.26.0, shipped normally, five days before the incident.
- 17 November, 20:35:20 UTC: version 1.26.1 was uploaded, as a wheel only.
- 17 November, 21:06:16 UTC: PyPI quarantined 1.26.1.
- 17 November, 21:08:39 UTC: version 1.26.2 was uploaded, two minutes and 23 seconds after the first quarantine, and was itself quarantined at 21:16:44.
Early coverage rounded these differently, which produced an apparent disagreement: the two uploads were 33 minutes apart, while the second upload came about two and a half minutes after the first release was quarantined. Both statements describe the same sequence; they measure from different anchors. StepSecurity's analysis of the release history gives the exact times above. The second upload after a quarantine shows the attacker still had publishing access at that moment. It does not establish whether that access remained afterward.
BleepingComputer describes the package as having roughly 200,000 monthly downloads; Elastic puts the average at 196,000 across all versions. That is the package's overall popularity, not a count of installs of the two malicious versions.
How the attacker got in: one researcher's evidence, still attributed
GitHub's advisory says the activity has not been attributed to a known campaign. Wiz published the most specific account on 18 November: by watching the attacker-operated tooling report its own progress to the same public webhook endpoint used for exfiltration, Wiz says the attacker appears to have used a compromised client certificate and private key for Microsoft ESRP, the internal service Microsoft uses to sign and publish this package. Wiz reports that a first publish attempt from AWS was rejected by ESRP's IP filtering and a second from Microsoft-owned IP space succeeded. How those credentials were obtained is not known, and Microsoft had not publicly confirmed this mechanism when these analyses were written. Treat it as Wiz's evidence-based finding, not an established root cause.
StepSecurity adds registry-side observations: both malicious wheels carried the uploader user-agent RestSharp/106.13.0.0, shipped without the provenance attestation or source distribution the clean release had, and a newly created maintainer account was added to the project on 17 November. Those are indicators, not proof of the full access path.
Why installing meant the code would run, at the next Python start
The trigger is not the install step itself and not an import agent_framework in your code. Each wheel placed a .pth file in the environment's site-packages directory. Python's site module, which runs automatically at interpreter startup unless started with -S, reads .pth files in the site directories it processes. Lines in a .pth file that begin with import are executed, and per the Python documentation they run at startup regardless of whether a particular module is going to be used.
Version 1.26.1 shipped agent_framework_meta.pth containing import agent_framework_meta, with a loader appended to that package's initializer calling the collector in _telemetry.py. Version 1.26.2 moved to af_runtime_diag.pth importing a standalone af_runtime_diag.py, and restored the package initializer byte-for-byte to the clean 1.26.0 content, so checking only the initializer misses it. The collector sets an environment marker, forks and detaches on Unix (a daemon thread where fork is unavailable), suppresses all errors, and runs while the parent interpreter continues normally. A later launch of pytest, a build script, a linter or pip in that environment is enough to start it.
Original diagram by Omnistu from the StepSecurity, Socket and GitHub descriptions. Not a figure from any source.
Two precision notes. First, exposure follows the site-packages directories the interpreter actually processes: installing into one virtual environment does not by itself affect every other environment sharing a base interpreter. Second, this behavior is version-dependent: current Python 3.15 documentation deprecates import lines in .pth files and introduces .start entry-point files that take precedence when a same-named pair exists. The mechanism described here is the behavior of released Python versions up to 3.14, documented in the Python 3.14 site reference.
What the code reportedly collected
According to the GitHub advisory, Socket, StepSecurity and Wiz, which performed full static analysis of both quarantined wheels, the collector gathers:
- host context: hostname, user, working directory, command-line arguments
- environment variables whose names contain strings such as TOKEN, SECRET, PASSWORD, KEY, AZURE, AWS, GITHUB, OPENAI, NPM or PIP, 31 substrings in 1.26.1 and 35 in 1.26.2
- the environments of up to 300 other processes via
/proc/*/environ, where permissions allow - credential files matching dozens of glob patterns: Azure CLI caches, pip.conf, .npmrc, .netrc, .git-credentials, Docker config, Hugging Face tokens, Azure DevOps agent credential files and application .env files, capped at 60 files in 1.26.1 and 80 in 1.26.2
- fresh identity tokens: Azure managed-identity tokens from IMDS or App Service endpoints for twelve resource audiences, Azure DevOps OIDC tokens, and in 1.26.2 GitHub Actions OIDC tokens for Azure token exchange audiences
The data is compressed with zlib, base64-encoded and sent in one HTTPS POST to a single webhook.site URL stored base64-encoded in both versions. The encoding hides the address from casual inspection but is not encryption, and the inspected payloads contain no second-stage downloader, retry loop or separate persistence mechanism beyond the .pth hook itself.
How much was actually taken: what one researcher observed
webhook.site is a public request-inspection service, and Wiz was able to read the requests stored on the attacker's free-tier URL. It counted 50 requests: four from the attacker's own machines, 29 that appear linked to sandbox environments, vendor scanning and tests, and 17 representing what it assesses as three unique, successful cases of victim data exfiltration. That is Wiz's read of one endpoint's retained requests, not a total victim count: the free tier caps stored requests, and nothing here shows how many environments ran the payload.
If either version reached your environment
The published guidance is unusually specific about ordering, and the order matters:
- Isolate first. StepSecurity warns not to begin with
pip show,pip uninstallor any Python inspection command in the affected environment, because interpreter startup can run the hook again. Isolate hosts, containers and runners from the network and preserve installation records, process information and logs with trusted tooling. - Rebuild rather than clean. Replace the environment or image from a known-clean base pinned to
agent-framework==1.26.0, and block 1.26.1 and 1.26.2 in package controls. Removing the hook file alone does not stop an already-detached collector process, and registry quarantine does not remove copies already downloaded into caches or images. - Rotate from a clean system. Treat every credential the payload could read or request as potentially exposed: CI and GitHub Actions secrets, cloud keys, package-registry, Docker, git and Hugging Face tokens, Azure CLI caches and service connections. That is a containment assumption, not proof every secret left the host.
- Review identity paths, not just static secrets. Audit GitHub OIDC permissions, Azure federated credentials, Azure DevOps service connections and managed-identity role assignments for the exposure window. Disabling a trust does not revoke tokens already issued, and rotating a static secret does not invalidate a token already minted from it.
- Hunt egress precisely. Search proxy and DNS logs for the exact webhook UUID path and the user-agents
af-runtime-diagnostics/1andruntime-diagnostics/1. A connection to the shared webhook.site domain alone is not incident-specific, and a blocked request does not prove earlier runs were safe.
What this does and does not establish
This is one package, two versions, and a general packaging lesson the Python documentation supports: code placed in the right configuration file runs at interpreter start without an import. StepSecurity's check of related satellite packages found no uploads after 12 November at the time it looked, which is not a blanket all-clear for the whole family. Version pinning and dependency review are common practice, but the sources do not claim either would have prevented this specific compromise of the official project. This guide was prepared with AI assistance and reviewed on 19 November 2026.
Sources
- StepSecurity, "Microsoft agent-framework PyPI Package Compromised" (18 November 2026, full static analysis of both wheels)
- GitHub Advisory Database, GHSA-764m-3ppc-5m73, "Malicious code in agent-framework (PyPI)"
- Wiz, "Microsoft agent-framework Compromised: Credential Stealer Targets Azure and CI Pipelines" (17 November 2026, updated 18 November)
- Socket, "Microsoft's agent-framework PyPI package Compromised with Credential Stealer" (17 November 2026)
- Elastic Security Labs, "We caught the agent-framework PyPI compromise six minutes after it published" (18 November 2026)
- BleepingComputer, "Microsoft's Agent Framework PyPI package compromised to steal credentials" (18 November 2026)
- Python 3.14 documentation, "site: Site-specific configuration hook"