Homeglossary

What is Package Hallucination?

Package hallucination is when an AI coding tool recommends installing a software package, a reusable library of code, that does not actually exist. It matters because a made-up package name is not just a dead end: attackers watch for the names AI invents, register real malicious packages under those names, and wait for someone to install them on the AI's advice.

Build with AI safely by knowing what to watch for.

How package hallucination works

An AI model suggests packages by predicting plausible names from the code it learned on. When it isn't sure, it can produce a name that sounds real but was never published, like a tidy, sensible-looking library that simply doesn't exist. Normally installing it just fails. The danger comes when attackers notice the same invented names appearing again and again in AI output, then publish actual harmful packages under those exact names. This attack has a nickname, "slopsquatting," and it turns a harmless-looking install command into a way to run someone else's code inside your project.

Package hallucination example

Say an AI tells you to install a package to handle image uploads, with a clean, believable name. You run the install and it works, so you trust it, but the real library never existed under that name; someone registered it after spotting the AI recommending it. Now their code is running in your app. The safe habit is to verify any unfamiliar package on its official registry and confirm its genuine before installing.

Frequently Asked Questions

Your Questions, Answered

This will automatically populate, don't change

Don't change this element unless you know what you are doing

Start Building
on Emergent today
Start Building