Back to glossary

Remote Code Execution (RCE)

Remote code execution (RCE) is a flaw that lets an attacker run arbitrary commands on a system they do not control, from across a network.

Remote code execution (RCE) is a vulnerability class that lets an attacker run their own commands on a machine they do not control, by pushing code across a boundary meant to carry only data. In the open source software supply chain that boundary is already open: package managers run a dependency's code at install time by design.

That design choice is where most supply chain attacks land. Almost every npm worm and credential stealer of the past year executed at install time, before a single line of application code loaded, so a malicious package needs no vulnerability of its own. We think default-on install scripts were a mistake, and the ecosystem now agrees: npm v12 and pnpm 10 both turned them off by default in 2026.

What is remote code execution?

#

Remote code execution is any path that ends with an attacker's code running on a system they do not own. Classically it is a bug: the attacker supplies data, and a flaw lets that data cross into the instruction stream. Three families produce most of it.

Command injection passes untrusted input into a shell or interpreter; the underlying weakness is CWE-94, improper control of code generation. Insecure deserialization rebuilds attacker-controlled objects and invokes callables while doing so. Memory corruption overwrites control data until execution jumps to attacker-chosen bytes.

Log4Shell is the canonical case. A crafted string in a logged field, tracked as CVE-2021-44228 and rated CVSS 10.0, made Log4j perform a JNDI lookup and load a remote Java class. Apache's advisory describes the affected versions as ones that do not protect against attacker-controlled LDAP and other JNDI related endpoints (Apache Log4j Security). A more recent example is React Server Components: CVE-2025-55182, disclosed December 2025 at CVSS 10.0, let an unauthenticated request deserialize into remote code execution.

Deserialization is the family developers underrate, because the “data” file looks inert. Python's pickle makes the danger explicit. Its own documentation warns that it is possible to construct malicious pickle data which will execute arbitrary code during unpickling (Python docs). The whole exploit is a five-line object:

Python
import pickle, os

class Exploit:
    def __reduce__(self):
        return (os.system, ("id -u",))

pickle.loads(pickle.dumps(Exploit()))  # runs: id -u

On unpickling, Python calls whatever __reduce__ returns: a callable and its arguments. Point that callable at os.system and loading the file becomes running a command. This is why loading a model checkpoint can be remote code execution, not just reading data.

How do install scripts make a package install remote code execution?

#

Install scripts make a package install remote code execution because the package manager runs them for you, automatically, with no vulnerability involved. In npm, the preinstall, install, and postinstall hooks fire during npm install. A binding.gyp file triggers an implicit node-gyp rebuild even when the package declares no install script at all.

The entire attack fits in a manifest. This package runs a command on install and nothing else:

JSON
{
  "name": "evil-pkg",
  "version": "1.0.0",
  "scripts": {
    "postinstall": "node -e \"console.log('running as', os.userInfo().username)\""
  }
}

Installed with npm 10, the script runs the moment the package lands in node_modules, with no import and no flaw:

Bash
$ npm install ./evil-pkg
> evil-pkg@1.0.0 postinstall
> node -e "console.log('running as', os.userInfo().username)"
running as root
added 1 package

Installed from the same tarball with npm v12, the script is skipped by default:

Bash
$ npm install ./evil-pkg
added 1 package
npm warn install-scripts 1 package had install scripts blocked because
npm warn install-scripts   they are not covered by allowScripts:
npm warn install-scripts   evil-pkg@1.0.0 (postinstall: node -e ...)

We also confirmed the implicit path directly: a binding.gyp with no declared script still compiled and executed code under npm 10, and was blocked under npm v12. As of November 2026, npm v12 and pnpm 10 ship with this execution off by default; older npm installs still run it.

Attackers reach for this path constantly. The jscrambler package was republished with a hidden preinstall hook that dropped a Rust infostealer. The Mastra campaign added a single typosquatted dependency, easy-day-js, whose postinstall hook ran before any Mastra code was imported. On the PHP side, the Laravel Lang compromise shipped a backdoor through Composer's autoload.files, which executes whenever the autoloader loads.

Where package managers run a dependency's code

#

Install scripts are only one of several places a package manager hands a dependency the CPU. We mapped the execution points across ecosystems and the default that now governs each one.

TriggerWhen it runsRuns code by default?
npm / pnpm lifecycle scriptsduring installNo in npm v12 and pnpm 10; yes in older npm
npm binding.gyp (node-gyp)during installNo in npm v12; yes in older npm
Python sdist setup.pyduring pip installYes (installing a wheel avoids it)
Python .pth / sitecustomize.pyat interpreter startupYes
PHP Composer autoload.fileswhen the autoloader loadsYes
Rust Cargo build.rsjust before compileYes
Go moduleson fetch and buildNo, by explicit design
pickle / torch.loadon deserializeYes (weights_only=True avoids it)

The verdict: only Go refuses to run dependency code before you call it — its toolchain treats that as a security goal — and only npm and pnpm have closed the install-script hole by default. Everywhere else, assume that adding a dependency can run its code.

Turning off install scripts does not close the hole

#

Blocking install scripts stops one trigger, not all of them. When jscrambler's install hook was flagged, the same actor moved the identical dropper into the package's top-level module code, so it fired on import and survived npm install --ignore-scripts.

LiteLLM 1.107.0 skipped install scripts entirely. Its payload lived in a cook.pth file and a sitecustomize.py, both of which Python executes at interpreter startup, so simply starting python or pip in the environment ran the credential collector. Inspecting the wheel as a ZIP did not.

This is also why a clean lockfile is weak evidence. Our analysis of the axios compromise showed that code fetched by npx or a global install never appears in a project's lockfile, so a lockfile checked after the fact does not prove you were safe: the absence of evidence after the fact is not strong evidence of absence.

And the deserialization path needs no package manager at all. PyTorch Lightning accepted crafted checkpoints that executed code through torch.load, affecting every version up to and including 2.4.0. Loading the model was the exploit.

Classic RCE
A bug lets data become code
Attacker sends crafted input (a log string, a serialized object, an oversized buffer)
↓
A flaw crosses the data → code boundary (injection, deserialization, memory corruption)
↓
Attacker code runs with the process's privileges
Requires a vulnerability
Example: Log4Shell, CVE-2021-44228, CVSS 10.0
Supply-chain RCE
The install already runs code
Attacker ships code as a dependency (a package, a lockfile entry, a model file)
↓
The toolchain runs it by design (install script, build.rs, .pth, autoload, unpickle)
↓
Attacker code runs with the developer's or CI's privileges
Requires no vulnerability
Example: install jscrambler@8.14.0, payload fires before any import

The two shapes of RCE. Classic remote code execution needs a vulnerability: an attacker sends crafted input, a flaw (injection, deserialization, or memory corruption) carries it across the data-to-code boundary, and the attacker's code runs with the process's privileges — as in Log4Shell, CVE-2021-44228, CVSS 10.0. Supply-chain RCE needs no vulnerability: an attacker ships code as a dependency, the toolchain runs it by design (an install script, a build.rs, a .pth line, a Composer autoload entry, or an unpickle), and it runs with the developer's or CI runner's privileges — as when installing jscrambler@8.14.0 fired its payload before any import.

How do you prevent remote code execution?

#

Preventing remote code execution means closing the specific boundary each variant crosses, and no single control closes all of them. For classic RCE: patch the vulnerable runtime, validate and encode untrusted input, and never deserialize untrusted data with an executing format. Load models with weights_only=True or a non-executing format instead of raw pickle.

For supply-chain RCE the controls are different. Turn install scripts off by default, as npm v12 and pnpm 10 now do; the cost is real, because native modules like sharp or better-sqlite3 build through install scripts and now need explicit approval. Add a dependency cooldown so a version is not installed the instant it publishes. Neither stops import-time or load-time execution, so the durable control is to analyze what a package actually does before it runs — whether it opens a shell, reaches the network, or reads credentials — rather than whether its metadata looks clean.

Two assumptions are worth dropping. A CVE scanner will not catch any of the attacks above, because malware is not assigned a CVE. And package provenance is necessary but not sufficient: LiteLLM's malicious container shipped with valid build provenance that happened to record a one-hyphen lookalike source repository, and compromised maintainers routinely publish through legitimate, signed pipelines.

This is the gap Socket targets. Socket's AI scanner flags packages on behavior rather than known CVEs, and in these incidents it flagged the malicious jscrambler release six minutes after publication and the LiteLLM wheels seven minutes after, per Socket's write-ups. Its install-scripts alert marks any package that runs code at install time, before it reaches a developer's machine or a build.

The deeper problem is that installing and running a dependency were never really separate. Turn off install scripts and the code still runs at import, at build, at autoload, at the next torch.load. The only safe assumption is that every dependency is code you will execute, which means the decision that matters is made before it enters the tree, not after.