Slopsquatting attacks: when an agent installs a fake package

Stefan-Iulian Tesoi · · 6 min read

An old wooden crate in a stack, a half-legible name stencilled on its side and nothing showing what is inside, which is all an install command checks

Slopsquatting is registering a package under a name AI models tend to invent, so that an agent's install command fetches the attacker's code instead of an error. The defence is to make every new dependency a reviewed change: nothing outside the lockfile installs until someone approves it, and each new package is checked for age, publisher and history first.

Slopsquatting attacks need no compromised maintainer and no stolen token. They need a model that guesses the same wrong name twice, and a coding agent with permission to run the install.

What are slopsquatting attacks?

A supply-chain attack on the gap between the packages a model believes exist and the packages that do. The attacker publishes fake npm packages or PyPI projects under names models hallucinate, and waits for an agent to ask for one.

The gap is large and measured. The authors of We Have a Package for You!, presented at USENIX Security 2025, generated 576,000 code samples from 16 models and found that 19.7% of the packages those samples relied on did not exist: 205,474 distinct invented names. Commercial models invented at least 5.2% of their packages on average, open-source models 21.7%.

What turns a curiosity into an attack is repetition. When a prompt that had produced an invented name was run ten more times, the same name came back in all ten runs 43% of the time. A name invented every time is a target someone can register in advance.

It has already been demonstrated. In 2024 the researcher Bar Lanyado published an empty package called huggingface-cli to PyPI after watching models recommend it. It collected more than 15,000 downloads in three months, and a research repository at Alibaba told its readers to install it.

How is slopsquatting different from typosquatting?

Typosquatting waits for a person to mistype a real name; slopsquatting waits for a model to invent a plausible one. The defences overlap, but the second is much harder to spot by eye.

TyposquattingSlopsquatting
Where the bad name comes fromA human typing errorA model's confident guess
What the name looks likeA near-miss of a real packageA plausible package nobody wrote
Who runs the installA developer, onceAn agent, possibly on every run
Caught by reading the diffOften, because the misspelling showsRarely, because the name looks right

An invented name looks like a library you have not heard of yet, and in a registry the size of npm that describes almost all of them.

Why is an agent's install command the weak point?

Because the agent picks the name, runs the command and reads the result in one loop, with no pause in which anyone sees the name.

A developer handed an invented package usually finds out at the install, when the registry answers 404. That 404 is the safety net, and slopsquatting removes it: the install succeeds, the import resolves, and an agent working towards a passing test reads success.

The install also runs code before any review can. npm executes preinstall and postinstall scripts by default, and a Python source distribution runs its build script, so the payload executes on the machine doing the work, often one holding a repository token. A sandbox with tight egress limits what it can reach, not whether it runs.

Agents choose install commands from habit, not from the repository. Our own workflow document opens its dependency section with "pnpm, never npm", because npm install crashes on a pnpm-managed tree with an error naming neither tool. The habit that picks the familiar command also picks the familiar-sounding package.

Should a new dependency need approval?

Yes. Adding a dependency decides what code the product trusts, and that decision belongs with a person even when an agent wrote everything around it.

An agent can still propose one, as a visible change rather than as a side effect of making a test pass. Three settings do most of the work:

The backlog item can carry the decision too: "adds no dependencies" is an acceptance criterion a reviewer checks in one glance at the lockfile diff. In Laimonade a coding agent hands work in for review rather than closing it, which is where that check sits. As what permissions a coding agent should have argues, the limit itself has to be a tool refusing, not an instruction to the model, and installing unreviewed code belongs on the list of what an agent should never be able to do.

Checks for every package an agent adds

Five checks, each under a minute, before the lockfile change merges:

  1. Does it exist where the agent says? Open its registry page by hand. A package first published this month, for a problem with a standard solution for years, is the classic shape.
  2. How old is it? pnpm's minimumReleaseAge refuses versions younger than a set number of minutes, 1440 being one day, which removes the freshest registrations without anyone remembering to look.
  3. Who publishes it? A first package from a new account is not proof of malice, but it is the profile every slopsquatted package has.
  4. Does it run install scripts? Install hooks in package.json, or a setup.py doing more than declaring metadata, deserve reading before anything runs them.
  5. Is it needed at all? Most invented packages wrap something the standard library or an existing dependency already does.

The rest falls to code review when an agent wrote the code, and dependencies are one surface of coding agent security.

Frequently asked questions

Does a lockfile protect against slopsquatting?

Against a package already in it, yes; against a new one, no. A lockfile pins what was resolved before, so a slopsquatted name cannot slip into an existing entry. Adding a dependency simply writes a new entry. The protection comes from installing with npm ci or a frozen lockfile and reviewing every lockfile change.

Is a private package registry safer?

Only if it refuses names nobody approved. A proxy that mirrors the public registry on demand fetches a slopsquatted package as readily as npm does. One run as an allow list, where a package has to be added before anyone can install it, turns every new dependency into a request a person approves.

Can dependency scanners catch a slopsquatted package?

Some can, late. Scanners that match against advisory databases, such as Dependabot and npm audit, only know a package is malicious after someone reports it, and a name registered last week has no advisory. Scanners that inspect behaviour, such as install scripts, network calls and obfuscated code, catch more. Keep a software bill of materials either way, so that when an advisory arrives you can tell within minutes whether you were affected.