WisyLink Blog

phantom packagespackage hallucinationslopsquattingsoftware supply chain securityAI-generated code

Phantom Packages: The Supply Chain Risk in Generated Code

Phantom packages are dependencies AI code invents, and attackers can register the names. See how often it happens and how to verify packages before install.

9 min read
Phantom Packages: The Supply Chain Risk in Generated Code

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:

Phantom packages and related supply chain attacks
AttackWhat the attacker exploitsExampleMain defence
SlopsquattingA name an AI model inventsRegistering a plausible library name a model keeps suggestingVerify existence and history before install
TyposquattingA person's typing mistakeA package one letter away from a popular oneCopy names from official docs; review diffs
Dependency confusionAn internal package name published publiclyA public package that shadows a private oneScoped names and a private registry
Account takeoverA real package's maintainer accountA malicious update to a trusted libraryLockfiles, 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:

  1. Harvest names. The attacker asks popular coding assistants common programming questions and records every package name that doesn't exist on the registry.
  2. Keep the repeaters. Names that come back across many runs and phrasings are the valuable ones, because real users will be shown them too.
  3. 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.
  4. 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:

  1. List new dependencies separately. Before running anything, pull every package name out of the generated code so none hides in the volume.
  2. Find the official source. Open the library's own documentation or repository and copy the package name and install command from there.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

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.

Frequently asked questions

What does slopsquatting mean?
Slopsquatting is registering a package name that AI models tend to invent, so that people who follow the model's suggestion install the attacker's code. The word blends "AI slop" with typosquatting, the older trick of registering misspellings of popular packages. It came into use in April 2025 and is credited to Seth Larson, security developer-in-residence at the Python Software Foundation.
Is it safe to install packages suggested by an AI coding assistant?
It is safe once you have checked them, and risky if you haven't. In the USENIX study, even the best-performing model, GPT-4 Turbo, suggested non-existent packages 3.59% of the time, and open-source models did so far more often. Newer models may do better, but no model's suggestion is proof that a package exists or is the one you meant.
How can I tell if an npm or PyPI package is legitimate?
Begin with the library's official documentation and copy the install command from there. For npm, the npm view command prints a package's version list, publish times and repository URL; on PyPI, the project page shows the release history. Then open the linked repository and confirm it is real, active and refers back to the same package name. A repository link that is missing or leads elsewhere is a warning sign.
Do lockfiles protect against phantom package attacks?
Partly. A lockfile records exactly which packages and versions were installed, and npm ci refuses to change it, so it prevents silent drift later. It doesn't help at the moment someone adds a new dependency, which is exactly when a phantom name gets in. Combine lockfiles with a review step for every newly added package.
Do newer AI models still hallucinate package names?
The published measurements describe the models tested at the time, mostly early 2024, and rates differ widely between models. Expect newer models to be better but not perfect, and expect rates to rise for niche libraries, recent releases and less common languages, where training data is thin. The verification habit costs little and doesn't depend on which model you use.
What should I do if I installed a package that turns out to be fake?
Remove it and stop using the machine or build environment for anything sensitive until you've checked it. Rotate any credentials it could have read, such as API keys, tokens and environment variables. Review what its install scripts did, rebuild affected environments from a clean state, and report the package to the registry's security team so others are protected.
Share