Sub topic 7
Agents, auto-install, and other risk amplifiers
This chapter assumes you know how a package manager resolves a name from a public registry and why installing a package can run code (the first two chapters). It also assumes you know what slopsquatting is and how the attack chain runs (chapters 4 to 6). Here the question is different. A hallucinated name only becomes an incident if something installs it. This chapter covers what makes that step more likely.
Exposure is hallucination rate times install probability
A model that invents a package name does no harm while a human reads the suggestion, searches for the package and decides not to use it. The risk comes from how often the invented name reaches an install command with no check in between.
You can think of it as a rough product:
- How often the model suggests a non-existent name.
- How often that same name comes back across users and prompts. A name that repeats is worth registering for an attacker. A one-off name is not.
- How often a suggested name is installed without a human check.
- How much damage the installed code can do with the access it gets.
Most defenses lower one of these factors. This chapter is about the third and fourth. Agents, auto-install and unreviewed generated code raise them.
Agents that run commands
A chat assistant produces text. You copy the text, and you decide whether to run it. A coding agent runs commands itself: it edits files, runs tests, reads the errors and tries again. This changes the risk in three ways.
The review step disappears. An agent that hits ModuleNotFoundError: No module named 'fastjson_utils' does what a helpful engineer would do. It runs pip install fastjson_utils. If a squatter has registered that name, the install succeeds and the agent moves on. The error was the model's own hallucinated import, and the "fix" installs the attacker's package.
Errors turn into install prompts. The agent reads a failed import as proof that a package is missing. It does not consider that the name may be wrong. The error message is the same whether the package is real and not installed, or invented and not real. If the name is now registered by an attacker, the install works and the problem seems solved.
Loops compound the exposure. Agents run many steps in one session. Each step that adds a dependency is another chance for a bad name. Long sessions that nobody watches add up. A human might glance at one install in a session. Nobody reads the fortieth.
Approval prompts do not fix this alone
Many agent tools ask the user to approve shell commands. This helps, but it has limits you should know:
- Approval fatigue. After a dozen routine prompts, people press "yes" or turn on an "always allow" mode. A command like
pip install requests-oauth-helperlooks as routine aspytest. - Allowlists that are too broad. Allowing
pip install *ornpm install *approves every future name along with the ones you checked. - Batching. One approved command can install several packages.
pip install -r requirements.txtafter the agent edited the file installs everything in it, and you approved only the command. - Hidden installs. An agent can start an install indirectly, by running a project script, a Makefile target or
npm testthat runs a setup step. The visible command does not show it.
Treat "the agent asked and I approved" as one control, not a complete one.
Auto-install behavior in tools
Some tools install dependencies without the user typing anything. Examples include:
- Notebook or sandbox environments where a generated cell begins with
!pip install something. - Project templates and scaffolding commands that fetch packages named in a generated config.
- Dev containers and CI jobs that run
pip install -r requirements.txtornpm installon whatever the branch contains. - Agents configured with a permissive mode so that tasks finish unattended.
The common pattern is that the install happens at a moment when nobody is looking at the package name. In CI there is a second problem. CI often has access to secrets such as deploy keys, registry tokens and cloud credentials. An install script that runs there can read them. This is the "how much damage" factor from earlier. The same bad package does far more harm on a build server than in a throwaway sandbox.
Unreviewed generated code
Install commands are not the only path. Generated code carries package names in other places:
requirements.txt,pyproject.tomlandpackage.jsonfiles that the model wrote or edited.importstatements that a later run turns into an install via an auto-install hook.- Dockerfiles with
RUN pip install ...lines. - README instructions, setup scripts and CI workflow files.
A diff that adds a hundred lines of application code and one line to requirements.txt gets reviewed for the hundred lines. The one dependency line is easy to miss, and it is the line that decides what runs at install time. Large generated changes make this worse because reviewers skim.
Generated code is also a source of repeat names. If a model puts the same wrong name in many tutorials, snippets and repositories, those get scraped into public code. Later suggestions can reinforce the name, and it starts to look established. A package name that appears in many public repositories feels legitimate even when it was never real.
Other factors that raise exposure
Weak knowledge of the ecosystem
Beginners and people working outside their usual language have no instinct for which package names are well known. A senior Python developer knows that requests is standard and python-requests-pro is odd. Someone new to the area cannot tell the difference. The model's confident tone adds to this.
Plausible naming patterns
Models tend to invent names that follow ecosystem conventions: flask-security-utils, @types/some-lib-extra, py- and -js prefixes or suffixes. The more a name looks like the pattern of real packages, the less it draws suspicion.
Prompts that ask for niche functionality
Hallucinated names are more common when the request is narrow or unusual, such as an obscure file format, a rarely used API or a combination of two libraries. The model fills the gap with a package that would be convenient if it existed.
Wide-open install permissions
Several things widen the damage after the fact:
- Installing into the global environment or as an administrator.
- Running agents as your normal user with access to SSH keys, cloud credentials and browser data.
- Allowing install scripts by default (npm runs lifecycle scripts unless told not to).
- Unrestricted outbound network access from build and dev environments.
Fresh registry state
A newly registered package has no history. There are no reviews, no download numbers to compare and no issue tracker. Tools that rank by "does it install" cannot tell it from a real library. The check is time and history, which a person or script has to look up deliberately.
Seeing the amplifiers in your own workflow
You can find where your workflow lets a new name reach an install without a person looking at it. Ask these questions about each place where dependencies enter a project:
- Who or what can add a name? (You, a teammate, an agent, a generator.)
- What can run an install? (A person, a hook, CI, a container build.)
- Is there a point where a human sees the full list of new names?
- What does the install have access to when it runs?
Where the answer to question 3 is "no", you have a gap. You can close it with a review script that flags new dependency names in a change. The following Python script compares two requirements files and prints names that are new. It exits with status 1 when there are any, so a CI job or a pre-commit hook can stop the change until someone has checked them.
import re
import sys
from pathlib import Path
NAME_RE = re.compile(r"^([A-Za-z0-9][A-Za-z0-9._-]*)")
def normalize(name):
return re.sub(r"[-_.]+", "-", name).lower()
def read_names(path):
names = set()
for raw in Path(path).read_text().splitlines():
line = raw.strip()
if not line or line.startswith(("#", "-")):
continue
match = NAME_RE.match(line)
if match:
names.add(normalize(match.group(1)))
return names
if __name__ == "__main__":
if len(sys.argv) != 3:
sys.exit("usage: new_deps.py OLD_REQUIREMENTS NEW_REQUIREMENTS")
added = sorted(read_names(sys.argv[2]) - read_names(sys.argv[1]))
for name in added:
print(f"NEW DEPENDENCY: {name} (verify before merging)")
sys.exit(1 if added else 0)To use it in a Git repository, save the old version and compare:
git show origin/main:requirements.txt > /tmp/requirements.old.txt
python new_deps.py /tmp/requirements.old.txt requirements.txtThe script does not decide whether a name is safe. It makes sure a person looks at every new name. The next chapter covers how to check a name.
Reducing the amplifiers
You do not have to give up agents or auto-install. You can put a gate where the amplifiers remove the human one:
- Narrow approvals. Approve specific package installs, not a blanket
pip install *rule. Read the package names in each command. - Run agents in a sandbox. Use a container or VM with no credentials, limited network access and a disposable filesystem. A bad package then has little to steal.
- Separate "agent can propose" from "agent can install". Let the agent edit the dependency file, then have a person or a check approve the names before an install runs.
- Keep CI installs strict. Install from a lockfile with hashes and without install scripts, so a new name cannot enter during a build.
- Review dependency lines on purpose. Make new dependency names a separate item in review, not part of a large diff.
- Use least privilege. Do not install as an administrator, and do not expose long-lived secrets to the environment where installs run.
The prevention chapter covers lockfiles, hash pinning and script restrictions in detail.
Summary of the amplifiers
| Amplifier | What it removes | Typical mitigation |
|---|---|---|
| Agent that runs shell commands | The human reading and typing step | Narrow approvals, sandbox, no credentials |
| Auto-install hooks and notebooks | Any look at the package name | Disable or limit to an allowlist |
| CI that installs whatever the branch lists | Review plus a safe environment | Lockfile, hash pinning, no install scripts |
| Large generated diffs | Attention to the dependency line | Review new names as their own item |
| Broad privileges | Limits on what bad code can reach | Least privilege, isolated environments |
Exercise
A coding agent in your team's repository hits ModuleNotFoundError: No module named 'csvkit_extras', runs pip install csvkit_extras, and the install succeeds. Why is the success not reassuring, and which two controls from this chapter would have caught the problem before the code ran?
Show answer
The success only shows that some package with that name is registered on PyPI. The model may have invented the name, and an attacker may have registered it afterward. The error message looked the same as for a real, missing package, so the agent had no way to tell. Two controls that would have helped: narrow command approval, so a person reads the package name before the install, and a CI or review check that flags new dependency names (for example the new_deps.py script, or hash-pinned installs that reject any package not already listed). Running the agent in a credential-free sandbox would also limit the damage.
Exercise
Your team lets an agent run any command that starts with pip install without asking. Name two ways this rule is weaker than it looks, and propose a tighter rule.
Show answer
First, it approves every future package name, including invented ones, because it matches the command and not the package. Second, it allows flags and inputs that add more packages, such as -r requirements.txt after the agent has edited that file, or an extra index URL pointing to an untrusted source. A tighter rule is to approve installs only for names on a reviewed allowlist, or to let the agent edit the dependency file but require a person (or a check such as hash-pinned --require-hashes installs) to approve any new name before an install runs.