Microsoft's agent-framework on PyPI Was Hijacked: A .pth File That Steals Credentials on Every Python Launch

On 17 November attackers published agent-framework 1.26.1 and 1.26.2 to PyPI with a .pth startup hook that runs a credential stealer whenever Python starts, even if the package is never imported. JFrog warns that a bare pip uninstall triggers it again. What to check, how to clean up safely, and what to rotate.

4 min readAdvanced

Executive summary. On 17 November 2026 someone with the ability to publish to Microsoft's agent-framework package on PyPI (reportedly around 40,000 downloads a week) uploaded versions 1.26.1 and 1.26.2. They kept the clean 1.26.0 code and dependency pin intact, and added one tiny .pth file to site-packages. Python runs import lines inside .pth files at interpreter startup, so the payload executed every time Python launched on that machine, even if your code never imported the package. It collected credentials from environment variables, config files and cloud identity endpoints and sent them to an attacker endpoint; the second release added GitHub Actions OIDC targeting. PyPI quarantined 1.26.1 at about 21:06 UTC, roughly half an hour after it appeared, but the second upload followed within minutes. Detection was fast (Elastic says it flagged the package six minutes after publication), yet anyone who installed during the window is exposed. JFrog gives one critical clean-up warning: do not run a bare pip uninstall first, because pip is itself a Python program and triggers the hook again.

agent-framework .pth hijack flow

What it is

Field Detail
Package agent-framework (Microsoft) on PyPI
Bad versions 1.26.1 and 1.26.2 (uploaded 17 Nov 2026)
Last clean version 1.26.0
Mechanism A .pth startup hook: agent_framework_meta.pth in 1.26.1, af_runtime_diag.pth plus af_runtime_diag.py in 1.26.2
Trigger Any Python interpreter start in that environment, including pip
Targets Environment variables, config files, cloud identity endpoints; 1.26.2 adds CI/CD OIDC tokens
Root cause (per JFrog) A compromised publishing credential, not a breach of the build pipeline. Another vendor claims the releases used Microsoft's release-signing credentials, which we could not confirm

How it works

text
 Attacker with publish rights  ──►  uploads 1.26.1 / 1.26.2 to PyPI
          │   clean package code and dependency pin left in place
          ▼
 Wheel installs a .pth file into site-packages
          │   "import ..." lines in .pth files run at Python startup
          ▼
 Every python / pip / pytest / script launch runs the stealer
          │
          ▼
 Env vars, config files, cloud metadata creds ──► attacker endpoint

Why this design is nasty: a normal malicious package needs someone to import it. A .pth hook needs only that the package be installed in an environment that later starts Python, which describes every developer laptop, CI runner, notebook server and agent host. The attacker also kept the legitimate code working, so tests still passed.

Why it needs industry attention

AI agent tooling is a high-yield target. Agent frameworks live in the environments that hold model API keys, cloud credentials, GitHub tokens and CI secrets, all in one place. Malware that wins there wins broadly. This is the same pressure that makes AI control planes such as LiteLLM attractive. It is also a reminder that quarantining a version does not revoke the publishing credential: JFrog notes the attacker can simply push a newer version, which is exactly what happened.

What to do

  1. Check for the files without running Python. The stealer fires on any interpreter start, so use the file system, not pip:
bash
# Linux/macOS: look for the known hook files and any .pth file with executable import lines
find / \( -name "agent_framework_meta.pth" -o -name "af_runtime_diag.*" \) 2>/dev/null
find / -path "*site-packages*" -name "*.pth" -exec grep -l "^import " {} + 2>/dev/null
powershell
# Windows
Get-ChildItem C:\ -Recurse -Include agent_framework_meta.pth,af_runtime_diag.* -ErrorAction SilentlyContinue
  1. If found, do not start Python or pip yet. Delete the malicious files using the environment's own tooling that is not Python (file manager, rm), or run the interpreter only after the hook files are gone. Then reinstall agent-framework 1.26.0.
  2. Treat every reachable secret as stolen. Rotate cloud keys and tokens, GitHub and CI tokens, model API keys, database passwords and anything in the environment, from a clean machine.
  3. Review cloud and CI audit logs from 17 November for use of those credentials from unfamiliar addresses, and tighten GitHub Actions OIDC trust policies (restrict by repository, branch and environment).
  4. Pin and verify going forward: lockfiles with hashes (pip install --require-hashes), and a delay on brand-new releases (for example uv's exclude-newer), so a hijack has time to be caught before you install it.
  5. Reduce what a stealer can see: short-lived credentials, no long-lived keys in environment variables on build hosts, and egress filtering on CI runners.

How to detect it

  • .pth files containing import lines outside known tooling, and any file named agent_framework_meta.pth or af_runtime_diag.*.
  • Python processes making unexpected outbound requests at startup, especially to paste/webhook services or the cloud metadata endpoint.
  • Cloud and CI audit events using a credential from a new IP shortly after an install.
  • Package inventory: SBOM or dependency scans listing agent-framework 1.26.1 or 1.26.2 on any host or image.

Conclusion

The trick here is old (.pth hooks) but the target is new: the agent tooling that sits next to your most valuable secrets. Check by file system rather than by running Python, rotate everything reachable, and make "new release, wait a few days" the default for dependencies in environments that hold credentials.

Do this now: search hosts, images and CI caches for the hook files, remove them safely, reinstall 1.26.0, rotate all reachable credentials, and review audit logs from 17 November.

Related: Optimizely's supply-chain attack, our prompt-injection and AI agents threat model, and the Learn track on cloud security assessment.

Sources: JFrog Security Research, Socket, BleepingComputer, Elastic Security Labs, Orca Security. Timings and the credential's origin varied between vendors; JFrog and the PyPI record are authoritative.

HackersRoot Research · Research team

The HackersRoot research team investigates attack techniques across AI systems, cloud and identity, and enterprise networks, then publishes the detections and hardening guidance that stop them.

More from HackersRoot →

Related research

AI & LLM Security

MONAI Label CVE-2026-133968: AI Agents Went From API Map to Root in About 11 Minutes

MONAI Label is an open-source annotation server for medical imaging. CVE-2026-133968 is a CVSS 9.8 path traversal that Amazon Threat Intelligence says was exploited by autonomous AI agents, which went from mapping the API to arbitrary file write in about 11 minutes and a root reverse shell on a university server. Authentication is off by default and no fixed release shipped at disclosure.

AI & LLM Security

GPUStack CVE-2026-102895: Attackers Are Owning the AI Control Plane

GPUStack is an open-source GPU cluster manager for serving AI models. CVE-2026-102895 is a CVSS 9.8 improper-authentication flaw that lets a remote, unauthenticated attacker make requests look local, bypass authentication, become administrator, read worker and cloud secrets, and run code. It's exploited in the wild and on CISA KEV. The fix is 2.2.0 — but assume pre-patch compromise.