Sub topic 7
Agents, Auto-Install, and Other Risk Amplifiers
This chapter assumes you know how pip and npm install packages, that install steps can run code, and that models sometimes suggest package names that do not exist. It covers the conditions that turn a hallucinated name from a nuisance into a compromise.
Why exposure depends on the workflow
A hallucinated name is harmless while a human stops to look at it. A typical chat session has a natural pause: the model prints pip install fastjson-utils, you read it, and you may notice you have never heard of that package. Risk grows when the workflow removes that pause. Each amplifier below does so in a different way.
Agents that run commands
A coding agent is a tool that lets a model run shell commands, edit files, and read the output. If the model decides a package is needed, the agent can run the install itself.
This changes three things:
- No human reads the name. The suggestion and the install happen in one step.
- Failures trigger retries. If an import fails, the agent may try an install, then another variant of the name, until something succeeds. A registered malicious package is the first one that "works".
- The agent runs with your permissions. Install scripts execute as your user, with access to your environment variables, SSH keys, cloud credentials, and source tree.
The last point matters most. The agent's success signal is "the error went away". It does not distinguish a legitimate library from a malicious one that happens to install cleanly.
Auto-approval and unattended runs
Most agent tools ask for confirmation before running commands. Settings such as "always allow", allow-lists for pip or npm, and flags that skip prompts remove that confirmation. This is common in CI jobs, background tasks, and long autonomous sessions.
Two habits make it worse. People approve prompts quickly after the tenth identical request. And an allow-list entry such as npm install * approves every package name, including ones that were never reviewed.
Unreviewed generated code
Hallucinated names also arrive through files, not just commands. A model may add an entry to requirements.txt, package.json, or a Dockerfile, or write an import for a package that you will install later. In a large diff, one extra line is easy to miss. The dependency enters the project through a commit, and the next teammate or CI run installs it.
Persistence is a related risk. Once a bad name is committed, it can spread to every machine that builds the project.
Repeatable hallucinations
Attackers can plan for this because models often repeat the same invented name for the same kind of prompt. A name that appears again and again is worth registering. Popular tutorials, answers, and generated code that mention the name make it look more legitimate to the next reader, and to the next model trained on that text.
Other amplifiers
- Weak review habits. Short pull requests that touch dependency files get less scrutiny than code changes.
- Broad credentials in the environment. Long-lived tokens in shell variables, or a CI job that can publish packages, increase the damage from a single install script.
- Fresh, minimal projects. With no lockfile, any new name resolves to whatever the registry serves today.
- Plausible names. Names that follow ecosystem conventions, such as
flask-jwt-helperorreact-form-utils, pass a casual glance.
Comparing the amplifiers
| Amplifier | What it removes | Typical fix |
|---|---|---|
| Agent runs install | Human reading the name | Require approval for new dependencies |
| Auto-approval | Per-command confirmation | Narrow allow-lists, no wildcard installs |
| Generated dependency files | Review of one extra line | Flag changes to manifests in review |
| No lockfile | Fixed, known versions | Commit lockfiles and hashes |
| Broad credentials | Limits on damage | Short-lived, scoped tokens |
Putting it together
Exposure is roughly the chance that a model emits a bad name, multiplied by the chance that nothing stops the install, multiplied by what the install can reach. You cannot control the first factor. The later chapters on verification and prevention work on the other two.
Exercise
Your team lets a coding agent run npm install * without prompts in a CI job that has a publish token in its environment. Name two amplifiers present and one change that reduces the risk.
Show answer
The amplifiers are auto-approval (the wildcard allow-list approves any package name with no human check) and broad credentials (the publish token is reachable by install scripts). Any one fix is acceptable: change the allow-list to npm ci --ignore-scripts so only lockfile contents install, require review for new dependencies, or remove the publish token from the job that runs the agent.