What does npm install run before you open a single file?
In short
npm install runs the scripts listed in the folder's own package.json. npm 12 blocks those of downloaded packages until that same file approves them.
Someone sends you a coding task as a folder, and step one says npm install. But that can run code from the folder before you open a single file. This post works through what
npm install runs, what npm 12 changed, and why the file that decides all of it arrives inside the folder.
The coding task here is a drawn example. The real pattern behind it is described in a joint advisory from September 2026 on the campaign known as "Contagious Interview". The run below is real, with its limits stated.
Step one: npm install
A joint advisory of 18 September 2026 from the National Police Agency of Japan, the FBI and other agencies in Japan, the US, Australia and Germany describes a group it calls WaterPlum, "commonly referred to as Contagious Interview". Its actors pose as employers. During recruitment they "require job seekers participate in technical online virtual interviews or complete technical coding assignments", and instruct them to "download and execute malicious files". The advisory says the group uploads malicious npm packages and has infected at least 30,000 devices in more than 100 countries.
The advisory does not say which step of a task ran the malware, and this post does not claim it. It shows one step that runs code by design:
npm install in a folder someone else wrote.
Seven scripts in package.json
npm's documentation lists the scripts that "run on a bare npm install in a local project (no package arguments)":
preinstallinstallpostinstallprepublishprepreparepreparepostprepare
Each one is a line in the scripts field of the folder's package.json. The documentation says how a line runs: "by passing the line as a script argument to /bin/sh on POSIX systems or cmd.exe on Windows". So each of the seven can be any shell command. The first,
preinstall, runs "before any dependencies are fetched".
The run: seven, then none
The run used a project whose seven scripts each write their own name to a log, plus one local dependency,
helper-a, with a postinstall script of its own. It ran offline with npm 10.9.3, the version installed on the test machine.
npm install 8 scripts ran helper-a: postinstall project: preinstall project: install project: postinstall project: prepublish project: preprepare project: prepare project: postpreparenpm install --ignore-scripts 0 scripts ran helper-a installed: yes
All seven project scripts ran, in the documentation's order. The dependency's script ran too, and first: npm 10.9.3 did not block it. With
--ignore-scripts, nothing ran and the dependency was still installed. On npm 10.9.3 the dependency's script even ran before the project's
preinstall; the v12 documentation places preinstall before any dependency is fetched, which was not run here.
npm 12: downloaded packages wait
The npm 12 documentation changes the second half of that picture. On the page for npm approve-scripts
it says: "Dependency install scripts are blocked by default." Install commands "silently skip lifecycle scripts for any dependency that does not have a matching entry in allowScripts", and end with a list of the packages whose scripts were skipped.
That block is for dependencies. For a dependency, "install scripts" means preinstall, install,
postinstall, and prepare for packages that do not come from a registry. The project's own seven scripts are not part of it. So on npm 12, by its documentation, the folder's own seven still run on
npm install.
The npm 12 behaviour was not run for this post: only npm 10.9.3 was installed. Everything in this section rests on the v12 documentation.
The approval list travels with the folder
So the downloads stay blocked? Only until they are approved. The same page says npm approve-scripts
"manages the allowScripts field in your project's package.json, which records which of your dependencies are permitted to run install scripts". By default it writes pinned entries such as
pkg@1.2.3; with --no-allow-scripts-pin it writes name-only entries that allow any future version. An entry set to
false is a denial.
That field sits in the same package.json as the seven scripts. A folder you were sent can therefore arrive with its packages already allowed. That is a conclusion from where the field lives; it was not run.
The config page adds one more place for the same policy: "use the allowScripts field in package.json (which also supports explicit denials), or configure it in .npmrc". The documentation lists a per-project
.npmrc in the project folder among the configuration files npm reads.
Before step one
There are two ways to keep the folder's code from running before you have looked at it.
-
Read
package.jsonfirst. Look at thescriptsfield for the seven names above, and atallowScriptsfor the packages the folder has already approved. Check the folder for an.npmrctoo. -
Install with scripts off. The config page says of
ignore-scripts: "If true, npm does not run scripts specified in package.json files." It also says--ignore-scriptsoverrides theallow-scriptssetting and takes precedence over--dangerously-allow-all-scripts.
npm install --ignore-scripts
The config page also describes a root .npm-extension.mjs or .npm-extension.cjs
file, which npm imports and executes. ignore-scripts turns that off as well, "since both disable root-owned install-time code".
The flag does not stop a script you start on purpose. Commands "such as npm start, npm stop, npm restart, npm test, and npm run will still run their intended script", without their pre- and post-scripts. That is the point: no script runs, allowed or not, until you run it yourself.
What it does not do
-
npm 12 was not run. The block on dependency scripts,
allowScriptsand the.npm-extensionfile rest on the v12 documentation ("Version 12.2.3 (Latest)" on 1 December 2026). The run used npm 10.9.3. -
"Arrives already allowed" is a conclusion. It follows from
allowScriptsliving in the project'spackage.json. No folder was tested with a pre-filled entry. -
--ignore-scriptsstops scripts, not code. It does not make the project's code safe to run later. The advisory's own advice is to avoid executing code from untrusted third parties and to "only run unknown code inside a sandbox or virtual machine". - npm is not the only door. The same advisory describes malware that uses a VS Code configuration file, which "triggers auto-run code execution when the folder is opened and trusted". Its advice there is to open unknown projects in VS Code's Restricted Mode.
- The seven scripts are for a bare install in a local project. Other commands run other lists; the documentation gives the order for each command.
Get the next explainer
Every reel on this site gets a post like this one: the example run, with sources and limits. Until the next one: read
package.json before step one, or add --ignore-scripts, and no script runs until you run it yourself.
If you would like the next post by email, sign up below. You will first get an email with a confirmation link; you are only on the list after you click it, and every email has a link to unsubscribe.
Sources
-
npm Docs (v12), "Scripts": the seven scripts of a bare install,
/bin/shandcmd.exe,preinstallbefore dependencies are fetched. -
npm Docs (v12), "npm approve-scripts": dependency install scripts blocked by default, the
allowScriptsfield, pinned and name-only entries. -
npm Docs (v12), "Config":
ignore-scripts,allow-scripts,dangerously-allow-all-scripts, per-project.npmrc,.npm-extension. - National Police Agency of Japan, FBI and partners, "North Korean 'WaterPlum,' commonly referred to as 'Contagious Interview'", 18 September 2026: fake recruiting with coding assignments, malicious npm packages, the device count, the advice on unknown code and VS Code.
All sources last opened on 1 December 2026. The run used npm 10.9.3 and Node.js 22.20.0, offline, on 1 December 2026.
More posts
-
How does an API key end up in a git push, and what keeps it out?
A saved permission rule can hold a command with its key, and .claude/settings.json is meant to be committed. Where the key's value can live instead.
-
How can ten tests find one bad commit in a thousand?
git bisect tests the middle commit and drops the half that cannot hold the bug. Ten halvings cover a thousand commits, if the test answers the same way.
-
The package didn't exist, so why was the failed install the better one?
Coding models make up package names, and many come back every time. Once someone registers one, the install and a list check both pass.