Subscribe
Supply Chain
5 min read

Your AI Coder Is Hallucinating Packages, and Someone Is Registering Them

Nineteen point seven percent of AI-recommended packages do not exist. Attackers now register the stable hallucinations on npm and PyPI, and coding agents install them without a human squinting at the name.

Mid-century Olivetti brochure style illustration: a robotic arm stamps a crate on a conveyor belt under the headline Your AI Invented That Package
Mid-century Olivetti brochure style illustration: a robotic arm stamps a crate on a conveyor belt under the headline Your AI Invented That Package

Nineteen point seven percent of the packages recommended by code-generating language models do not exist. That figure comes from the largest measurement to date: researchers generated 2.23 million Python and JavaScript code samples across 16 models and counted 440,445 that referenced at least one fabricated dependency, under 205,474 unique invented package names. The paper, "We Have a Package for You!", was presented at USENIX Security 2025.

A fake package name is only a bug when nobody claims it. Slopsquatting is what happens when somebody does.

From typo to hallucination

The term was coined by Seth Larson, developer-in-residence at the Python Software Foundation, and popularized by Andrew Nesbitt of Ecosyste.ms. Typosquatting bets on human fingers slipping (reqeusts for requests). Slopsquatting bets on models inventing names outright: the LLM confidently recommends a library that never existed, an attacker registers that exact name on npm or PyPI, and every future developer, or agent, who follows the suggestion installs whatever is waiting there.

The attack works because model hallucinations are not random. When the USENIX researchers re-ran 500 hallucination-triggering prompts ten times each, 43 percent of the fake names reappeared on every single run and 58 percent appeared more than once. An attacker only needs to prompt a popular model with common development tasks, log the invented names, and register the stable ones. The names are also engineered by construction to look ordinary. Only 13 percent were off-by-one typos of real packages. Thirty-eight percent were conflations of two genuine libraries, and 51 percent were pure fabrications that merely sounded plausible in context. Cross-registry confusion adds a cheap shortcut: 8.7 percent of the hallucinated Python package names already existed as npm packages.

Rate varies enormously by model class. Open-source models hallucinated an average of 21.7 percent of recommendations; commercial models averaged 5.2 percent. CodeLlama 7B and 34B exceeded a third. GPT-4 Turbo performed best in the study at 3.59 percent. Those numbers were measured against 2025-era releases, and current models are almost certainly better. "Better" is not the same as safe, because at the scale AI-assisted coding now operates, even a low single-digit rate yields thousands of predictable, registerable names per day.

A shelf of identical crates with one dashed outline where a box is missing, and a hand reaching for the gap

The cases are no longer hypothetical

The Cloud Security Alliance's April 2026 research note catalogs confirmed exploitation. The npm package unused-imports (models conflate it with the legitimate eslint-plugin-unused-imports) carried a malicious payload and, despite an npm security hold, was still recording roughly 233 downloads a week as of February 2026. The name huggingface-cli does not describe a real PyPI package, but Alibaba pasted an AI-recommended install command for it into the README of a public repository, and the squatted package accumulated more than 30,000 downloads in three months. The researcher who registered a test version, Bar Lanyado, has said the lesson was distribution: a harmless placeholder got corporate-scale install volume with zero friction.

The react-codeshift case matters most for teams shipping agent-written code. Security researcher Charlie Eriksen traced it through 237 repositories via AI-generated agent skills, with downloads arriving not from humans copying code but from autonomous agents executing the outputs they had just generated.

That is the structural change. Typosquatting always had a human in the loop who might squint at a misspelling. An agent asked to add a rate limiter generates code, reads its own import statement, resolves the dependency, and runs pip install without ever looking up at the name. The post-install script then executes in an environment that typically holds cloud credentials, Git tokens, and model API keys. Andrew Nesbitt's April 2026 post on package security for AI agents makes the point bluntly: the checkpoint was never the tool, it was the person.

A conveyor belt stamping crates roll past an empty inspection chair, no human at the desk

The flood that followed the models

Slopsquatting landed on registries that were already losing ground. Phoenix Security threat intelligence counted 37 distinct supply chain campaigns and 497 cataloged malicious packages across npm and PyPI in the first half of 2026 alone: 2.6 times the campaign count and 4.5 times the package volume of the entire preceding year, according to the CSA's June note on registry systemic risk.

The August 2026 campaign tracked as WEL1DROPPER (Sonatype: "Flooding Dropper") showed what industrialized naming looks like: roughly 800 malicious npm packages published in a 48-hour window, with the count growing past 1,000, their names generated by interpolating generic fragments like "bigops" and "bnpl" into plausible-looking libraries, in the same register as model hallucinations. Researchers call it AI slopsquatting. The campaign also sidestepped the industry's favorite control: the packages avoided preinstall and postinstall lifecycle hooks entirely and shipped README instructions to require() the module, executing the payload at import time, which --ignore-scripts does not stop. One payload chain delivered a remote-access trojan and infostealer to Windows, macOS, and Linux.

The registries respond, slowly

npm and PyPI both publish first and remediate second. PyPI fielded over 2,000 malware reports in 2025 and achieved a median removal time of 39 hours, an eternity for a self-propagating worm. The defensive improvements are real: PyPI mandated two-factor authentication for critical maintainers and reported over 50,000 projects using trusted publishing by end of 2025 (more than 20 percent of file uploads); GitHub made 2FA mandatory for npm publishing with granular tokens capped at seven-day lifetimes; PyPI now refuses new file uploads to releases older than 14 days, closing the retroactive poisoning channel used in the LiteLLM compromise. None of this reviews a package before publication. In May 2026, the Mini Shai-Hulud worm put out 171 compromised packages carrying valid SLSA Build Level 3 attestations, proof that the integrity labels themselves can be laundered through a compromised CI pipeline.

There is no pre-publication gate coming soon. Registries are small, underfunded teams, as The Register reported in February 2026, and the volume of new packages keeps climbing with AI-generated code: PyPI alone added roughly 130,000 new packages in 2025, nearly matching its cumulative total through 2018.

What actually helps

The CSA recommendations read like a checklist, but each item closes a real observed gap. Treat every AI-generated import or dependency line as untrusted input: verify the package exists on the target registry, check the registration date and publisher history before first install, and flag anything registered in the last 30 to 90 days for human review. Commit lockfiles and install from known-good hashes so a name claimed later cannot silently change payload. Gate agents: an allowlist for package installs, or human review for anything off it, is the minimum for any agent with shell access. Disable lifecycle scripts where possible, and remember import-time execution defeats that control, so isolate build environments and keep long-lived secrets out of them.

The encouraging note from the USENIX work: GPT-4 Turbo and DeepSeek could correctly identify over 75 percent of the fake package names they had themselves just generated. The models can usually check their own homework. Almost no tooling makes them do it before npm install runs.

Sources

Supply ChainSecurityAI CodingAnalysis