Installing a package is executing code. That has been true of the Python ecosystem for as long as anyone has used it seriously, and yet most organisations still treat pip install as though it were a file copy. The analysis of the LiteLLM 1.107.0 compromise is a reminder that the gap between those two mental models is where attackers live — and that the component involved, an LLM gateway, is about the worst place in a modern estate to lose that argument.
Microsoft Threat Intelligence has published a breakdown of the incident covering the use of Python startup hooks, credential theft and remote code loading, along with detections and mitigations. I'd encourage anyone running AI infrastructure to read the original. What I want to talk about is why this particular shape of attack is so effective against the way most teams actually operate.
Startup hooks are not a clever new trick — that's the point
Python deliberately provides places where code runs before anything you wrote does. The site module processes sitecustomize and usercustomize at interpreter startup, and .pth files in site-packages can carry lines that execute on import. These are documented, legitimate features, used by perfectly innocent tooling for path manipulation and environment setup. That's exactly what makes them good tradecraft.
Code placed in a startup hook runs in every interpreter invocation in that environment. Not just the application you were worried about — your test runner, your ad-hoc script, your CI job, your engineer's interactive shell. It runs before your application logging is configured, before your tracing is initialised, and it inherits whatever environment variables happen to be present at the time. If your security model assumes malicious code announces itself by doing something visible inside the application, a startup hook sits comfortably underneath that assumption.
The second half — remote code loading — compounds it. A small, boring-looking stub that fetches and executes a payload at runtime means the artefact you scanned, hashed and approved is not the code that ultimately runs. Static review of the package tells you less than you think. This is why egress control from build agents and runtime workloads keeps turning up in post-incident recommendations: it is one of the few places you can break the chain without having to spot the stub in the first place.
An LLM gateway is a credential concentrator
LiteLLM exists to put one interface in front of many model providers. Architecturally that's sensible — it centralises routing, rate limiting, cost tracking and key management. Operationally it means the process holds, or has access to, provider API keys for several services at once, usually via environment variables or a mounted secret. Compromise the process and you compromise the lot.
This is a pattern worth naming, because the AI gateway is not the only example. Any component whose job is to broker credentials on behalf of other systems — a CI runner, an integration platform, a secrets-injecting sidecar — carries the same concentration risk. The difference with AI tooling is that it has been adopted at speed, frequently by teams who are not the ones who normally run production services, and often with keys that carry real spend attached. Stolen model-provider keys are directly monetisable. There is no need for the attacker to work out what to do with them.
[AUTHOR: add a real example from your own work here, if you have one, about where AI tooling landed in your estate relative to normal change control.]
Pinning is necessary and not sufficient
The standard advice after any supply chain event is to pin versions. You should — but pinning to a version number only protects you from drift, not from a malicious release of the version you pinned to. The unit of trust needs to be the artefact, not the label: hash pinning, a lock file that records digests, and an internal mirror or proxy that holds the approved copy so that a later change upstream doesn't silently become your dependency.
There's also a timing problem that pinning makes worse. Teams who pin aggressively and upgrade rarely are protected from a bad release for a while — and then adopt it months later, long after the noise has died down, because the advisory had scrolled off everyone's feed. Pinning without a process for consuming advisories against your pinned set is just delayed exposure.
What to actually check this week
- Inventory. Find every environment running LiteLLM and establish the exact installed version and when it was installed. If you can't answer that from a system of record, that's a finding in itself.
- Startup hooks. Enumerate sitecustomize.py, usercustomize.py and .pth files in your site-packages directories and container images, and compare against what should be there.
- Credentials. Treat every key, token and connection string reachable from the affected process as compromised. Rotate, then check provider-side usage and billing for anomalies.
- Egress. Review what outbound connections that workload is permitted to make, and whether anyone would have noticed an unexpected one.
- Images. Rebuild rather than patch in place, and confirm the rebuild pulls from a controlled source.
Detection is mostly about knowing what normal looks like
Detections for this class of attack rely on a baseline: an interpreter process making network connections it has never made before, a package directory changing outside a deployment window, a child process spawned from something that should never spawn one. None of that is exotic, and all of it is useless without an idea of the expected state. If your AI workloads were stood up outside the normal provisioning path, they probably aren't in your EDR coverage, your log pipeline or your configuration baseline — which means the detections in the Microsoft write-up will fire for other people and not for you.
The governance point, stated plainly
Nothing here is specific to AI. It is dependency hygiene, secret management, egress control and asset inventory — the unglamorous disciplines that every mature estate claims to have and many apply unevenly. What AI adoption has done is create a fast-moving class of production-adjacent services that frequently bypassed all four, because the people standing them up were experimenting and the experiment quietly became load-bearing.
My view is that the useful response to this incident is not a scramble for one package version. It's to ask which AI components in your estate hold credentials, who approved them, how they get updated, and whether anyone would see it if they started talking to somewhere new. If those questions are uncomfortable, the next compromised release will be considerably more expensive than this one.
Source: Inside the LiteLLM 1.107.0 supply chain compromise: Credential theft through Python startup hooks