Rightshold™ Sign up

Answers · vibe coding

How do I stop an AI coding agent from installing hallucinated packages (slopsquatting)?

Last updated

TL;DR: Don't let the agent run npm install or pip install on its own. Make package installs ask you first, and check each new name before approving: does it exist on the registry, when was it first published, who maintains it, and does it link to a real source repo? A name that doesn't exist is a hallucination. A name that exists but is days old with no history may be a squat of one. Then limit the damage: set npm's min-release-age so brand-new versions aren't installed, turn off install scripts by default, and commit a lockfile. Research on 576,000 generated code samples found 19.7% of the packages they referenced did not exist (arXiv 2406.10279), and the same fake names often come back, which is what attackers count on.

What should I check, step by step?

1. Make dependency installs need your approval. In Claude Code, add ask rules such as Bash(npm install *), Bash(pnpm add *) and Bash(pip install *). Deny and ask rules match even inside chained commands and subshells.

  1. For every new name the agent proposes, look it up yourself: npm view <name> (a 404 means it doesn't exist) or https://pypi.org/pypi/<name>/json.
  2. If it exists, check time.created, the maintainers, the repository link, recent downloads and whether the docs the agent cited actually mention it. A days-old package with a plausible name and no history is a red flag.
  3. Prefer a well-known package that does the same job over one you can't vouch for, even if the agent's code calls the unknown one.
  4. Set min-release-age in .npmrc (for example 7 days) so npm only installs versions that have been public that long.
  5. Turn off install scripts: ignore-scripts=true in .npmrc, or use npm's allowScripts policy in package.json so only packages you approve run install-time scripts.
  6. Commit the lockfile and install with npm ci in CI, so a later run can't quietly pick up a new package.
  7. Check the license of each new dependency before you ship, not after.

What slopsquatting is

LLMs sometimes write code that imports a package that doesn't exist. If someone registers that name with malicious code, the next developer or agent who runs the suggested install gets it. Seth Larson (PSF Security Developer-in-Residence) coined the term slopsquatting for this, and Andrew Nesbitt popularised it in April 2025.

Settings that make installs safer

npm min-release-age: if set, npm only installs versions that were available more than the given number of days ago. min-release-age-exclude lets your own scope update immediately. A brand-new squat of a hallucinated name won't install until the window passes, which gives registries and scanners time to catch it.

What can go wrong?

The agent adds the dependency to package.json or requirements.txt and a later CI run installs it. Review dependency-file diffs too, not just install commands.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Before I install it, what license does the npm package this agent wants to add declare, and is it OK for a commercial app?”

One-click setup

{
  "tool": "check_license",
  "arguments": {
    "source_url": "https://www.npmjs.com/package/express",
    "intended_use": {
      "commercial_use": true
    }
  }
}

Rightshold checks the license a registry page declares. It doesn't check whether a package is malicious, scan its code, or verify that it's the package your agent meant. Use it alongside the steps above, not instead of them.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'