# CVE-2026-58659: PyTorch Lightning remote code execution in load_from_checkpoint

Source: https://junglewise.ai/threats/cve-2026-58659-pytorch-lightning-remote-code-execution-in-load-from-checkpoint  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-07-15. Updated: 2026-07-15  
License: CC BY 4.0 with a link back

CVE-2026-58659 · Severity: high · CVSS 7.8 · Published 2026-07-15

PyTorch Lightning, a popular framework for high-level machine learning development, is vulnerable to a security flaw that allows for arbitrary code execution. An attacker can create a specially crafted model checkpoint file that, when loaded by a user, executes malicious commands on the user's system. This vulnerability is particularly dangerous because it bypasses standard security protections designed to make loading machine learning models safe.

Technologies: [lightning (PyPI)](https://junglewise.ai/threats/technologies/lightning), [pytorch-lightning (PyPI)](https://junglewise.ai/threats/technologies/pytorch-lightning). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2026-58659 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-58659 being exploited in the wild.

**How severe is CVE-2026-58659?** High severity, with a CVSS score of 7.8, published 15 July 2026.

**Which products and versions are affected?** lightning (PyPI) < 2.6.6, ECOSYSTEM:introduced=0,fixed=2.6.6; pytorch-lightning (PyPI) ECOSYSTEM:introduced=0,fixed=2.6.6.

**Is there a fix for CVE-2026-58659?** Yes. lightning (PyPI): upgrade to 2.6.6 or later; pytorch-lightning (PyPI): upgrade to 2.6.6 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-58659 attacked?** It is attacked with local access, in a software library.

**Am I affected by CVE-2026-58659?** Check whether you run lightning (PyPI) or pytorch-lightning (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- lightning (PyPI): upgrade to 2.6.6 or later

  ```sh
  pip install "lightning>=2.6.6"
  ```

- pytorch-lightning (PyPI): upgrade to 2.6.6 or later

  ```sh
  pip install "pytorch-lightning>=2.6.6"
  ```


## Technical details

A remote code execution vulnerability exists in PyTorch Lightning's `_load_state` function within `src/lightning/pytorch/core/saving.py`. The vulnerability stems from unsafe reflection (CWE-470) where the library reads a string field named `_instantiator` from a checkpoint's hyperparameters and uses it in an `__import__` and `getattr` call. Because this field consists of plain strings/dictionaries, it bypasses the `weights_only=True` security mitigation introduced in PyTorch to prevent pickle-based attacks. An attacker can achieve arbitrary code execution by tricking a user into calling `LightningModule.load_from_checkpoint` on a malicious checkpoint file. The issue is fixed in commit d710d68 by implementing an allowlist for trusted instantiators.

## Affected products

- Lightning-AI pytorch-lightning <= 2.6.5

## Identifiers

- CVE-2026-58659
- GHSA-qqmf-gpg7-g8gw
- PYSEC-2026-3624
- PYSEC-2026-3967

## Timeline

- 2026-06-09: disclosed: Reported via email to vendor
- 2026-07-14: patched: Fix merged in PR 21832
- 2026-07-15: advisory: CVE published and NVD record created

## References

- [https://github.com/Lightning-AI/pytorch-lightning/commit/d710d689510d50e800f53b3cd773cbca20b1f86f](https://github.com/Lightning-AI/pytorch-lightning/commit/d710d689510d50e800f53b3cd773cbca20b1f86f)
- [https://github.com/Lightning-AI/pytorch-lightning/issues/21822](https://github.com/Lightning-AI/pytorch-lightning/issues/21822)
- [https://github.com/Lightning-AI/pytorch-lightning/pull/21832](https://github.com/Lightning-AI/pytorch-lightning/pull/21832)
- [https://www.vulncheck.com/advisories/pytorch-lightning-arbitrary-code-execution-via-instantiator-hyperparameter](https://www.vulncheck.com/advisories/pytorch-lightning-arbitrary-code-execution-via-instantiator-hyperparameter)

## Related threats

- [PYSEC-2026-3968 - pytorch-lightning is vulnerable to Deserialization of Untrusted Data](https://junglewise.ai/threats/cve-2021-4118-pytorch-lightning-deserialization-of-untrusted-data)
- [PYSEC-2026-3971 - PyTorch Lightning denial of service vulnerability](https://junglewise.ai/threats/cve-2024-8020-pytorch-lightning-denial-of-service-vulnerability)
- [PyTorch Lightning code injection via eval()](https://junglewise.ai/threats/cve-2022-0845-code-injection-in-pytorch-lightning)
- [PYSEC-2026-3975 - pytorch-lightning vulnerable to Arbitrary File Write via /v1/runs API endpoint](https://junglewise.ai/threats/cve-2024-5980-pytorch-lightning-vulnerable-to-arbitrary-file-write-via-v1-runs)
- [PYSEC-2026-3974 - Remote code execution in pytorch lightning](https://junglewise.ai/threats/cve-2024-5452-remote-code-execution-in-pytorch-lightning)
