Why your AI agent invents packages, and how to stop it installing one
A short breakdown from Adam Rosler, AI engineer. The one you commented GUARD for.
What's happening
AI coding assistants sometimes recommend software packages that don't exist. A model writes one likely token (a word or piece of a word) at a time, so a made-up name can be built from pieces that each look right: "huggingface" + "-" + "cli" sounds exactly like a real tool, but nobody published a package by that name.
Researchers tested 16 popular code-generating models on 2.23 million package recommendations: almost one in five (19.7%) didn't exist. And the made-up names repeat: when the same question was asked ten times, 43% of the fake names came back every single time.
That's what attackers use. They collect the names models invent and publish real packages under them (this is called
"slopsquatting"). In 2024 a security researcher at Lasso Security uploaded an empty package called huggingface-cli
to see what would happen: it got over 30,000 downloads in three months, from people (and agents) who installed it
because an AI said to.
Why it matters
If your agent installs packages by itself, the attacker's code runs on your machine, with your keys and your files. Nothing looks wrong: the install succeeds and the name looks right.
What to do
- Check before installing. Does the package exist on its registry? Is it more than a month old? A name that doesn't exist, or appeared last week, gets blocked.
- Don't trust age alone. After a month, a squatted package passes that check too. So the last rule is simple: your agent never adds a new package on its own; it asks you, and shows you how old the package is, how many releases it has and where its homepage points.
- Turn on the setting your package manager already has (30 days is a sensible value):
- pnpm:
minimumReleaseAge: 43200inpnpm-workspace.yaml(minutes; recent pnpm already defaults to one day). - uv:
exclude-newer = "30 days"under[tool.uv]inpyproject.toml.
- pnpm:
- If you use Claude Code, a small pre-install hook can do steps 1 and 2 automatically (I can share mine).
Sources: Spracklen et al., "We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code
Generating LLMs" (arXiv 2406.10279; to appear at the 2025 USENIX Security Symposium); Bar Lanyado, Lasso Security, "AI package hallucinations"
(2024); pnpm and uv documentation. Checked 23 Nov 2026: PyPI still returns "not found" for huggingface-cli.
Unlock the full GUARD breakdown
Drop your email once to read the complete step-by-step guide, grab the files, and unlock all 96 Reel breakdowns on this device forever.