Kevin ScheerenBlog

· 7 min read · Deutsch

The package didn't exist, so why was the failed install the better one?

A coding assistant's script imported a package that didn't exist, so the install failed. The next time, it worked, and that was worse. How can a working install be the bad outcome, and why does checking each name against the list of known packages on PyPI or npm not settle it?

The script and the package package-a are an illustration, not a real incident. The numbers come from one study, "We Have a Package for You!" by Spracklen and others, listed on arXiv as "To appear in the 2025 USENIX Security Symposium". It tested code-generating models against the Python registry PyPI and the JavaScript registry npm.

Why the question exists

Python and JavaScript projects pull their libraries from central registries. The study names PyPI and npm as the two most popular, and points to what makes them useful and risky at once: "anyone can upload new code packages/libraries".

It calls the problem a package hallucination: a model "generates code that recommends or contains a reference to a package that does not actually exist". On its own, that is a failed install. The rest of this post is about what turns it into something else.

Step 1: how often models make up names

The researchers ran 16 code-generating models, commercial and open-source, on two sets of prompts. They took the package names out of each answer and compared them with a master list of all names on PyPI and npm, taken on 10 January 2024. "If a package name is not on the master list, it is considered a hallucination." The totals from the paper:

code samples generated            576,000packages named in them          2.23 millionof those, not on the list         440,445   (19.7 %)distinct made-up names            205,474average rate, commercial models     5.2 %average rate, open-source models   21.7 %

The abstract calls both averages a minimum ("at least").

So the 205,474 is a count of different names, each counted once, however often it appeared.

Step 2: the names come back

A made-up name that appears once and never again would be noise. The study tested that. It took 500 prompts that had produced a made-up name and asked each one again ten times:

came back in all 10 repeats       43 %never came back                   39 %came back more than once          58 %

The paper's reading: most hallucinations "are not simply random errors, but a repeatable phenomenon". The 43 % is a share of the made-up names from those 500 prompts; it is not "43 % of the time".

The repeats are mostly tied to one model. Across models, "81% of hallucinated packages are generated by only one model". That is why the reel says "the same assistant": the same model, asked the same kind of question, tends to give the same made-up name.

Why a name that comes back matters

A name that keeps coming back is a name worth registering. The paper describes the attack in one sentence: an adversary publishes "a package to an open-source repository with the same name as the hallucinated or fictitious package and containing some malicious code/functionality". The next people who get the same answer install it.

The researchers did not do this themselves. Publishing packages under made-up names was, in their words, a step "we chose not to pursue for ethical reasons".

The second case: the careful developer

Say the next developer is careful. Before installing anything an assistant suggests, they check every name against the list of known packages.

On day one, the check works. It is the same test the study used to find the made-up names: not on the list, so not real. The install never runs.

But the list is the registry, and the registry takes new names. The paper puts it plainly: comparing a generated name with a list of known packages is "ineffective for detecting a package hallucination attack, as an adversary may already have published the hallucinated package with malicious code". In its section on defences, it calls this kind of filtering "ineffective as a defense strategy, as an attacker could immediately publish a hallucinated package to the repository and be subsequently included in the 'allow' list."

The test: change one thing

Keep the developer, the assistant, the prompt and the made-up name the same. Change only one thing: a stranger registers package-a.

  • Before: the install fails, and the list check says "not on the list".
  • After: the install works, and the list check says "on the list".

Both signals asked the same question, whether the name exists, so both flip together. That is why the failed install was the better outcome. While the name was empty, every check said no. Once it was filled, every check said yes, and the code that arrived was a stranger's.

The paper adds one more line that applies here: "the mere presence of a package in an open-source repository does not confirm its credibility."

What "real and known" can mean

The reel ends: before you install a package an assistant suggests, check that it's real and known. The study supports the second word more than the first. Existence alone is what the stranger can fake. A curated list of "known good packages", picked by a measure such as popularity, "would be a more effective method", the paper says, though it still calls that approach "blunt and reactive", because the list needs constant checking and updating.

The study also tested ways to make the models produce fewer made-up names in the first place, and reports that they "significantly reduce the number of package hallucinations while maintaining code quality". The abstract speaks of a reduction, not of zero.

What this does not show

  • Models, not agents. The study tested code-generating models answering prompts. It did not test agents that run installs on their own. "Coding assistant" is the example's word.
  • Snapshot numbers. The rates come from the models and the registry lists the study used, with the master list taken on 10 January 2024. How newer models score, the paper cannot say.
  • No measured attack. The study did not publish packages under made-up names, so it measures the opening, not how often someone has used it.
  • The stand-in name. package-a is a placeholder. Whether a real package of that name exists was not checked.
  • A known package can still be bad. Popularity is a better filter than existence, by the paper's account, and it is still a filter, not a proof.

Get the next explainer

Every reel on this site gets a post like this one: the example worked through, with sources and limits. Until the next one: before you install a package an assistant suggests, check that it is known, not only that it exists.

If you would like the next post by email, sign up below. You will first get an email with a confirmation link; you are only on the list after you click it, and every email has a link to unsubscribe.

Sources

Both pages last opened on 1 December 2026, after arxiv.org's robots.txt, which allows /abs and /html; its crawl delay of 15 seconds was kept.