Skip to content
mentoor

Topic 4 of 5 · 5 min read

Agents installing packages on their own

Goal: Review an agent's run log and flag every package install that bypassed the team's dependency rules.

A coding agent that can run shell commands can install packages, and an install can run code. Treat every install in an agent's log as a code change that needs the same approval as any other dependency.

Check yourself · 1 of 3

Why can an install command be more dangerous than a normal code edit?

Choose one answer

Why it matters

Agents such as Claude Code, Codex, Cursor and Copilot's agent mode run npm install, pip install and cargo add to get a failing task working. In a normal change you review the diff. An install can change the machine and the project before any diff exists: new files in node_modules, a new line in the lockfile, and lifecycle scripts that execute during install. In npm, a preinstall, install or postinstall script in any package, including one deep in the tree, runs with your user's permissions unless scripts are disabled.

So the question is not only "is this package good?" It is "did this run, where, and with which secrets in the environment?" A developer machine often holds cloud credentials, SSH keys and tokens.

How to review an agent run

  1. Search the transcript or log for install verbs. npm install, npm i, pnpm add, yarn add, pip install, uv add, go get, curl ... | sh.
  2. For each one, ask three questions. Was it requested? Is the package on the team's approved list? Did it run in a sandbox or on a machine with real credentials?
  3. Check for side routes. pip install from a git URL, npm install of a tarball link, an extra --registry flag, or --force and --legacy-peer-deps used to push past a conflict.
  4. Read the lockfile diff, not just package.json. A single added package may bring dozens of transitive ones.
  5. Set the rules before the run. Make installs a permission the agent must ask for, and deny the risky forms. See the permissions docs in the references. Consider ignore-scripts for installs that do not need build steps.

Before and after

A run log fragment:

$ npm install left-pad-utils --force
added 41 packages in 6s
$ node scripts/seed.js

The agent added an unrequested package with --force, pulled in 41 packages, and then ran project code that now loads them. The reviewed run asks first, uses the existing helper instead, and shows no install line at all.

What goes wrong

  • Reviewing the diff and not the log. The install ran before the diff was made.
  • Blanket approval. "Always allow npm" lets any later hallucinated name through without a prompt.
  • Running the agent on a machine full of secrets. One install script can read the environment.
  • Missing the quiet installs. pip install -r of a file the agent just edited counts as an install too.

Examples

The forced install

An agent's test run fails on a peer dependency conflict. It retries with npm install --force and --legacy-peer-deps. The conflict disappears, and a package outside the approved list is added. The reviewer should reject the change and ask why the conflict appeared.

The pipe to shell

A log shows curl -s https://example-installer.dev/setup | sh. The agent wanted a CLI tool. There is no diff and no lockfile entry, so a diff review would never see it. A permission rule that denies curl | sh stops this before it runs.

Key points

  • An install is code execution, because packages can run scripts while they install.
  • Reviewing the agent's log for install commands matters as much as reviewing its diff.
  • Flag installs that were not requested, are not on the approved list, or use --force, a custom registry or a git URL.
  • Read the lockfile diff to see all the transitive packages one install brought in.
  • Set permission rules before the run: ask for installs, deny pipe-to-shell forms and run with the fewest secrets available.

Common mistakes

  • Looking at the final diff only and never reading the command log.
  • Granting the agent a standing allow for every install command.
  • Running agents with production or cloud credentials in the environment.
  • Ignoring install flags such as --force, --registry and git URLs.

Check yourself · 2 of 3

Which line in an agent's log should you flag first?

Choose one answer

Check yourself · 3 of 3

Which setup best limits what an agent's installs can do?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic