AI Package Hallucinations Are the New Supply Chain Attack Vector
A security researcher types “generate a Python script to parse CSV files.” The model confidently returns code that imports csv-pro-plus from PyPI. The package does not exist. Within hours, an attacker registers it, uploads malware, and the install runs unverified on the next developer’s machine. This is the AI package hallucination problem — now the single fastest-growing supply chain attack vector of 2025, where attackers weaponize the names that AI assistants confidently invent out of thin air.
The asymmetry is the attack itself: defenders need every install verified, while attackers need just one developer to copy-paste without checking. According to the University of Texas study at CCS 2024, the rate of hallucinated package suggestions in commercial AI coding assistants is roughly 20% — and attackers have noticed.
How a Hallucinated Package Attack Works
Large language models invent package names because their training objective predicts plausible-looking identifiers, not verified ones. Once an attacker identifies a hallucinated name — through systematic querying or monitoring developer forums — they can register it on the relevant registry in seconds. PyPI, npm, and RubyGems all allow publication without lengthy review.
The kill chain runs in four stages:
1. Discovery — Attacker queries LLMs at scale to harvest hallucinated package names 2. Registration — Attacker claims the names before the genuine package appears 3. Weaponization — Malicious payload is uploaded, often disguised as legitimate utility code 4. Installation — Developer runs pip install, executes the payload
Socket’s 2025 threat report documented a single threat actor registering over 150 hallucinated package names across PyPI and npm in a three-month span, all linked to the same C2 infrastructure.

Why 2025 Changed the Calculus
Three converging trends turned an academic curiosity into a category-one threat: AI assistants moved from autocomplete to autonomous generation, security tooling lagged model iteration speed, and attackers industrialized the harvesting process. The 2024 paper from UT Austin showed the hallucination rate at 21.7%, while the Snyk 2025 State of Open Source Security report tracked a 248% year-over-year increase in malicious package attacks.
The Defensive Playbook
1. Verify Before Installing
Every package an AI assistant suggests should be cross-checked on the official registry before installation. A literal lookup on pypi.org or npmjs.com — not just pip install. The five-second manual check defeats the entire category. For teams using AI code generation heavily, automated gates are table stakes:
2. Pin and Reproduce
Lockfiles with pinned versions and hash verification (pip install --require-hashes, npm package-lock.json with integrity hashes) prevent both typosquatting and silent-replacement attacks. Pin everything.
3. Segment Trust Boundaries
Developers should treat AI-suggested code as untrusted input — the same threat model as copying from Stack Overflow. npm install --ignore-scripts and pip install --no-deps --no-build-isolation reduce a successful install’s attack surface dramatically.

What to Do Today
For engineering leaders: turn on Socket or Snyk in CI this week. For individual developers: verify every package before install, every time. The hallucination economy is a security problem we saw coming. Acting on it is overdue.
Frequently Asked Questions
What is an AI package hallucination attack?
An attack where an AI coding assistant suggests a non-existent or wrong package name, which an attacker then registers on a public package registry and weaponizes before the legitimate package ever appears. The developer installs the malicious package, believing it was endorsed by the AI.
Which AI tools are most affected?
All major AI coding assistants hallucinate package names, including GitHub Copilot, Cursor, Claude Code, and ChatGPT. None are immune. The UT Austin study found roughly 20% of suggested imports point to non-existent packages.
How do I check if a package exists before installing?
Search pypi.org, npmjs.com, or rubygems.org directly in your browser, or use the registry’s JSON API. Do not rely on pip install succeeding or failing as a signal — by the time you test, an attacker may have registered the name.
Are package typosquatting attacks new?
Typosquatting itself is decades old. The novelty is that AI assistants now generate plausible package names at scale. The 2024-2025 surge is specifically AI-driven.
What tools can detect hallucinated packages?
Socket, Snyk, and Aikido flag low-reputation and recently-created packages at install time and in CI. Socket’s 2025 update specifically targets AI-hallucinated names.
Should we block all AI-suggested packages from being installed?
Not block, but gate. Allowlist trusted packages, require explicit approval for anything else, and route AI-generated dependency changes through a security review process before merging.
What is the most common payload in these attacks?
Information stealers targeting browser credentials and crypto wallets, followed by reverse shells and dependency-confusion droppers. Persistence matters more than immediate damage.