codewithkarani

Slopsquatting: when your AI coding assistant invents a package

Karani GeoffreyKarani Geoffrey6 min read
On this page
  1. For business owners: the short version
  2. What the research actually measured
  3. Where the name comes from
  4. Defence 1: check a package before anything installs it
  5. Defence 2: lock what you install
  6. Defence 3: make dependency changes visible in review
  7. Defence 4: rein in agents that install on their own
  8. Sources

You ask an AI coding assistant for help and it hands back code with pip install or npm install for a library you have never heard of. Sometimes that library does not exist: the model made up a plausible name. On its own, that package hallucination only costs you an error message.

The danger starts when someone registers the made-up name on PyPI or npm and fills it with malicious code. The next person given the same suggestion installs the attacker's package. This is slopsquatting, and the defence is mostly old supply-chain hygiene applied more strictly.

AI models sometimes recommend packages that do not exist, and they often repeat the same fake names. An attacker can publish a package under such a name. Protect a project by checking every new dependency before it is installed (age, maintainers, source), committing lockfiles and installing with npm ci or hash-checked pip, and making CI flag any change to the dependency list for human review.

For business owners: the short version

If developers or AI tools write your software, a fake package name suggested by an AI can let an attacker run code on your developers' machines or servers. Ask your team three questions: who approves a new third-party library before it goes in, is the exact list of libraries locked and stored in the project, and does the build stop when that list changes without review? Any "nobody" or "no" is the gap to close.

What the research actually measured

The main study is "We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs" by Spracklen and colleagues, presented at USENIX Security 2025. The authors had 16 models generate 576,000 Python and JavaScript code samples, then checked every package name against the PyPI and npm package lists as of 10 January 2024.

  • Scale: the 30 test runs produced 2.23 million package references, of which 440,445 (19.7%) were hallucinations, including 205,474 unique names that did not exist on PyPI or npm.
  • Commercial vs open-source: the GPT-series models had a hallucination rate of 5.2%, against 21.7% for the open-source models tested.
  • Repetition: when 500 prompts that had produced a hallucination were re-run 10 times each, 43% of the hallucinated packages came back in all 10 runs, and 58% came back more than once.
  • Not just typos: only 13.4% of hallucinated names were 1 or 2 characters from a real package; most are invented, not misspelt.

Repetition is what makes this an attack: a name the model suggests again and again is worth registering. These are models tested in 2024 under the authors' settings, and they do not tell you the rate for the assistant you use today. They do show the behaviour is systematic, not rare.

Where the name comes from

"Slopsquatting" blends "AI slop" with typosquatting. Socket's glossary credits Python Software Foundation Developer-in-Residence Seth Larson with coining it and Andrew Nesbitt with popularising it in April 2025. The OWASP Top 10 for LLM Applications 2025 lists the underlying problem under LLM09 Misinformation: "The model suggests insecure or non-existent code libraries", with an example scenario where attackers look for "commonly hallucinated package names". For why models produce confident wrong answers at all, see AI hallucinations explained.

Defence 1: check a package before anything installs it

Checking that a name exists is not enough: once an attacker registers it, it does. As the paper puts it, "the mere presence of a package in an open-source repository does not confirm its credibility." Look for evidence of a real project: age, maintainers and a source repository you can open.

For npm, npm view reads registry metadata without installing anything. A name that does not exist returns E404:

npm view some-package name time.created time.modified maintainers repository.url

For PyPI, https://pypi.org/pypi/<project>/json returns 404 for a missing project; otherwise it lists every release, each file with an upload_time_iso_8601, plus the project's links.

curl -fsS https://pypi.org/pypi/some-package/json | python3 -m json.tool | less

Warning signs: created very recently, one release, no linked source repository. That is the exact profile of a slopsquatting package.

Defence 2: lock what you install

Lockfiles stop the dependency list changing silently. In CI and on servers, install from the lockfile only:

  • npm: npm ci requires an existing package-lock.json or npm-shrinkwrap.json, exits with an error if it disagrees with package.json "instead of updating the package lock", and "will never write to package.json or any of the package-locks". Add --ignore-scripts if your project does not need install scripts; install scripts are one way a malicious package runs code.
  • pip: pin every requirement with == and one or more --hash=sha256:... values, then install with --require-hashes. The pip docs also recommend --only-binary :all: to refuse source distributions.
# Node: install exactly what the lockfile says, run no install scripts
npm ci --ignore-scripts

# Python: refuse anything without a matching hash
pip install --require-hashes --only-binary :all: -r requirements.txt

Defence 3: make dependency changes visible in review

A slopsquatted package enters as a one-line change to package.json, requirements.txt or pyproject.toml. A CI step can flag that on every pull request:

git diff --name-only origin/main...HEAD \
  | grep -E '(^|/)(package\.json|package-lock\.json|requirements[^/]*\.txt|pyproject\.toml)$' \
  && echo "Dependency files changed: review every new package before merging"

The stronger version is an allowlist: installs go through a private registry or proxy that serves only approved packages.

Defence 4: rein in agents that install on their own

An agent that can run shell commands can install a hallucinated name before you see it. Configure coding agents so installs need your approval, and read the name first. The workflow in my daily Claude Code workflow treats agent output as a pull request to review, which is the right posture here too. As push access is code execution explains, anything that changes what a build installs can run code on it.

Provenance, checked with npm audit signatures, shows "where a package was built and who published a package", but npm notes "it does not guarantee the package has no malicious code".

For the wider picture of how AI changes a business's attack surface, read the new attack surface.

Sources

Frequently asked questions

What is slopsquatting?
Slopsquatting is registering a package on a public registry such as npm or PyPI under a name that AI coding tools invent, so that developers who follow the AI's suggestion install the attacker's package. The name blends "AI slop" with typosquatting.
How often do AI models suggest packages that do not exist?
In the USENIX Security 2025 study by Spracklen and colleagues, 19.7% of 2.23 million package references from 16 models tested in 2024 were hallucinated: 5.2% for the GPT-series models and 21.7% for the open-source models. 43% of hallucinated names came back in all 10 repeats of the same prompt. Rates for today's assistants may differ.
Is it enough to check that a package exists before installing it?
No. Once an attacker registers a hallucinated name, it exists. Check how old the package is, who maintains it and whether it links to a real source repository, then commit a lockfile, install with npm ci or hash-checked pip, and have CI flag every change to the dependency list for review.
#Supply Chain#AI Security#AI hallucinations#npm#pip#Dependencies#Agentic Coding

Written by

Karani Geoffrey

Software engineer in Nairobi and founder of Upeosoft. I build ERPNext, AI and web systems that businesses run on, and write down what I learn along the way. More about me

Keep reading