A phantom package is a software dependency that AI-generated code names but that doesn't actually exist. The danger starts when an attacker registers that name on a public registry such as npm or PyPI, a technique called slopsquatting, so the next developer who installs the suggested package runs the attacker's code.
- In a USENIX Security 2025 study, 19.7% of packages referenced in 576,000 generated code samples did not exist.
- The invented names repeat: 43% came back in all ten re-runs of the same prompt, which makes them predictable targets.
- Most are not typos of real names, so typo checks alone won't catch them.
- The defence is a habit: confirm that every new dependency exists, is the one you meant and has a real history before installing it.
- Lockfiles, signature checks and human review narrow the window; agents that install packages on their own widen it.
- Hosted app builders keep installs off your own machine, but testing what the app does is still your job.
What is a phantom package?
A phantom package is a dependency that a code-generating model presents as real when no such package has been published. Researchers call the behavior package hallucination. The model gives no signal of doubt: the import line, the install command and the function calls look exactly like those for a real library, because the model is predicting likely text, not checking a registry.
The invented names are plausible for a reason. In the code and discussions models learn from, package names follow recognisable patterns: a vendor or topic, then a function, then a suffix such as -utils, -client or -cli. Asked for help with a niche task, a model can produce a name that fits the pattern perfectly and corresponds to nothing. Libraries that were renamed, retired or only ever mentioned in issue threads add more names that look real.
On its own, a phantom name is just an error. The install fails and the developer moves on. It becomes a supply chain risk when someone fills the empty name. Registries like npm and PyPI let anyone publish under an unclaimed name, so an attacker who knows which names models invent can register them and wait. From then on, the install succeeds, and the code that runs is theirs.
It helps to separate this from related attacks, because each needs a different defence:
| Attack | What the attacker exploits | Example | Main defence |
|---|---|---|---|
| Slopsquatting | A name an AI model invents | Registering a plausible library name a model keeps suggesting | Verify existence and history before install |
| Typosquatting | A person's typing mistake | A package one letter away from a popular one | Copy names from official docs; review diffs |
| Dependency confusion | An internal package name published publicly | A public package that shadows a private one | Scoped names and a private registry |
| Account takeover | A real package's maintainer account | A malicious update to a trusted library | Lockfiles, signatures and provenance checks |
How often does AI invent package names?
The largest study so far is "We Have a Package for You!" by Joseph Spracklen and colleagues, presented at the 2025 USENIX Security Symposium. The team generated 576,000 Python and JavaScript code samples with 16 code models and checked every referenced package against the registries. Of the package references, 19.7% pointed to packages that don't exist, covering 205,474 unique invented names.
Rates varied widely by model. Commercial models hallucinated at least 5.2% of packages on average, open-source models 21.7%, and the best performer, GPT-4 Turbo, 3.59%. These were the models leading the rankings in early 2024; newer models may do better, and you should treat the figures as a description of the risk, not a current scoreboard.
One detail matters more than the headline rate. The researchers measured how far each invented name was from the nearest real package. Only 13.4% were one or two characters away, and 48.6% differed by six characters or more. The authors conclude that most hallucinations are not simple typos. A tool that only flags near-misspellings of popular packages will miss most phantom names.
Why do repeated phantom names become targets?
If every invented name were random, an attacker would have little to aim at. They aren't. When the researchers re-ran the same prompts ten times, 43% of hallucinated packages appeared in all ten runs, and 58% appeared more than once. Models follow probability, so similar questions produce similar wrong answers. That consistency turns a one-off mistake into a predictable address.
The idea has been demonstrated in public. In 2024, security researcher Bar Lanyado of Lasso Security noticed models repeatedly recommending a package called huggingface-cli, a name that didn't correspond to the official tool's install command. He uploaded an empty, harmless package under that name to PyPI and, as reported by The Register in March 2024, counted more than 15,000 downloads in three months. A README in an Alibaba research repository even told readers to install it. He reported finding no malicious use of the technique, but the experiment showed how little effort it takes.
The security community now treats this as a known risk. The OWASP Top 10 for Large Language Model Applications (2025 edition) lists "insecure or non-existent code libraries" under unsafe code generation, and one of its example attack scenarios is exactly this: attackers find commonly hallucinated package names, publish malicious packages under them, and wait for developers to install them.
How does a slopsquatting attack work?
The attack needs no access to the victim's systems, only patience. Following the scenario OWASP describes, it runs in four steps:
- Harvest names. The attacker asks popular coding assistants common programming questions and records every package name that doesn't exist on the registry.
- Keep the repeaters. Names that come back across many runs and phrasings are the valuable ones, because real users will be shown them too.
- Register and disguise. The attacker publishes packages under those names. A plausible description, or even working code, keeps a quick glance from finding anything wrong.
- Wait. Developers, or agents acting for them, install the suggested package. Malicious code can run through install scripts or on first import, with access to whatever that machine or build environment can reach: tokens, environment variables, files.
Two features make this hard to spot afterwards. The victim chose the package, so nothing feels like an intrusion. And because the name never belonged to a legitimate project, there is no original to compare against: no change of maintainer, no suspicious new version of a familiar library. Detection has to happen before installation, at the moment the name is accepted.
Where does trust in generated code slip?
The slip happens when the code is read, well before anything is installed. Fluent, well-formatted output feels verified. People ask fewer questions of a confident source, and generated code almost never expresses doubt, so scrutiny is weakest exactly where it is needed.
Scale makes it worse. One suggested package is easy to check; one unfamiliar name inside 400 generated lines doesn't stand out. When review feels expensive, it is the first step skipped. Inheritance adds a third slip: once an unverified dependency is in the project, the next generation treats it as established and builds on top of it.
The fourth slip is the newest. Coding agents can now run commands themselves, including install commands, with nobody reading the name in between. That is a large part of why tool-using agents need tighter guardrails than chat assistants, and why accepting whatever the model produces, the risk our essay on the discipline and limits of vibe coding discusses, is most dangerous at the dependency line.
How to check a dependency before installing it
Verification means testing a package's reality instead of assuming it. A short, fixed routine is enough for most projects:
- List new dependencies separately. Before running anything, pull every package name out of the generated code so none hides in the volume.
- Find the official source. Open the library's own documentation or repository and copy the package name and install command from there.
- Check the registry page. Confirm the exact name, a linked source repository with real history, several releases over time, named maintainers and believable download numbers.
- Stop on red flags. A package first published days ago, with a single version, no repository or a description that doesn't match its name, gets escalated to a human decision.
- Pin what you accept. Commit the lockfile and install with
npm ci, which requires an existing lockfile and never writes to it, so builds can't pick up surprises. - Verify signatures. Run
npm audit signatures, which checks the registry signatures and provenance attestations of downloaded packages, or the equivalent for your ecosystem.
None of these steps slows real work much. Together they move trust from the tone of the output to evidence about the package.
Team habits that keep phantom names out
Checklists work when they become defaults. Teams that handle this well make the safe path the easy one:
- Fail the build when a new dependency appears without a recorded review, so adding a package is always a deliberate act.
- Keep an approved list or an internal mirror of vetted packages, and point tools and agents at it.
- Tell the model which libraries it may use, or ask it to prefer the standard library, so fewer new names appear at all.
- Give coding agents permission to suggest installs but not to run them unattended.
- Treat a rejected dependency as a good catch worth sharing, not as wasted time.
- Package hallucination
- A model referencing a package that has never been published.
- Lockfile
- A file that records the exact versions installed, so every later install reproduces them.
- Provenance
- Verifiable information about where and how a package was built and published.
Dependency checks are one part of a broader habit of verifying what was generated, the theme of our piece on eval discipline, and unexamined dependencies are a textbook source of the intent debt that builds up when generated code outpaces understanding.
Where WisyLink fits if you don't write code
If you use a code-first AI tool, you are the one running installs, so everything above applies to you directly. Our comparison of vibe coding tools and AI app builders covers what each approach leaves you to manage, packages included.
With WisyLink you describe the app in a chat and never run an install command on your own computer. An isolated build agent writes the app. It has no standing access to your account, your credentials or other sites, and each site runs on its own compute. That limits how far a problem could reach.
A good question to ask of any AI tool is who runs the install, where it runs, and what that code could reach. With a code-first tool, the answer is usually you, on your own laptop, with access to everything on it. With a hosted builder such as WisyLink, it is the platform, in a separate build environment. Neither answer replaces your part of the job: test what the app does before launch, keep payment and email keys under Integrations rather than in the chat, and check that the behavior matches what you asked for.
The product page explains how sites are isolated and deployed. When you want to build without managing dependencies yourself, start free and describe your first app.
F.A.Q.
