AI Agents and Coding Assistants

Invented Package Names: A Supply Chain Risk From AI Code Suggestions

AI tools can suggest software packages that do not exist. Learn how attackers could exploit that and how to check before installing.

Key takeaways

  • A language model can produce a package name that sounds right but refers to nothing real.
  • An attacker may register such a name, so a successful install is no proof that the package is the one you wanted.
  • Before installing, confirm the name against the official documentation and look at the package's history, source and maintainers.
  • Teams can reduce the risk with approved lists, locked versions, human approval for new dependencies and limited install environments.

AI coding tools sometimes tell you to install a software package that does not exist. Usually the install simply fails. The danger comes if someone else has noticed that the tool tends to suggest that name and has published a package under it containing harmful code. Your install then succeeds, and you have invited a stranger's program into your project.

People often call this slopsquatting, a play on typosquatting, where attackers register names that resemble popular ones and wait for typing mistakes. The defense is straightforward: treat every new package name as unverified until you have checked it yourself.

How packages and registries work

Few programs are written from scratch. Developers reuse packages, which are bundles of ready-made code for jobs such as reading spreadsheets or sending email. Public registries host them, and a tool called a package manager downloads one by name with a single command.

Each package may depend on others, which depend on others again. This web of borrowed code is part of what is called the software supply chain, everything that goes into your program before it reaches users.

Many public registries let nearly anyone publish a new name. That openness has made sharing easy. It also means a name's presence in a registry says little about who made it or what it does. And in several ecosystems, installing or first using a package can run its code on your machine, with your permissions.

Why a model invents names

A language model generates text by predicting likely continuations. Package names follow patterns: a task, a library name, a suffix. A plausible combination can come out even when nobody has published it. This is a form of the same problem as other made-up details, explained in why chatbots invent facts.

Several situations make it more likely.

  • The request is niche, and little real code exists for it.
  • A name differs between languages, such as a library known one way in one ecosystem and another way elsewhere.
  • The name you type to install differs from the name you import in code.
  • A package was renamed or removed after the model's training data was collected.

Researchers have reported that models invent package names at a noticeable rate and that some invented names recur across repeated requests. Repetition is what makes the trap worthwhile for an attacker. Rates differ between tools and change over time, so do not assume a particular figure for the one you use.

How the attack would unfold

How an invented name can become a trap
1 Model suggests A plausible but nonexistent name appears in code 2 Name noticed An attacker sees the name come up repeatedly 3 Name claimed A package is published under it 4 Victim installs A person or agent runs the suggested command 5 Code runs Secrets or systems within reach are exposed Model suggests A plausible but nonexistent name appears in code 1 Name noticed An attacker sees the name come up repeatedly 2 Name claimed A package is published under it 3 Victim installs A person or agent runs the suggested command 4 Code runs Secrets or systems within reach are exposed 5

A hostile package may even do the advertised job, so nothing seems wrong. Meanwhile it could collect passwords and access keys from the machine, alter files or add a hidden way in. Developer computers and build servers are attractive targets because they often hold credentials for many other systems.

Check a package before you install it

A few minutes of checking is cheap compared with cleaning up. Work through these steps for any name you have not used before.

  1. Look for the package in the official documentation of the project or service it claims to serve. Follow their install instructions, not only the assistant's.
  2. Search the registry and compare spelling carefully, including hyphens, underscores and prefixes.
  3. See how old it is and how many releases it has. A brand-new package with a very specific, convenient name calls for caution.
  4. Follow the link to its source repository. Check that it exists, matches the package and has real history.
  5. Look at the maintainers, open issues and whether others you trust depend on it.
  6. Check for install scripts, unexplained network calls or deliberately unreadable code, if you are able to read it.
  7. Read the license.

Download counts and star ratings can be inflated, so treat them as weak evidence. None of these checks alone proves a package is safe. They raise the cost of fooling you.

Also ask whether you need it at all. A few lines of clear code, or a function in the language's standard library, may do the job with nothing new to trust.

Warning signs at a glance

Signal More reassuring More worrying
Official mention Named in the vendor's own documentation Only the assistant mentions it
History Years of releases Published very recently
Source Matching public repository Missing, empty or unrelated
Description Specific and consistent Copied from another project or vague
Install behavior Installs files only Runs scripts or downloads more

A new package is not automatically malicious, and an old one can be taken over by a new owner. Look at the whole picture.

A hypothetical walk-through

Say you ask an assistant for code that reads data from a particular brand of weather station. It replies with a short script and an install command for a package whose name combines the brand and the word "client." The name looks exactly like what you would expect.

You search the manufacturer's developer pages and find no mention of it. They describe a plain web interface that any general-purpose request library can use. In the registry the suggested name does exist. It has a single release, published a few weeks ago, a one-line description and no link to source code.

You do not need to prove it is hostile. The sensible decision is simply not to install it. You return to the assistant, say that you will use the documented web interface, and give it the relevant page of the manufacturer's instructions. The resulting code is a little longer and depends on something you already trust. If your organization has a security contact, you also pass along the suspicious name.

Had the registry returned no result at all, the lesson would be similar. Do not try variations until one installs. Each guess is another chance to land on a trap.

Packages are the best-known case, but the same caution applies to any name a tool suggests that your computer will fetch or trust.

  • Container images, ready-made software environments pulled from a registry by name.
  • Editor and browser extensions, which can often see your files or pages.
  • Build and automation steps borrowed from public collections.
  • Plug-ins and tool servers that give an AI agent new abilities.
  • Web addresses and email domains in sample settings, which someone else may own.

Older tricks also remain. Typosquatting relies on misspellings. In dependency confusion, a public package shares the name of a company's private one, and a badly configured installer fetches the public copy. Clear settings about which registry supplies which names help against that.

Habits and team rules

Protection works best when it does not depend on everyone remembering.

Record exact versions in a lock file, which lists what was installed so that later installs match, and verify checksums where your tools support it. Review changes to dependency lists as carefully as changes to code; a review checklist should include them.

Larger teams may keep an approved list or an internal mirror of the registry, and require a person to approve anything new. Automated scanners can flag known malicious or vulnerable packages, though a freshly published trap may not be listed yet.

Coding agents deserve particular care, since some can run install commands without waiting. Require approval for installs, run the agent in an isolated environment without live credentials and restrict its network access where you can. These ideas appear in sandboxes and test accounts and in habits for terminal coding agents.

If you already installed something suspicious

Act on the assumption that code may have run.

  1. Disconnect the affected machine or stop the build system from running further jobs.
  2. Tell your security contact. Keep the package name, version and logs.
  3. Revoke and replace passwords, keys and tokens that were reachable, working from a clean device.
  4. Rebuild the environment from a known good state. Uninstalling the package may not undo what it did.
  5. Review recent code changes, published releases and account activity.
  6. Report the package to the registry so others are protected.

If customer or personal data may have been exposed, you may have legal duties to notify people. Get qualified advice.

Common questions

How is this different from other malicious packages?

The harmful package is the same kind of thing. What differs is how the victim arrives at it: through a tool's suggestion instead of a typing slip or a misleading link.

Does a connected search feature solve it?

Tools that look things up can reduce invented names. They can also find a trap package that already exists and report it as real. Verification against trusted sources is still needed.

I am a beginner. What is the one habit to adopt?

Before pasting any install command from a chat, find that exact name in the official documentation of something you already trust. If you cannot, do not run it, and ask someone experienced.

Written for 4ArtificialIntelligence with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 46 articles in AI Agents and Coding Assistants →

Latest news on this topic