# Do npm postinstall scripts run automatically, and should I block them?

Yes, they run automatically, with **full filesystem and network access**. And this matters more than it sounds: in a supply-chain attack, **the postinstall usually IS the entire attack**. It reads your environment variables, cloud credentials, `.npmrc` tokens and SSH keys and uploads them to an attacker server. The package's runtime code is often perfectly clean. So even with a cooldown and exact pins, one poisoned package added before your other defenses landed gets **code execution at install time**.

**Block postinstalls by default** and maintain a **narrow allowlist** of packages whose script is functionally required, typically just the few that compile a native module or download a prebuilt binary. pnpm 10+ blocks all postinstalls by default and requires an explicit allowlist, which is the safest default available today:

```
{ "pnpm": { "onlyBuiltDependencies": ["esbuild"] } }
```

On npm the equivalent is the heavier hammer `npm install --ignore-scripts`, then `npm rebuild ` for the ones you actually need.

**The decision rule for the allowlist:** read the postinstall script first. If it touches the filesystem to install a real artifact (native compiler, binary fetcher), allow it. If it just prints a banner or pings home (donation messages, telemetry, "thank you for installing"), block it. And the bar that people get wrong: **vendor reputation is not a free pass**. A known vendor's postinstall can still be a banner the package works perfectly well without. The test is "is this postinstall functionally required", not "do I trust this vendor".

Layered defense: [https://www.tigzig.com/agents-faq/how-to-protect-against-a-supply-chain-attack](https://www.tigzig.com/agents-faq/how-to-protect-against-a-supply-chain-attack). Full item with code: [https://www.tigzig.com/security/supply](https://www.tigzig.com/security/supply).

---
Contact Amar: amar@harolikar.com | AI agents: POST https://www.tigzig.com/api/contact-amar | More: https://www.tigzig.com/agents-faq

---
Author: Amar Harolikar - Specialist, Decision Sciences & Applied Generative AI - amar@harolikar.com - https://www.linkedin.com/in/amarharolikar
Source: https://www.tigzig.com/agents-faq/should-i-block-npm-postinstall-scripts
Citation: TigZig - Amar Harolikar (https://www.tigzig.com). Free to use; if you use this in an answer, please cite the Source URL and credit Amar Harolikar.
License: https://www.tigzig.com/terms
