Slopsquatting: when AI agents install fake packages
Matt · · Last updated · 10 min read · Guides
How slopsquatting gets a fake package into a repo through an AI agent's pull request, five defences, and a CI gate you can copy that blocks new packages.
On this page
Slopsquatting is when an attacker publishes a package under a name that AI models tend to invent, and a developer or a coding agent then installs it because the model suggested it. The defence is to treat every new dependency in an AI-written pull request as unchecked: look it up before anything installs it, and block names that don't exist, are brand new or have almost no users. Below are five controls and a CI gate I ran that does that lookup.
What slopsquatting is
Ask a model for code that parses a config file or talks to a payment API, and it often imports a package to do the work. Most of the time the package is real. Sometimes it isn't. The model has seen thousands of similar names, and it produces one that sounds right but was never published.
When a person reads that code, a fake name is a nuisance: the install fails and they pick another library. It turns into a supply chain attack when someone notices which fake names models keep producing and publishes real packages under them. The next developer, or the next agent, who gets the same suggestion installs the attacker's code. That is slopsquatting: typosquatting where the typo is made by the AI.
The best public measurement I know of is We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs by Joseph Spracklen and co-authors, accepted at USENIX Security 2025 (abstract checked on 24 October 2026). They used 16 code models and two prompt datasets to generate 576,000 code samples. On average, at least 5.2% of the packages suggested by commercial models and 21.7% of those suggested by open-source models did not exist. Across the study they collected 205,474 unique hallucinated package names.
The attack doesn't need every fake name. It needs one that comes up more than once, because a name models keep suggesting is worth registering. Those numbers are for the models tested at the time; newer ones may do better or worse, and I won't guess which. The defences don't depend on the exact rate.
How it reaches a repo through an agent's pull request
When a person copies a suggestion from a chat window, there is a moment where they read the import, maybe search for the library, and notice it has three downloads and was published last week.
A coding agent skips that moment. It writes the import, adds the name to package.json and runs the install, because that is what finishing the task looks like. If the install succeeds, the agent moves on and opens a pull request. The new name is one line in a manifest and a few hundred lines of lockfile, below a summary that says "added input validation".
The install is where the harm happens, often before anyone reviews the pull request. npm runs lifecycle scripts from the packages it installs unless you tell it not to. The npm config docs describe ignore-scripts as "If true, npm does not run scripts specified in package.json files", with a default of false (checked on 24 October 2026). So a postinstall script in a freshly squatted package runs on whatever machine did the install. On a developer laptop, that machine has SSH keys and cloud credentials. On a CI runner, it has deploy tokens.
So the question is not only "would we merge this?" It is "where does this name get installed before anyone decides?"
Defences
None of these need a new product. They are ordinary package hygiene, applied on the assumption that some names in a change were never checked by a person.
Lockfiles
npm ci installs exactly what the lockfile says. The npm ci docs say the project must have a package-lock.json or npm-shrinkwrap.json, and that if the dependencies in the lockfile don't match those in package.json, "npm ci will exit with an error, instead of updating the package lock" (checked on 24 October 2026). That turns "the agent added a name and forgot the lockfile" into a red build instead of a silent resolve.
It doesn't help when the agent also updated the lockfile, which most do. It does make every new dependency show up as a lockfile diff that a check can read.
Allowlists and registries
Decide where packages come from and which install-time code may run:
- Point CI at one registry in its
.npmrcorpip.conf. If you run a private registry or proxy, it can hold an allowlist of approved packages, and a name that isn't on it fails to resolve. - Set
ignore-scripts=truein the.npmrcfor jobs that only read code, such as linting or a dependency check. Some packages need their install scripts, for example to fetch a native binary, so test before you set it everywhere. Where you can't turn scripts off, run the install on a runner that holds no secrets. - For Python, pip's secure installs page describes hash-checking mode (
--require-hashes), where every requirement, transitive ones included, must be pinned and hashed. It also recommends--only-binary :all:to refuse source distributions, since building them runs the package's code.
Check that a package exists and how old it is
This is the control aimed squarely at slopsquatting. When a pull request adds a dependency, look it up on the registry before anything installs it. Three answers should stop the merge:
- the name isn't on the registry (the agent made it up and nobody has claimed it yet);
- the name exists but was first published very recently (someone may just have claimed it);
- the name exists but almost nobody downloads it.
The next section has a script that does all three.
Dependency audit as a merge gate
A software composition analysis tool covers the known-vulnerability half of a new dependency, and it should be a required check, not a report. In AI CodeOps, the Dependency Auditor agent reads your manifests and reports known vulnerabilities, license problems and packages that look abandoned. The review at the end of the session turns those into findings, and an open finding of high or critical severity blocks the pull request until it is marked fixed, won't fix, false positive or duplicate.
Be clear about its limit: the auditor works from the model's own knowledge and doesn't query the registry or an advisory database. It can't tell you a name was registered an hour ago. That is why the existence and age check is a separate gate.
SBOM diff review
An SBOM lists every component a build contains, transitive ones included. Diffing the SBOM of the base branch against the pull request shows what the change really added, which is often more than the one name in the manifest. The SBOM diff tool compares two CycloneDX JSON files in your browser and lists added, removed and changed components, with their versions and licenses. A component that is new to the SBOM is the one to look at first.
Example: a gate that blocks a new, low-download package
This Node script compares the package.json on the base branch with the one in the pull request and finds the names that were added. For each, it asks the registry when the package was first published with npm view <name> time.created, then asks the public npm downloads API how many downloads it had last week. It never installs anything. It is written for a Linux runner, where npm can be started without a shell.
// scripts/check-new-deps.mjs
// Usage: node scripts/check-new-deps.mjs base/package.json head/package.json
// Fails when a dependency added between the two files is not on the npm
// registry, was first published fewer than MIN_AGE_DAYS days ago, or had
// fewer than MIN_WEEKLY_DOWNLOADS downloads last week.
import { readFileSync } from "node:fs"
import { execFileSync } from "node:child_process"
const MIN_AGE_DAYS = Number(process.env.MIN_AGE_DAYS ?? 30)
const MIN_WEEKLY_DOWNLOADS = Number(process.env.MIN_WEEKLY_DOWNLOADS ?? 500)
const FIELDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"]
const names = (file) => {
const pkg = JSON.parse(readFileSync(file, "utf8"))
return new Set(FIELDS.flatMap((f) => Object.keys(pkg[f] ?? {})))
}
const before = names(process.argv[2])
const added = [...names(process.argv[3])].filter((n) => !before.has(n))
const VALID = /^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/
let failed = false
for (const name of added) {
if (!VALID.test(name)) {
console.log(`BLOCK ${name}: not a valid npm package name`)
failed = true
continue
}
let created
try {
// execFile, not a shell: the name comes from an untrusted pull request.
created = JSON.parse(
execFileSync("npm", ["view", name, "time.created", "--json"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}),
)
} catch {
console.log(`BLOCK ${name}: not found on the registry`)
failed = true
continue
}
const days = Math.floor((Date.now() - new Date(created).getTime()) / 86_400_000)
if (days < MIN_AGE_DAYS) {
console.log(`BLOCK ${name}: first published ${days} days ago (${created})`)
failed = true
continue
}
const res = await fetch(`https://api.npmjs.org/downloads/point/last-week/${name}`)
const downloads = res.ok ? (await res.json()).downloads : 0
if (downloads < MIN_WEEKLY_DOWNLOADS) {
console.log(`BLOCK ${name}: ${downloads} downloads last week`)
failed = true
continue
}
console.log(`ok ${name}: first published ${created.slice(0, 10)}, ${downloads} downloads last week`)
}
if (added.length === 0) console.log("No new dependencies.")
process.exit(failed ? 1 : 0)
I ran it with Node 22 on 24 October 2026, against a base file with only express and a head file that added zod, @types/node, vitest and a made-up name, fastify-auth-session-helper-x7:
ok zod: first published 2020-03-07, 221643257 downloads last week
ok @types/node: first published 2016-05-17, 296109529 downloads last week
BLOCK fastify-auth-session-helper-x7: not found on the registry
ok vitest: first published 2021-12-03, 83654107 downloads last week
It exited with status 1. With no new names it prints "No new dependencies." and exits 0. To check the other two branches, I raised the limits: MIN_AGE_DAYS=2500 blocked zod and vitest as too new, and MIN_WEEKLY_DOWNLOADS=250000000 blocked them for too few downloads.
To run it on every pull request in GitHub Actions:
name: New dependency check
on: pull_request
permissions:
contents: read
jobs:
new-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version: 22
- name: Look up dependencies the pull request adds
env:
BASE_REF: ${{ github.base_ref }}
run: |
git show "origin/$BASE_REF:package.json" > "$RUNNER_TEMP/base-package.json"
node scripts/check-new-deps.mjs "$RUNNER_TEMP/base-package.json" package.json
A few notes on it:
- It runs on every pull request rather than filtering on
paths, so it can be a required check without hanging on pull requests that don't touchpackage.json. - It only reads the root
package.json. In a monorepo, loop over each workspace's file. npm viewuses the registry and credentials from your.npmrc. If you install private scoped packages, give the job the same.npmrc, or a private name will read as "not found". The downloads API only knows public packages, so skip that check for your own scope.- Thirty days and 500 downloads a week are starting points, not limits I can back with data. A blocked name is a prompt for a person to look, not proof of an attack.
What AI CodeOps does when a session adds a dependency
AI CodeOps runs agents on the platform, so "where does this name get installed?" has a specific answer, checked against the code as of this post.
The agents don't run a package manager. A session's agents write the change as file edits. The only place a session executes anything is the verify step, which runs your project's tests in a sandbox.
Your existing dependencies install first, then the network goes away. For a project connected to a repository, the verify step clones it into the sandbox and installs the dependencies already on your default branch, with network access, before any of the AI's edits are written. Then it cuts the sandbox off the network and confirms that from inside. If it can't confirm it, the change is not run at all.
A new dependency has to install offline. If the change touches a dependency manifest or lockfile, such as package.json, requirements.txt, go.mod or Cargo.toml, the install runs again, still offline. A package that wasn't already installed can't be downloaded, so a hallucinated or freshly squatted name is never fetched, and its install scripts never run in our sandbox. The suite then doesn't run either: the run page says "The change's dependencies could not be installed with the sandbox offline, so the suite never ran," and the step is recorded as skipped. A skip records no test result, so it doesn't block by itself. What stops the change is the human approval it still needs, from a person who can see it wasn't tested.
You can refuse dependency changes from sessions entirely. A workspace policy rule on the diff.apply action is checked against every file a change touches when its pull request is opened, and a deny stops the pull request. **/package.json needs a slash before the name, so the root file needs its own rule:
[
{ "id": "no-ai-root-manifest", "action": "diff.apply", "resource": "package.json", "decision": "deny" },
{ "id": "no-ai-nested-manifests", "action": "diff.apply", "resource": "**/package.json", "decision": "deny" },
{ "id": "no-ai-root-lockfile", "action": "diff.apply", "resource": "package-lock.json", "decision": "deny" }
]
This is strict. It also stops the built-in Dependency Refresh workflow from landing its upgrades, so use it where you want people, not sessions, to add packages. Try it in log-only mode first to see how often it would fire. The DevSecOps page covers how this fits with findings, SBOMs and license checks.
Checklist
- [ ] CI installs from the lockfile (
npm ci, hash-checked pip) and fails on a mismatch. - [ ] CI uses one registry, and install scripts are off where jobs don't need them.
- [ ] Every pull request that adds a dependency runs an existence, age and downloads check before any install.
- [ ] A dependency audit runs as a required check, and high-severity findings block the merge.
- [ ] The SBOM diff between base and pull request is read for new components and licenses.
- [ ] A person approves every new dependency an agent adds, and can say who publishes it and why it's needed.
Slopsquatting is one route into your dependency tree, not the only one. A real, popular package can be compromised through its maintainer's stolen token, and an agent can pick a real package that is simply a bad choice. The software supply chain guide covers SBOMs and build provenance, which help you answer "what did we ship?" once a bad package is found.
Key takeaways
- Models invent package names often enough to matter: at least 5.2% for commercial models and 21.7% for open-source ones in the Spracklen study.
- Coding agents install what they import, so the risk lands on the machine that runs the install, before anyone reviews the pull request.
- Lockfiles, a single registry and install scripts turned off narrow the gap, but don't close it.
- Look up every new name before installing it: block names that don't exist, are brand new or have almost no downloads.
- Make the dependency audit and the new-dependency check required checks, and keep a person on every new package.
Frequently asked questions
What is slopsquatting?
Slopsquatting is registering a package under a name that AI models invent. When a model or coding agent suggests that made-up name again, whoever installs it gets the attacker's code.
How is slopsquatting different from typosquatting?
Typosquatting waits for a person to mistype a real package's name. Slopsquatting waits for a model to produce a name that sounds right but was never published, so nobody made a typo at all.
Does a lockfile stop slopsquatting?
Only partly. A lockfile makes every new dependency visible and stops CI from resolving names nobody recorded, but an agent that adds a package usually updates the lockfile too. You still need a check that the package exists and isn't brand new.