Sandeep Machiraju
Back to writing

· Writing

Why we should build our own packages, especially in the AI era

AI made trusting npm packages riskier and writing small code yourself cheaper. When to build your own, and when a dependency is still the right call.

Sandeep Machiraju
securitydeveloper experiencebuilding with AI

In January 2025 I was building a small inventory dashboard for a take-home assignment. I installed axios and wrote a client for it, with a token interceptor and a redirect on 401. Six minutes later I deleted all of it. The app made one GET request to a public endpoint, so a plain fetch call replaced the package, its config file and 100 lines of lockfile. Nothing broke. The one thing fetch does differently is that it doesn't reject on a 404 or 500, and my version never checked response.ok.

Fourteen months later, axios was the package an attacker used to ship a remote access trojan.

When you add a dependency, you are trusting more than its code. You trust every maintainer account that can publish it, every package it depends on, and the pipeline that builds it. If any of those is compromised, everyone downstream gets the same bad version on their next install.

What one install trusts Your app depends on one package. That package in turn trusts its maintainer accounts, its own dependencies and its release pipeline. A problem in any of the three reaches your app. your app package what you read maintainerscan publish it dependenciesand theirs pipelinebuilds it
fig. one install trusts everything that can change the package

2026 showed how fast that spreads.

  • Axios, March 31. An attacker took over the lead maintainer's npm account and published two versions that added a fake dependency, plain-crypto-js. Its install script dropped a remote access trojan on macOS, Windows and Linux. Axios gets around 100 million downloads a week, and the bad versions were live for about three hours. (Trend Micro, CISA)
  • Mini Shai-Hulud, May 11. A self-spreading worm got into TanStack's GitHub Actions release pipeline. No npm tokens were stolen: it pulled a short-lived OIDC token out of the runner's memory and published 84 malicious versions across 42 @tanstack/* packages in about six minutes (TanStack postmortem). From there it spread using credentials it stole from machines that installed it. By the end of the day researchers had counted roughly 170 npm packages, plus some on PyPI, including the official Mistral AI and OpenSearch clients. (Unit 42, JFrog)

Two details from the May attack are worth sitting with. The malicious packages carried valid SLSA build provenance, because they were published from inside the project's own release workflow, even though its real publish step never ran. And the payload installed persistence hooks in Claude Code and VS Code, so removing the package did not remove the malware. (StepSecurity, Akamai)

Neither was a first. The original Shai-Hulud worm compromised over 500 packages in September 2025 (CISA). A week before that, a phished maintainer account pushed malicious versions of chalk, debug and 16 other packages with an estimated two billion downloads a week between them (AWS).

The teams hit by these attacks had no bug in their own code. They depended on something that was bad for a few hours.

AI adds a new way in

Coding agents install packages too, and they can be confidently wrong about names. A USENIX Security 2025 study generated 576,000 code samples across 16 models and found that 19.7% of the package names they recommended did not exist (Spracklen et al.). That average is pulled up by open-source models at 21.7%. The commercial models in the study were closer to 5%. But 43% of the made-up names came back on every rerun, which makes them predictable.

That is what slopsquatting relies on: an attacker registers a name that models keep inventing and waits for an agent or a hurried developer to install it (Cloud Security Alliance). When an agent runs npm install in a loop, nobody reads the package name before its code runs.

How slopsquatting works Four steps: an agent suggests a package name that does not exist, the same name comes back on reruns, an attacker registers that name, and the next install runs the attacker's code. 01 agentsuggests afake name 02 same nameon everyrerun 03 attackerregistersit on npm 04 installruns theircode
fig. a made-up name becomes a real package

Building the small things is now cheap

Zero dependencies made Fireship's list of trends for 2027 (The wild world of tech in 2027). The usual argument against it was time. Why spend an afternoon on a deep clone or an argument parser when a package already exists?

That cost has mostly gone. An agent can write a small utility, with tests, in a couple of minutes. You review code you can read in one sitting, it lives in your repo, and it changes only when you change it.

Often you don't need to write anything, because the platform already has it. Node.js now ships built-ins for a lot of what used to be a default install (e18e replacements):

  • fetch instead of node-fetch, or axios for simple requests
  • structuredClone instead of lodash.clonedeep
  • util.styleText instead of chalk
  • util.parseArgs instead of a small CLI parser
  • crypto.randomUUID instead of uuid
  • fs.rm and fs.mkdir with recursive instead of rimraf and mkdirp

Each package still covers edge cases the built-in doesn't. If you aren't using those edges, the package is weight you carry and an account you trust for nothing.

The win is not disk space. chalk is tiny and has no dependencies, so removing it saves almost nothing on disk. The win is your lockfile: one fewer maintainer account that can push code into your build.

When a dependency is still the right call

Owning code means owning its bugs. Nobody else will find the security issues in code that only exists in your repo, and no advisory feed will warn you about it. So I would not write my own:

  • Cryptography, auth and session handling. Use the platform or a well-reviewed library.
  • Standards-heavy work like time zone math, HTML sanitizing, or parsing a format with a long spec.
  • Large, fast-moving tools like frameworks, bundlers and database drivers. Their maintainers do work you would otherwise do yourself.

AI-written code is not automatically safe either. It needs the same review and tests you would give a teammate's pull request, and a green test suite only means something if the tests are real.

A rough rule: build it yourself when the code is small, the spec is stable, and you can read the whole thing in one sitting. Depend on a package when correctness is hard, security is the point, or keeping up with changes is a job in itself.

For the packages you keep

  • Check every package name an agent suggests before it installs. Make sure it exists and is the one you meant.
  • Commit your lockfile and install with npm ci in CI.
  • Upgrade to npm 12. Released on 8 July 2026, it no longer runs dependency install scripts unless your project allows them in allowScripts, and it stops resolving git and remote tarball dependencies by default (GitHub changelog, npm docs). Install-time scripts are how both of this year's big npm attacks ran their payloads.
  • Wait before taking new versions. Both attacks were caught within hours, so a cooldown of a day would have skipped them. pnpm 11 ships a 24-hour minimum release age by default (Socket).