An npm worm that plants rogue MCP servers
Default rules refuse key steps
In February 2026, Socket found an npm worm that adds a fake tool server to AI assistants’ settings, with tool descriptions that tell the assistant to hand over your SSH keys and cloud credentials. Tego's default rules would refuse both steps: the agent can't read your keys, and a program run under Tego can't plant the server. A program run without Tego still can. We reproduced the incident's steps under these rules to confirm it.
What happened?
On 20 February 2026, Socket's Threat Research Team published an analysis of a campaign it calls SANDWORM_MODE. It found "at least 19 malicious npm packages" under two publisher aliases, official334 and javaorg. Many are typosquats, packages named one typo away from a real one, such as claud-code, cloude-code and suport-color. suport-color keeps the behaviour of the real supports-color, so a project that uses it still works.
The harmful code runs when the package is first loaded by a program, not when it is installed, in two stages:
- Stage 1 collects tokens and keys from files and sends any crypto keys at once to a Cloudflare Worker (a small program hosted on Cloudflare). Outside CI it starts on a 5 to 30 second timer.
- Stage 2 waits "a 48-hour base delay" plus "per-machine jitter of up to 48 additional hours", counted from the package folder's time stamp. In CI (automated build servers), spotted through variables such as
CIandGITHUB_ACTIONS, it runs at once.
One Stage 2 module, McpInject, targets AI assistants. An MCP server is a small program an assistant starts and calls as a tool. The module writes a malicious one into a hidden home folder such as ~/.dev-utils/, then adds it to every assistant's settings file it finds: Claude Code, Claude Desktop, Cursor, VS Code Continue and Windsurf. Each tool description hides text telling the assistant to read ~/.ssh/id_rsa, ~/.ssh/id_ed25519, ~/.aws/credentials, ~/.npmrc and the project's .env files, pass them to the tool, and not mention it.
Socket also lists AI API key theft, spreading through npm and GitHub, git hook persistence (code git runs on each commit), and data sent out over HTTPS, GitHub and DNS. npm removed the packages and Cloudflare took down the workers, though the article also says the packages were still live at the time of writing. Infosecurity Magazine reported the campaign on 23 February. Neither source gives victim counts or reports an assistant obeying.
Why the usual safety didn't catch it
No AI agent made a mistake here. A developer's node process loaded a package, with all of the user's rights. It could write ~/.claude/settings.json and ~/.cursor/mcp.json because the user can.
And the process that installs the package is not the one that plants the server: that comes days later, from whatever loads the package next.
How it could have been prevented
Two general habits stop this without knowing the worm in advance. Programs you run for a task change files only in that task's folders, so your home folder and assistants' settings stay out of reach. And no program reads your secret files unless you say so.
Tego enforces both with the Linux kernel, and its default rules would refuse both steps inside a run:
- The assistant can't fetch your keys. Tego always keeps a built-in list of secret files from the agent, and
~/.ssh,~/.awsand~/.npmrcare on it (contract semantics). An assistant under Tego that obeys the hidden instructions gets a permission error. Without root this holds while no folder the agent may write sits above those files (capabilities). Keys you pass in as environment variables stay in reach. - A program under Tego can't plant the server. With writes limited to your project folders, creating
~/.dev-utils/, writing the server and editing each settings file all fail with a permission error (capabilities).
That covers an agent like Tego's interactive Claude Code example running npm test on a package installed days earlier, once its rules allow npm, node and env (rules that allow an interpreter must allow env). It also covers a CI job under Tego, though a fresh build server may have no assistant settings to poison.
Tego's strict setup is three built-in rule sets: the agent can't read your secrets, can only reach the hosts you list, and can only change files in the folders you name. The strict setup is the general habit for the test runner, the editor and the assistant.
For a job that runs npm ci && npm test, we checked these rules against Tego's rules file format but have not run them. In Tego's rules file, that's:
fs:
write: ["./node_modules/", "./.npm-cache/", "./.tmp/", "/dev/null"]
net:
allow: ["tcp://registry.npmjs.org:443"]
env:
pass: ["PATH", "HOME", "LANG"]- Writes: only the project's install folders.
- Hosts: only the npm registry, so Stage 1's send to the Worker is most likely refused (capabilities). Tego matches the addresses a name resolves to (contract semantics), and the registry sits behind Cloudflare, so a destination sharing one of its addresses would not be told apart (Tego's feature list).
- Variables: with the CI variables gone, Stage 2 can't skip its delay. Since
npm ciinstalls fresh each run, its clock most likely restarts every time; that is a reading of Socket's code, not a test.
Tego can also log each refused read of ~/.npmrc or .env (schema). The full rules also refuse npm publish, by argument checks that are best effort. It runs without root, with port rules on Linux 6.7 or later (protection levels).
The honest limit: Tego doesn't judge packages, so the install still lands on disk, and if the next program to load it runs outside Tego, the plant goes through with your full rights.
Inside a run, name lookups through the machine's DNS resolver, the worm's third channel, stay open by default (operations, stated limit). Turning them off is meant to close it; some lookups slipped through until a fix on 16 October 2026 (operations), and we have not tested npm that way. Secret files off the built-in list, such as hardhat.config, foundry.toml or a .npmrc in the project, stay readable. An allowed node can do anything in its own memory (interpreters), and every allowed host is a way out (allowed hosts). Running as root adds a record of file reads but changes none of this. On macOS and Windows, which the worm also targets, Tego applies only inside a Linux VM.
The lesson
This worm installs in one process and strikes days later in another, so guarding the install alone misses it. Run the test runner, the editor and the assistant under rules that keep the home folder unwritable. And check your assistants' settings: Socket advises looking "for unexpected mcpServers entries", deleting node_modules/ after a bad install, rotating npm and GitHub tokens, and checking git config --global init.templateDir.
Sources (11 links)
Checked on 5 November 2026.
- Socket Threat Research Team, SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains, 20 February 2026.
- Infosecurity Magazine, Shai-Hulud-Like Worm Targets Developers via npm and AI Tools, 23 February 2026.
- Tego: README, TIERS.md, FEATURES.md, GAPS.md, OPERATIONS.md, contract semantics, backend capabilities, agent schema and the interactive Claude Code example.
Read next
Previous teardown
One issue title could hijack Cline's CI agent
Strict rules refuse key steps
Next teardown
One click could take over an OpenClaw assistant
Strict rules refuse key steps
Start here
Eleven agent incidents and the rule for each
Eleven agent incidents, each in one line.