Ask a coding agent to add CSV parsing to a service, and there is a good chance its next step is npm install some-csv-library or pip install something. That one line does more than download code. It runs code: install scripts, build steps, and later everything the library does when imported. The agent chose the name, often from memory, and nobody checked it.
Package registries have been a supply-chain target for years. Agents make the existing attacks easier and add one new one. This post walks through the main patterns and the controls that actually help.
Installing is executing
Start with the uncomfortable basics.
npm runs lifecycle scripts. A package can declare preinstall, install and postinstall scripts, and npm runs them during installation. The npm docs describe these in the scripts reference. A malicious package does not need you to import it; installing it is enough.
pip can run a build. When pip installs from a source distribution rather than a prebuilt wheel, it builds the package, and building means running the package’s build code. pip’s own secure installs guide suggests --only-binary :all: to disallow source distributions, and hash-checking mode with --require-hashes to pin exactly what gets installed.
So when an agent installs a package, the question is not “will we use this code?” but “what can this code reach right now, on this machine?”
Attack 1: typosquatting
The oldest trick: publish a package whose name is one typo away from a popular one, and wait. Humans make typos occasionally. Models make a related mistake: they produce names that look right, blending real package names together or using a plausible but wrong spelling.
Attack 2: dependency confusion
In February 2021, Alex Birsan published Dependency Confusion, describing how he got code running inside dozens of large companies, with permission through their bug bounty programs. The idea: companies use internal package names that do not exist on the public registry. If someone publishes a public package with the same name, some build systems prefer the public one. His proof-of-concept packages used install scripts to report back when they ran.
Agents add a twist. An agent reading your internal code sees internal package names, and when something fails to resolve, a helpful agent may try installing it from the public registry, which is exactly the move the attack waits for.
Attack 3: hallucinated packages
This is the new one. Models sometimes recommend packages that do not exist. A 2024 study, We Have a Package for You! by Spracklen and colleagues, generated 576,000 code samples with 16 code-generating models and found that the average share of hallucinated packages was at least 5.2% for commercial models and 21.7% for open-source models, with 205,474 unique hallucinated names.
A name that a model invents once, it may invent again for someone else. An attacker who registers those names gets their code installed by whichever agent repeats the mistake next. This pattern is sometimes called “slopsquatting”.
Controls that help
No single control stops all three. Layer them.
Decide where installs happen
The strongest control is architectural: do not install anything new on a machine that matters. If the agent’s code runs in a disposable sandbox with nothing valuable in it, a malicious install script finds an empty room. Secrets the task does not need are not there, your home directory is not there, and the sandbox is deleted when the run ends.
Split install from execution
Install dependencies from a reviewed lockfile in a setup step, then run the agent’s code with the network off. If the agent wants a new dependency, that is a change to the lockfile, which goes through review like any other change, rather than an npm install in the middle of a run.
Limit the network during install
If installs must happen in the run, allow only the registry hosts the ecosystem needs, as in our post on egress allowlists. A postinstall script that tries to send your environment to its own server then fails. Note that a registry host that accepts publishes is also a way out if the run holds a publish token, so keep publish credentials out of agent runs entirely.
Turn off what you do not need
npm ci --ignore-scriptsskips lifecycle scripts. Some packages genuinely need them (native builds), so expect a short allowlist of exceptions.pip install --only-binary :all:refuses source builds, and--require-hashesrefuses anything not pinned in your requirements file.- Scope internal packages so their names cannot be claimed on the public registry, and configure your package manager so internal scopes resolve only from your internal registry.
Check names before installing
Give your agent a tool policy: a new package name triggers a check before install. Does it exist? How old is it? How many versions and maintainers does it have? Does the name match what the agent says it does? A package published last week with one version and a name nearly identical to a popular one deserves a human look. This fits naturally as an approval step; see which agent actions should wait for a person.
Review dependency changes as code
Treat a new entry in package.json, requirements.txt or go.mod from an agent as one of the riskiest lines in its PR, not boilerplate. Read the name carefully, and read the lockfile diff for unexpected transitive additions.
Where Sandscale fits
Sandscale runs each agent run in its own Firecracker microVM, so install scripts execute inside a sandbox with its own kernel instead of on a laptop or a shared CI runner, and the sandbox goes away when you stop it. Its network is limited to what your plan and your egress allowlist allow, so you can keep a run’s outbound traffic to the registries it needs. Secrets reach a run only if you reference them from Vault for that run.
That limits what a malicious package can reach. It does not tell you whether a package is malicious, and code inside the sandbox can still read anything you put there. Name checks, lockfile review and keeping installs out of the execution phase are still yours to build.