Sample alert How it works Coverage PENTEST METHODOLOGY DOCS PRICING FAQ MCP CONTACT LOG IN SCAN MY APP →

AI agent installed a malicious npm package: what to do

FIX / MALICIOUS NPM PACKAGE / 9 MIN READ

If an AI agent installed a malicious npm package, assume that its install script ran. Isolate the machine, find the artifacts, remove persistence, and rotate every secret from a clean device. Also check the CI runners and your GitHub account.

This guide shows how to check a lockfile and what to look for on disk and on GitHub. It also shows how to stop install scripts from running in the future.

What happened in the Shai-Hulud attacks?

Shai-Hulud is a family of self-spreading npm attacks. The first wave appeared in September 2025, according to Sonatype. Copies kept coming in 2026.

The attack works like this:

  1. A bad version of a real package is published. The attacker uses a stolen maintainer token.
  2. The version has an install script, for example a preinstall hook.
  3. The script downloads a runtime and runs a hidden payload.
  4. The payload steals secrets from files, environment variables, and cloud metadata services.
  5. It uses stolen npm tokens to publish bad versions of other packages. The cycle repeats.

Two public reports give details:

  • Mini Shai-Hulud, spring 2026. The Cloud Security Alliance (CSA) tracks a group called TeamPCP. Its research note says the campaign grew sharply on May 10 and 11, 2026. It hit TanStack npm packages and packages from Mistral AI, UiPath, and OpenSearch. The note lists about 170 npm packages. It also says the malware installs hooks in Claude Code and VS Code, and writes workflow files into repositories that a stolen token can reach.
  • August 2026 wave. Sonatype reports that Shai-Hulud returned on August 4, 2026 in the keyv and cacheable packages. It tracked 2,225 affected component versions in a snapshot. Its report says the package can keep working while the environment is compromised.

The counts differ by source, and they change. Use the vendor advisory for the exact package and version.

AI agents raise the risk. An agent runs npm install to fix a failing build, often with no review. It can also add a package name that you never checked. Use the package hallucination scanner for names that an agent suggests.

How do I check if I installed a bad package?

Start with the lockfile. It records the exact version that was installed.

  1. Find the advisory. Search the vendor advisories, the GitHub Advisory Database, and the Sonatype and CSA pages for the package name. Write down the bad versions.
  2. Search the lockfile. Use the file that your project has.
grep -n -A2 '"node_modules/some-package"' package-lock.json
grep -n -A2 'some-package@' pnpm-lock.yaml yarn.lock 2>/dev/null
  1. Check the installed tree.
npm ls some-package --all
  1. Check the Git history. An agent may have changed the lockfile in a commit. Find the commit and the time.
git log --follow -p --since="2026-05-01" -- package-lock.json | grep -n 'some-package'
  1. Run an audit.
npm audit
npm audit signatures

Caution: A clean npm audit does not prove safety. An advisory can appear hours after the attack starts. npm audit signatures checks registry signatures and provenance. CSA reports that the malicious Mini Shai-Hulud packages carried valid SLSA provenance, so a pass is not enough.

  1. Check every machine. Repeat the check on your laptop, each teammate’s laptop, build agents, and CI runners. Check cached layers and container images too.

If the bad version appears in any lockfile that was installed, go to the next section.

How do I check if the install script ran?

An install script runs when you install, not when you start the app. Assume that it ran if a bad version was installed with scripts on.

Find the script names that the reports list. Sonatype names setup.mjs, Math_Symbol.js, and Math_Init.js. CSA names tanstack_runner.js. New waves can use new names.

find . -path "*/node_modules/*" \( -name "setup.mjs" -o -name "Math_Symbol.js" -o -name "Math_Init.js" -o -name "tanstack_runner.js" \) 2>/dev/null
grep -rl --include=package.json -E '"(pre|post)?install"' node_modules 2>/dev/null | head -50

Look for a Bun runtime that you did not install. Sonatype says the loader downloads a standalone Bun runtime.

find / -name bun -type f -mtime -30 2>/dev/null | head
ls -la ~/.bun 2>/dev/null

The find / command can be slow. Limit it to your home folder if needed.

Check for new network connections and processes:

ps aux | grep -E 'bun|node' | grep -v grep
lsof -i -P -n | grep ESTABLISHED

Where does the malware leave persistence?

Mini Shai-Hulud targets developer tools. Check these places on macOS and Linux.

Claude Code hooks. A hook runs a shell command on an agent event. Read these files and look for hooks that you did not add:

cat ~/.claude/settings.json
cat .claude/settings.json .claude/settings.local.json 2>/dev/null

VS Code and Cursor tasks. Sonatype tells you to check .vscode/tasks.json. Check the Cursor folder in the same way.

find ~ -maxdepth 6 -path "*/.vscode/tasks.json" 2>/dev/null
ls -la ~/.cursor .cursor 2>/dev/null
cat ~/.cursor/mcp.json 2>/dev/null

Shell startup files.

tail -n 30 ~/.zshrc ~/.zprofile ~/.bash_profile ~/.bashrc ~/.profile 2>/dev/null

macOS background items. CSA reports token-monitoring services at the operating system level that survive reboots.

ls -la ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons
launchctl list | grep -vi apple
sfltool dumpbtm | head -100

Linux services.

ls -la ~/.config/systemd/user /etc/systemd/system 2>/dev/null
systemctl --user list-units --type=service --state=running
crontab -l

CSA states that removing the package may not remove these items. Remove them by hand.

How do I fix it now?

Follow these steps in order. Sonatype advises to isolate, preserve logs, remove persistence, and only then rotate.

  1. Isolate the machine. Disconnect it from the network. For a CI runner, cancel the job and disable the runner.
  2. Keep the evidence. Copy the lockfile, the shell history, and the CI logs. Take a disk image if the machine is a company device.
  3. Do not revoke tokens yet on the infected machine. One CSA report says revoking a stolen npm token may trigger a destructive wipe on some variants. It states this with a hedge. Isolate first, then remove persistence, then rotate.
  4. Remove persistence. Delete the bad hooks, tasks, startup lines, and service files that you found.
  5. Remove the package. Delete node_modules and pin a known good version.
rm -rf node_modules
npm ci --ignore-scripts

Sonatype warns that a higher version number is not proof of safety. Use a version from the advisory that is marked clean.

  1. Rebuild from a clean place. If the machine ran the payload, reinstall the operating system. Restore only documents. Do not restore shell files, hooks, or node_modules.
  2. Rotate secrets from a clean device. See the next section.
  3. Check GitHub and npm. See the section after that.

Warning: Do not run npm install again on the infected machine. It can run the script again.

Which secrets must I rotate?

The payload searches for secrets in many places. Sonatype lists npm, GitHub, cloud, CI and CD, database, SSH, payment, and messaging secrets. CSA lists more than 100 file paths, cloud metadata, Kubernetes tokens, and Vault.

Treat every secret that the machine or runner could read as stolen. Rotate in this order:

  1. npm tokens. Revoke them and create new ones with the smallest rights.
npm token list
npm token revoke <id>
  1. GitHub tokens and keys. Revoke personal access tokens, deploy keys, and SSH keys. Revoke OAuth apps that you do not know.
  2. CI secrets. Rotate every secret in GitHub Actions, GitLab CI, and other systems. Include OIDC trust settings.
  3. Cloud keys. Rotate AWS, Google Cloud, and Azure credentials. Check the role that the machine used.
  4. AI provider keys. Rotate OpenAI, Anthropic, and other keys.
  5. Database and backend secrets. Rotate every value in each .env file. This includes Supabase service role keys, Stripe keys, and webhook secrets.
  6. SSH keys. Create new keys. Remove the old ones from all servers.
  7. Browser and password manager. Change the passwords that were on the machine.

List the files that held secrets:

find ~ -maxdepth 5 -name ".env*" -not -path "*/node_modules/*" 2>/dev/null
ls -la ~/.npmrc ~/.ssh ~/.aws ~/.config/gh 2>/dev/null

For a leaked GitHub secret, read what to do after a GitHub secret alert.

How do I check for new repositories and workflow files?

The malware uses stolen tokens to write to GitHub. CSA reports more than 400 repositories that the malware created with stolen credentials, and workflow files that it injects into reachable repositories. Check your account from a clean device.

  1. List recent repositories. Look for names and dates that you do not know.
gh repo list --limit 100 --json name,createdAt,visibility,isFork --jq 'sort_by(.createdAt) | reverse | .[:20]'

Repeat for each organization that you belong to.

  1. Check the security log. Open Settings, then Security log. Look for new tokens, new keys, and new apps.
  2. List SSH keys and deploy keys.
gh api user/keys --jq '.[] | {title, created_at}'
  1. Find new workflow files. In each repository, look for workflow files that you did not add.
git fetch --all
git log --all --since="2026-05-01" --name-status --pretty=format:'%h %an %ad %s' -- .github/workflows
  1. Check the branches. Look for new branches with odd names.
git branch -r --sort=-committerdate | head -20
  1. Read the workflow runs. Open the Actions tab. Look for runs that you did not start. A workflow that prints secrets to a log is a strong sign.
  2. Check npm. Open your npm account. Check the package list for versions that you did not publish. Unpublish or deprecate the bad versions, and tell the users.

If a stolen token published bad versions of your own packages, contact npm support and publish a notice. Your users need to know the exact versions.

How do I stop this in the future?

Install scripts are the main entry. Remove them, and review each new dependency.

How do I turn off install scripts?

Set ignore-scripts in npm. The npm documentation says that npm then does not run the scripts in package.json files.

npm config set ignore-scripts true

For a project, add it to .npmrc in the repository:

ignore-scripts=true

In CI and agent sandboxes, use the flag on each install:

npm ci --ignore-scripts

Some packages need a build step. Run it yourself for the packages that you trust:

npm rebuild some-trusted-package

npm 12 does not run dependency install scripts unless you approve them, The Hacker News reports. Older versions and some configurations still run them. Check your version with npm --version.

How do I keep agents from installing packages without review?

  • Remove the install permission. Do not allow the agent to run npm install with no prompt. See how agents run dangerous commands.
  • Use a sandbox. Run the agent in a container with no secrets and no network access to your internal systems.
  • Give the agent no tokens. Do not put npm, GitHub, or cloud tokens in the agent environment.
  • Block install in the rules. Tell the agent in CLAUDE.md or a rules file to ask before it adds a dependency. Treat it as a request, not a control. Use permission settings for real enforcement.

How do I pin and review dependencies?

  • Commit the lockfile. Use npm ci in CI. It installs exactly what the lockfile lists.
  • Review the lockfile diff. Require a human review for any change to package.json or package-lock.json. Use a CODEOWNERS entry for both files.
  • Wait before you upgrade. CSA suggests a 48 to 72 hour observation window for AI SDKs. The --before option installs only versions that existed before a date.
npm install --before=2026-11-01
  • Pin exact versions. Use npm config set save-exact true. Avoid ^ ranges for packages with install scripts.
  • Check new names. Check the age, the maintainers, and the download history of each new package.
  • Scope publish rights. Use short-lived tokens for publishing. Require approval on publish workflows.
  • Limit CI. Give each job the smallest token. Do not let pull requests from forks read secrets. See poisoned CI and DevOps leaks.
  • Watch the network. Block outbound traffic from build jobs except to the hosts that they need.

When should I get help?

Ask for help in these cases:

  • You find a payload, a hook, or a service that you cannot explain.
  • The infected machine or runner held production secrets, signing keys, or publish rights.
  • You see new repositories, new workflow files, or new package versions that you did not publish.
  • The machine is a company device. Tell your security team before you wipe it.

Give the team the lockfile, the list of artifacts, and the time line. Run a scan on each app whose keys were exposed to see what an attacker can reach.

Common questions

Did the malware run if I did not start the app?
It can run at install time. An npm preinstall or postinstall script runs during npm install. You do not need to start the app.
Is it enough to delete node_modules?
No. The malware may have run already and may have left persistence. Delete the folder, but also check hooks, startup files, and workflow files, then rotate secrets.
Do I rotate secrets first or remove the malware first?
Isolate the machine and remove persistence first. Rotate from a clean device. One report says revoking a stolen token can trigger a wipe on some variants.
Does npm audit find this?
Only after an advisory exists. A new attack can run for hours before it appears. Check the vendor advisories for the package name and version.
Do valid provenance badges prove a package is safe?
No. CSA reports that malicious Mini Shai-Hulud packages carried valid SLSA provenance. Provenance shows where a build ran, not that the code is safe.

Test what stolen keys reach

A VibeEval scan tests the live web app and API from outside. Run it on the apps whose keys were on the infected machine or CI runner, to see what an attacker could reach.

14-day free trial · Cancel anytime

SCAN YOUR APP →