If you have run pip install lightning (PyPI) in the last few days, stop what you are doing and read this. On April 30, 2026, a new PyTorch Lightning malware strain slipped onto PyPI inside two innocent-looking patch versions — 2.6.2 and 2.6.3. They looked like routine bug-fix releases. They were not. Hidden inside the package was a sophisticated, multi-stage payload dubbed “Shai-Hulud” by researchers at Semgrep. The moment you imported lightning, the payload activated, silently scanning your environment for credentials, cloud secrets, and API keys, then exfiltrating them through four separate channels.
This is not a theoretical risk. It is a live, confirmed supply-chain compromise of one of the most downloaded ML frameworks on Earth. And it signals something bigger: AI infrastructure has become the new frontier for software supply-chain attacks.
What Is PyTorch Lightning and Why Does This Matter?
PyTorch Lightning is a wrapper around PyTorch that abstracts away the boilerplate of training loops, distributed training, and checkpointing. If you have fine-tuned a large language model, trained a diffusion model, or run a computer-vision pipeline in the last three years, there is a good chance you have used it directly or pulled it in as a transitive dependency.
The numbers are staggering. The lightning package on PyPI averages roughly 8 million downloads per month. It is used by solo researchers, YC startups, and Fortune 500 data-science teams alike. Lightning AI, the company behind the project, has raised significant venture funding and counts major enterprises among its customers. In other words, this is not a niche academic tool. It is foundational infrastructure for modern machine learning.
That scale is precisely why it makes such a devastating target. A compromise here does not affect one application. It affects the entire pipeline that feeds into model training, from local Jupyter notebooks to multi-node GPU clusters in the cloud. When a foundational ML library turns malicious, the blast radius is measured in millions of environments, not thousands.
The Discovery: How the PyTorch Lightning Malware Was Found
The discovery came from Semgrep‘s supply-chain monitoring team, who flagged the anomalous versions within hours of publication. Their technical write-up, published the same day, reads like a cyber-thriller — except every detail is real.
The Injection Mechanism
The malicious versions added a hidden _runtime directory inside the Python package. Inside that directory sat two critical files:
_runtime/start.py— a Python loader that triggers on module import._runtime/router_runtime.js— a 14.8 MB obfuscated JavaScript payload.
When a developer typed import lightning — something that happens automatically in countless training scripts, Docker containers, and CI pipelines — start.py executed, bootstrapping the JavaScript payload. No extra install step. No suspicious setup.py hijinks. Just a normal import of a library millions of people trust.
This is how the PyTorch Lightning malware bootstrapped itself: silently, instantly, and with no user interaction beyond a routine import.

A Multi-Channel Exfiltration System
What makes Shai-Hulud genuinely alarming is not just that it steals data, but how relentlessly it tries to get that data out. The malware uses four parallel exfiltration channels, so even if one path is blocked by a firewall or DLP rule, the others keep firing:
Direct HTTPS POST to C2. Stolen credentials are immediately shipped to an attacker-controlled server over port 443. The domain is encrypted inside the payload, making static signature detection harder.
GitHub commit-search dead drop. The malware polls the GitHub commit search API for commit messages prefixed with
EveryBoiWeBuildIsAWormyBoi. These commits carry double-base64-encoded tokens that the malware decodes and uses to authenticate fresh GitHub sessions.Attacker-controlled public repositories. The malware creates public GitHub repos with randomly chosen Dune-themed names and the description
"A Mini Shai-Hulud has Appeared". Stolen credentials are committed as JSON files (base64-wrapped via the API) with innocuous commit messages likechore: update dependencies.Push to the victim’s own repository. If the malware gets hold of a
ghs_GitHub server-to-server token, it pushes stolen data directly into every branch of the compromised repository itself — hiding the leak in plain sight.
The Payload
The malware targets more than just GitHub tokens. Its credential-harvesting logic is exhaustive:
- Local files: Scans 80+ known credential paths for
ghp_,gho_, andnpm_tokens, reading up to 5 MB per file. - Shell & environment: Runs
gh auth tokenand dumps the entireprocess.envdictionary. - GitHub Actions runners: On Linux CI workers, it dumps the memory of the
Runner.Workerprocess and extracts every secret marked"isSecret": true. - Cloud providers: It hits AWS via IMDSv2 and ECS metadata endpoints, enumerates Secrets Manager and SSM Parameter Store; does the same for Azure Key Vault via
DefaultAzureCredential; and pulls every secret from GCP Secret Manager viaGoogleAuth.
Any machine that imported lightning during the exposure window should be treated as fully compromised.
Who Is at Risk?
The short answer: anyone who installed lightning==2.6.2 or lightning==2.6.3 between April 30 and the time PyPI quarantined the packages.
Because Python dependency resolution is transitive, you do not even need to have lightning in your top-level requirements.txt. If another library you depend on pulled it in — or if a teammate experimented with the new version in a virtual environment — your organization could be exposed.
The risk profile is especially severe for three groups:
ML Engineers and Researchers. Your local development machine likely contains AWS or GCP credentials, Hugging Face tokens, and wandb API keys. A single import lightning in a notebook could have shipped all of them to an attacker-controlled repo.
CI/CD Pipelines. If your GitHub Actions workflows install dependencies fresh on every run, the malware had access to runner memory — including repository secrets, workflow tokens, and sometimes cloud-assigned IAM credentials. Worse, if the compromised runner held a token with write access, the malware pushed persistence hooks and malicious workflows back into your repository.
Cloud Training Clusters. Managed notebook environments, SageMaker Studio, Vertex AI Workbench, and self-managed Kubernetes training jobs often run with broad IAM roles. The malware’s cloud-credential enumeration means a compromised training container could escalate from “stolen API key” to “full cloud-account takeover.”
If you are unsure whether you hit the affected versions, assume you did until proven otherwise. The PyTorch Lightning malware does not announce its presence; it simply takes what it finds and leaves.
Why AI Frameworks Are the New Frontline for Supply-Chain Attacks
Software supply-chain attacks are not new. The xz Utils backdoor in early 2024 taught the industry that even obscure compression libraries can become nation-state targets. The Codecov breach in 2021 showed how CI tooling can leak secrets at scale. But the PyTorch Lightning malware reveals a new, uniquely dangerous pattern: AI frameworks are the perfect beachhead for modern attackers.
The Trust Problem in ML Tooling
Machine-learning pipelines are uniquely trusting. A typical training workflow imports dozens of packages — Lightning, Transformers, Datasets, Weights & Biases, DeepSpeed, Accelerate — often in an isolated container with full GPU access and cloud credentials. Each import is an implicit act of trust. There is no sandbox. There is no prompt asking, “Are you sure you want to run this library?” You type import lightning, and 14.8 MB of obfuscated JavaScript gets a seat at the table.
The Serialization Risk
ML adds its own attack surface on top of traditional software. Model weights are commonly shipped as pickled Python objects, a serialization format that is trivial to weaponize. A malicious model file can execute arbitrary code on load. Training checkpoints, pretrained weights from unofficial mirrors, and Hugging Face repos with thousands of forks create a landscape where malicious payloads can hide inside the data itself, not just the code.
GPU Access = Compute Access
A compromised training node is not just a data breach. It is a compute resource. Attackers can abuse GPU clusters for cryptocurrency mining, password cracking, or — more strategically — as a launchpad for further attacks inside a corporate network. AI infrastructure tends to sit in high-trust network segments with access to data lakes, feature stores, and production model registries.
The “Shai-Hulud” Campaign Is Evolving
Semgrep assesses that this PyPI attack is the work of the same threat actor behind the “Mini Shai-Hulud” npm campaign. The naming conventions, dead-drop mechanics, and cross-ecosystem spread all match. In fact, the Lightning compromise is arguably more sophisticated because it bridges ecosystems: the entry point is a Python package, but the worm propagation happens through npm. If the malware finds npm publish credentials on an infected machine, it injects a setup.mjs dropper and router_runtime.js into every npm package that token can publish, bumps the patch version, and republishes — turning one compromise into a cascading infection across the JavaScript ecosystem.
This cross-language, cross-registry behavior is a wake-up call. Supply-chain security used to mean auditing your own language’s package manager. That is no longer enough. An infection in PyPI can jump to npm, and from there to every developer who installs a poisoned JavaScript dependency.
How to Protect Your AI Pipelines
The PyTorch Lightning malware compromise is a worst-case scenario, but it is also a blueprint for what to fix. Here is a pragmatic defense stack for ML teams.
Pin Dependencies and Audit Lockfiles
Stop using bare version ranges for critical ML libraries. Pin to exact versions in requirements.txt or pyproject.toml, and hash-pin in lockfiles (poetry.lock, Pipfile.lock, requirements-lock.txt). Before upgrading any foundational package — Lightning, PyTorch, Transformers — review the release notes, diff the source on GitHub, and check the PyPI upload timestamp. A patch version published at 3:00 AM on a holiday weekend is worth extra scrutiny.
Generate and Review SBOMs
Software Bills of Materials are not just for compliance auditors. For ML projects, an SBOM tells you exactly which packages are in your training container, which versions they are, and which transitive dependencies they pulled in. Tools like syft, pip-licenses, or cyclonedx-python can generate SBOMs automatically. Review them before every production deployment. If you see a package version you did not expect, investigate immediately.
Runtime Scanning and Sandboxing
Static dependency scanning catches known-bad versions, but it does not catch zero-day compromises. Complement it with runtime monitoring:
- Network egress filtering. Training containers rarely need unrestricted outbound HTTPS. Restrict them to known endpoints (your model registry, your cloud API, your logging service) and flag unexpected connections.
- Secret-scanner sidecars. Tools like
ggshieldor TruffleHog can scan environment variables and filesystems inside running containers for leaked credentials. - Sandboxed training jobs. Where possible, run training workloads in least-privilege environments with no direct cloud metadata access, no GitHub tokens, and read-only access to data stores. If the job does not need to push to GitHub, do not give it a token that can.
Monitor Your Model Registry and Artifact Store
If an attacker compromises your training pipeline, they may not just steal data — they may poison the models you produce. Implement checksums and signing for every artifact that lands in your model registry. Before deploying a model to production, verify its provenance: which container built it, which git commit, which dependency versions. Any mismatch should block deployment.
Audit for Persistence Hooks
The Shai-Hulud malware specifically targeted developer tooling for persistence. If you suspect exposure, audit your repositories for:
.claude/settings.jsonwith unexpectedSessionStarthooks..vscode/tasks.jsonwithrunOn: folderOpentasks.- Any
setup.mjsorrouter_runtime.jsfiles outside of known dependency trees. - GitHub Actions workflows named
Formatterthat dump secrets via${{ toJSON(secrets) }}.
Rotate every GitHub token, cloud credential, and API key that was present in any environment that imported the affected versions. Assume compromise, do not hope for the best.
Bottom Line
The PyTorch Lightning malware attack is not a niche security story. It is a watershed moment for AI infrastructure security. An attacker managed to upload malware to an 8-million-downloads-per-month package, and all it took for activation was the most routine action in a data scientist’s day: import lightning.
If you work in machine learning, MLOps, or DevOps, you need to act now. Check your lockfiles for lightning==2.6.2 or lightning==2.6.3. Audit your CI logs for installations on April 30. Rotate your tokens. And most importantly, treat your ML dependency tree with the same skepticism you bring to production server software — because attackers already do.
The future of AI security is not just about adversarial examples and prompt injection. It is about the supply chain that builds the models in the first place. And that supply chain, as this attack proved, is only as strong as its most trusted — and most targeted — dependency.
References and further reading
- Semgrep — Security Advisory: npm packages using secret-scanning tools to steal credentials (technical write-up covering the Shai-Hulud campaign)
- Aikido — Popular PyTorch Lightning Package Compromised by Mini Shai-Hulud
- Socket — Lightning PyPI Package Compromised
- OX Security — Lightning Python Package Infected in Shai-Hulud Attack
- PyTorch Lightning on GitHub
lightningon PyPI
Please let us know if you enjoyed this blog post. Share it with others to spread the knowledge! If you believe any images in this post infringe your copyright, please contact us promptly so we can remove them.