Language models recommend libraries when they write code. Sometimes they recommend a library that does not exist: the model invents the name because the name sounds plausible. This is called a package hallucination. An attacker only has to register that name in a public registry (npm for JavaScript, PyPI for Python) and put their own code inside. The next time a model recommends it, the install pulls the attacker package. The combination of hallucination and squatting has become known as slopsquatting.
The principle is not new, but the scale is changing. As long as a human did the installing, the name had to be mistyped. Today the name comes from a model, and with coding agents the install can be triggered by the agent itself, in an environment that holds cloud credentials, registry tokens and access to servers.
What the attack looks like step by step
- The attacker finds out which non-existent package names models suggest repeatedly. No guessing is needed, it is enough to query models and watch the answers.
- The attacker registers the name in a public registry. Registration is open and free of charge.
- Malicious code goes into the package, most often into a script that runs during installation (an install script). Some packages contain no malicious code at all and only download the payload from an external server at install time, so they look clean at first sight.
- A developer or an agent installs the package on the model's recommendation. The code runs with the rights of whoever installs it and usually collects whatever is in the environment straight away: tokens, keys, the contents of environment variables.
- With those credentials the attacker moves on into repositories, into the pipeline and into every environment the stolen access reaches.
Why typosquatting defences do not catch it
Typosquatting relies on a typing mistake, so the malicious name is similar to the real one. Registries have protections for that and detection is built on string similarity. Invented names, however, do not have to be similar at all. A model may produce a name completely unlike anything that exists, or merge two libraries into a third one. A name similarity filter does not see such a package.
The second trap is ecosystem confusion. According to the security company Aikido, some of the names hallucinated for Python exist as real packages on npm, so checking that the name exists is not enough. The name has to be verified in the registry it is installed from, and against the documentation of the library.
How common it is
The most cited measurement is a study from the USENIX Security 2025 conference (Spracklen et al.). The authors had 16 models generate 576 000 code samples in Python and JavaScript. The share of recommended packages that did not exist averaged at least 5.2 per cent for commercial models and 21.7 per cent for open-weight models. In total they found 205 474 distinct invented names.
A newer replication on 2026 models (Aleksandr Churilov, independent researcher, paper version of 9 November 2026) went through 199 840 generations in Python and JavaScript across five current models. The results are worth reading in two directions:
- Invented names account for 3.6 to 5.0 per cent of all package mentions. Today's best models therefore sit where commercial models sat in 2024, and the gap between commercial and open-weight models has disappeared. Python is worse than JavaScript for every one of the five models.
- The same name is invented by several models. The set of names hallucinated by all five models tested contains 104 entries. That is exactly what an attacker needs: a name that will come up again.
The same work tempers the alarm on the other half of the problem. Around 1 per cent of the invented names were registered within six months, and the author found no difference between names that appeared publicly in his list and names that stayed unpublished. At the same time, at least 23 names the models suggested had previously hosted malware that the registries removed, and one invented name was registered with malicious content after his runs. There is no publicly documented case of a large attack carried out this way so far. This is a risk that controls can handle, not a reason to panic.
What to do in advance
In dependencies and installs
- Install from the lockfile only. Builds and pipelines must not decide about versions or about new dependencies. In the npm ecosystem that means installing from package-lock.json, in Python installing from requirements with pinned versions.
- Turn on hash checking. The pip tool supports a mode where only artefacts matching the hash recorded in requirements are installed (the
--require-hashesoption) and where source distributions cannot be used (--only-binary :all:). Without that, installation executes foreign code from setup.py. - Disable install scripts where you do not need them. The npm tool has the
ignore-scriptsoption. It is worth enabling on developer machines and on runners, and handling exceptions deliberately. - Route installs through your own registry proxy. Nexus, Artifactory or Verdaccio only allow what is on an approved list or in the cache. An invented name is not found in the proxy and the install fails instead of succeeding.
- Set a quarantine for new versions and new packages. A package published a few days ago, with a single version and no history, is reason enough for a manual check.
In the environment where the AI agent runs
- The agent runs in a container or on a runner without persistent credentials. No cloud tokens, no SSH keys, no registry token in environment variables.
- Outbound connections are limited to what the agent needs: the registry proxy, internal services. Not the whole internet.
- The agent has no access to production and no right to install into the system. Its output is a proposed change, not a deployment.
- Do not approve install commands with a single click. If an agent proposes installing a package the project does not use yet, that is a decision for a human.
In the process
- A new dependency is a change that a human reviews. The review covers the lockfile diff as well, not only source code.
- Before adding a library, verify that it exists and where it comes from: the package page in the registry, the link to the repository, version history, author, documentation. A name in a model's answer is not evidence.
- Run dependency scanning (SCA) and malicious package detection in the pipeline, and keep a component inventory (SBOM). When a malicious package surfaces somewhere, you want to know within a minute whether you have it.
- Write rules for working with AI assistants and give them to developers: what an agent may install, where it may run, what has to pass through a human.
How to tell it has happened
Typical signals are a dependency in the lockfile that nobody asked for, an install reaching a domain that does not belong to the registry, a build that takes noticeably longer, a runner opening outbound connections during installation, or a login with a CI token from somewhere other than where CI runs. That is why it pays to log installs and outbound connections from builds, even when it feels like unnecessary work.
What to do once the package has been installed
- Stop the run and isolate the machine. The pipeline, the agent and the runner where the install happened. Disconnect it from the network, but do not wipe it: you will need its logs.
- Treat every credential from that environment as exposed. Rotate registry tokens, cloud keys, CI secrets, SSH keys and database access. Rotation has to be faster than abuse.
- Establish the scope. When the package entered the project, where it came from and where it now is: which repositories, which caches, which built images and containers.
- Rebuild the environment from a clean base. Uninstalling is not enough, the code has already run. Rebuild images and runners, and pull dependencies again from a controlled source.
- Look for persistence. New scheduled jobs, new keys in authorized_keys, changes in pipeline configuration, new tokens and applications in the cloud, edits in the repository.
- Report the package to the registry. Both large registries have a channel for reporting malicious content and can block the name. It saves everyone else the trouble.
- Assess whether this is a reportable incident. If you fall under NIS2 or DORA, assess the impact and the deadlines according to your internal procedure and the guidance of your supervisory authority. That assessment belongs to management, not to the developer who installed the package.
- Write it down. The risk, the control you put in place and a date to review it. Without a record the same thing comes back in six months.
What this means for regulated organisations
Coding assistants are reaching companies faster than the rules for using them. In risk management terms, an AI agent allowed to install dependencies is a new entry point into your software supply chain, except without a contract and without a supplier you would assess. If you run security in an organisation under NIS2 or DORA, it is worth having this one specific risk in the risk register, with the controls from the sections above and evidence that they work.
We help put this in place in practice, from rules for working with AI assistants and checks in the pipeline to keeping a record of risks and controls. If you are wondering where you stand, start with a security assessment or write to us through our contact page. If you suspect a malicious package has already taken something, we have a page for that: under attack.
Sources: Spracklen et al., USENIX Security 2025, measurement of package hallucinations across 16 models · Churilov 2026, replication on 2026 models and registration of invented names · pip documentation, secure installs with hash checking · npm documentation, the ignore-scripts option · Aikido Security, description of slopsquatting and ecosystem confusion