Cycle's hosted MCP is live. Your AI tooling just learned DevOps.Read the announcement

What Is Remote Code Execution (RCE)?.

Remote code execution (RCE) is a vulnerability that lets an attacker run their own code or commands on a system they can reach over a network, without logging in or touching the machine. The attacker's code runs with the privileges of the vulnerable program, which is why RCE flaws are usually rated high or critical.

An RCE usually starts with something small: an HTTP header, a form field, an uploaded file or a log message that the application hands to a component that treats part of it as instructions. The bug can be in your own code, but it often sits in a library, framework or server you depend on.

In security, RCE means remote code execution (the acronym has unrelated meanings in insurance and real estate). This page covers how RCE vulnerabilities happen, real CVEs and how they're scored, and how to prevent RCE and contain the ones that get through.

How remote code execution works

Almost every RCE comes down to one mistake: data that came from outside gets treated as code. Programs hand strings to interpreters all the time: a shell parses a command line, a template engine evaluates expressions, a deserializer decides which classes to create. When attacker-controlled input reaches one of those interpreters without being kept strictly as data, the attacker gets to write part of the program.

Memory corruption gets there by a different route. In code written in C or C++, a buffer overflow, a use-after-free or a race condition can let crafted input overwrite memory that the program later uses to decide what to run. With enough control over that memory, the CPU ends up executing instructions the attacker chose.

The "remote" part is about reach: the attacker gets to the vulnerable code through a web request, a connection to an SSH or mail server, or a message on a queue. The worst cases need no account and no action from a user. Once their code runs, attackers typically install a backdoor, collect credentials, run a cryptominer or ransomware, or move on to other systems on the same network.

Common causes of RCE vulnerabilities

Command injection is the most direct pattern. An application pastes input into a shell command string, and the shell reads characters such as ;, | and $( in that input as syntax. Shellshock (CVE-2014-6271) was a variant inside Bash itself: through version 4.3 it executed trailing strings after function definitions in environment variables, and CGI scripts receive HTTP headers as environment variables, so a web request could run commands.

Code and template injection follow the same idea one level up: the input reaches eval(), an expression language or a template engine that can call methods. Server-side template injection happens when an application renders a template string a user supplied instead of passing the user's text into a fixed template as a variable. Atlassian Confluence's CVE-2022-26134 was an OGNL expression injection that let an unauthenticated attacker execute arbitrary code.

Unsafe deserialization turns a data format into code execution. Native formats such as Python's pickle and Java object serialization can name which classes to create and which methods to call while rebuilding objects. Python's pickle documentation warns: "It is possible to construct malicious pickle data which will execute arbitrary code during unpickling." CVE-2025-55182 in React Server Components was this kind: the vulnerable packages unsafely deserialized HTTP request data sent to Server Function endpoints, and React's advisory notes that apps supporting Server Components could be affected even without Server Functions of their own. Versions 19.0.1, 19.1.2 and 19.2.1 fix it.

Memory corruption bugs live in parsers, network daemons and other code written without memory safety. Address space layout randomization (ASLR) and non-executable memory make them harder to exploit than injection, but a working RCE exploit runs with the full privileges of the process.

File upload flaws come in two forms. Either the server stores an uploaded script somewhere it will execute it, such as a PHP file in a web root, or it passes the uploaded file to a parser with its own bug. ImageTragick (CVE-2016-3714) was the second kind: several ImageMagick coders passed parts of a crafted image to a shell, so resizing a user's profile picture could run commands.

Real-world RCE examples

Dates below are National Vulnerability Database (NVD) publication dates, and scores are CVSS v3.1 base scores as listed by NVD in November 2026.

CVE

Software

Published

Cause

CVSS v3.1

CVE-2014-6271 (Shellshock)

GNU Bash through 4.3

Sept 24, 2014

OS command injection (CWE-78)

9.8

CVE-2017-5638

Apache Struts 2 Jakarta Multipart parser

Mar 11, 2017

Command execution through crafted upload headers (CWE-755)

9.8

CVE-2021-44228 (Log4Shell)

Apache Log4j 2

Dec 10, 2021

JNDI lookups in logged data load remote code (CWE-917, CWE-502)

10.0

CVE-2022-26134

Atlassian Confluence Server and Data Center

June 3, 2022

OGNL expression injection (CWE-917)

9.8

CVE-2024-6387 (regreSSHion)

OpenSSH sshd 8.5p1 to 9.7p1

July 1, 2024

Race condition in a signal handler (CWE-362)

8.1

CVE-2025-55182

React Server Components 19.0.0, 19.1.0, 19.1.1 and 19.2.0

Dec 3, 2025

Unsafe deserialization of HTTP requests (CWE-502)

10.0 (CNA score)

Log4Shell affected Apache Log4j 2 versions 2.0-beta9 through 2.15.0 (apart from the 2.12.2, 2.12.3 and 2.3.1 security releases), whose JNDI features didn't protect against LDAP and other JNDI endpoints controlled by an attacker. An application only had to log a string the attacker supplied, such as a User-Agent header, for Log4j to evaluate a lookup inside it, connect out to the attacker's server and load code from there. CISA added it to its Known Exploited Vulnerabilities catalog on December 10, 2021, the day NVD published it. Apache disabled the behavior by default in 2.15.0 and removed it in 2.16.0. For many teams the hard part was finding every copy of Log4j, including the ones bundled inside vendor products.

CVE-2017-5638 in Apache Struts let remote attackers execute commands through crafted headers on a file upload request, and NVD notes it was exploited in the wild in March 2017. According to the US Government Accountability Office's report on the Equifax breach (GAO-18-559), attackers scanned Equifax's systems on March 10, 2017, two days after US-CERT publicly identified the vulnerability, and found an online dispute portal running it. Equifax's patch notice had gone to an out-of-date distribution list, and its own scan, run a week after the vulnerability was identified, didn't detect it on that portal. The attackers went on to access personal information of at least 145.5 million people.

regreSSHion took the memory corruption path. It reintroduced an old sshd race condition (CVE-2006-5051) that an unauthenticated client could trigger by not finishing its login in time. OpenSSH's 9.8 release notes say it may allow code execution as root, and that the exploit demonstrated against 32-bit Linux/glibc systems with ASLR took 6 to 8 hours of continuous connections on average in the lab.

RCE vs arbitrary code execution vs privilege escalation

Arbitrary code execution (ACE) is the broader term: any flaw that lets an attacker run code of their choosing. RCE is arbitrary code execution reached over a network. A bug that triggers when a user opens a crafted file is arbitrary code execution; whether advisories call it remote depends on how the file arrives.

Privilege escalation starts where code execution ends. The attacker already runs code on the system, often as an unprivileged user or inside a container, and uses a second flaw to gain more rights. Baron Samedit (CVE-2021-3156), a heap overflow in sudo before 1.9.5p2, let a local user become root and scores 7.8 with a Local attack vector. A container escape is privilege escalation across a boundary: in runc 1.0.0-rc93 through 1.1.11, a leaked file descriptor could give a new container process a working directory in the host's filesystem (CVE-2024-21626), fixed in runc 1.1.12.

Remote code execution

Arbitrary code execution

Privilege escalation

Where the attacker starts

On the network, usually with no account

Anywhere, including local files the victim opens

Already running code on the system

What they gain

Code running as the vulnerable service

Code running as the affected program

More rights: root, another user, or the host from inside a container

Typical CVSS Attack Vector

Network (AV:N)

Network or Local

Local (AV:L)

Example

Log4Shell, CVE-2021-44228

ImageTragick, CVE-2016-3714

Baron Samedit, CVE-2021-3156

Real attacks often chain these. An RCE in a web application gives the attacker a shell as the application's user, a privilege escalation bug turns that into root, and root on one host becomes credentials for the next. Each link is a separate vulnerability, so a defense that blocks any one of them, such as a seccomp profile that removes the system call a kernel exploit needs, stops the chain there.

How RCE severity is scored with CVSS

Advisories score severity with the Common Vulnerability Scoring System (CVSS), maintained by FIRST. The base score comes from a vector string that describes the flaw itself. Log4Shell's NVD vector is CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H. Read left to right, it says the attack works over the network, has low complexity, needs no privileges and no user interaction, affects resources beyond the vulnerable component (scope changed), and has high impact on confidentiality, integrity and availability. That combination is the maximum, 10.0.

CVSS maps scores to ratings: Low is 0.1 to 3.9, Medium 4.0 to 6.9, High 7.0 to 8.9, and Critical 9.0 to 10.0. Unauthenticated RCEs with vectors like Log4Shell's land in Critical. regreSSHion scored 8.1, High, because its attack complexity is High (AC:H): winning the race takes hours of attempts.

CVSS v4.0, published on November 1, 2023, renames the Temporal metrics to Threat metrics and labels scores by what they include, such as CVSS-B for base only. Advisories may carry a v3.1 score, a v4.0 score or both, so check the version before comparing two numbers.

A base score describes the bug in the abstract. Your exposure depends on where the component runs and whether anyone is exploiting it. CISA's Known Exploited Vulnerabilities (KEV) catalog lists CVEs with confirmed exploitation in the wild, and FIRST's Exploit Prediction Scoring System (EPSS) estimates the probability that a CVE will be exploited in the next 30 days. A 9.8 in a component you don't expose can wait behind an 8.1 on your internet-facing SSH servers, and anything on the KEV list that you do expose goes first.

How to prevent remote code execution

The most effective fix for injection-type RCE is to stop building code out of strings. Pass input to programs as separate arguments, to databases as query parameters, and to templates as variables, so no interpreter ever parses it as syntax. This Python script counts lines in a file two ways, with an input value that contains a shell metacharacter:

import subprocess
# A value that arrived from outside: a form field, an API parameter, a filename.
filename = "notes.txt; echo second command ran"
def count_lines_unsafe(name):
# The value is pasted into a command string, and a shell parses the result.
return subprocess.run(f"wc -l {name}", shell=True, capture_output=True, text=True)
def count_lines_safe(name):
# Each list item reaches wc as exactly one argument. No shell is involved.
return subprocess.run(["wc", "-l", "--", name], capture_output=True, text=True)
for func in (count_lines_unsafe, count_lines_safe):
result = func(filename)
print(f"{func.__name__}: exit {result.returncode}")
print(result.stdout + result.stderr)

Run it in a directory that contains a three-line notes.txt:

count_lines_unsafe: exit 0
3 notes.txt
second command ran
count_lines_safe: exit 1
wc: 'notes.txt; echo second command ran': No such file or directory

With shell=True and an f-string, the shell split the value at the semicolon and ran a second command. Here it's a harmless echo; it could have been any command the application's user may run. The list version passed the whole value to wc as one filename, and -- stops a value that starts with a dash from being read as an option. Once you pass shell=True, Python's subprocess documentation makes quoting the application's job and points to shlex.quote(). Leaving the shell out removes that job.

The same rule covers the other interpreters. Don't deserialize untrusted data with pickle, Java serialization or similar formats; use JSON and validate it against a schema, and sign data with an HMAC if it has to round-trip through a client. Don't render templates that users wrote. Keep eval() and expression languages away from request data entirely, and turn off features you don't use, the way Log4j first disabled message lookups by default and then removed them.

For uploads, accept only the file types you expect, store files under generated names outside any directory the web server executes from, and run thumbnailing and document conversion in a separate, locked-down process. For memory corruption, use memory-safe languages for new parsers and network services where you can, and keep compiler hardening and ASLR turned on.

None of this helps with a flaw in a dependency you didn't know you had. Keep an inventory of what each build contains, scan container images in CI and in the registry, follow advisories for your frameworks and servers, and set patch deadlines by exposure: days for an internet-facing service with a KEV-listed or critical RCE.

Containing RCE when prevention fails

Some RCE will eventually land, through a zero-day or a patch that hasn't rolled out yet. Containment decides what the attacker's code can do next: which user it runs as, what it can write, what it can reach on the network, and how much of the kernel it can touch. Sandboxing covers the general approach, and container hardening and container security basics cover containerized services.

Least privilege comes first. Run services as a non-root user, drop Linux capabilities they don't need, block privilege gains through setuid binaries with no-new-privileges, and mount the root filesystem read-only. For a container that doesn't need the network at all, remove it. Here are those settings on a container, running the commands an attacker would try first (app:1.0 is a small local BusyBox image):

docker run --rm \
--read-only \
--cap-drop ALL \
--security-opt no-new-privileges \
--network none \
--user 10001:10001 \
--pids-limit 100 \
--memory 256m \
app:1.0 sh -c 'id; grep CapEff /proc/self/status; touch /etc/x; wget -T 3 -q -O- http://10.0.2.2/'
uid=10001(app) gid=10001(app) groups=10001(app)
CapEff: 0000000000000000
touch: /etc/x: Read-only file system
wget: can't connect to remote host (10.0.2.2): Network is unreachable

The process has no effective capabilities, can't write to its filesystem and can't open a connection. Without those flags, the same commands ran as root with Docker's default capability set (CapEff: 00000000a80425fb) and wrote to /etc. The process and memory limits stop a runaway or hostile process from exhausting the host's PIDs and memory.

Most services need some network access, so allow outbound connections only to the databases and APIs the service calls and deny everything else. Log4Shell needed the vulnerable server to connect out to a server the attacker controlled, so a default-deny egress policy blocked the common exploitation path even on unpatched hosts. It also makes it harder to download more tools or send stolen data out.

Containers share the host kernel, so a kernel bug or a runtime bug like CVE-2024-21626 can turn an RCE inside a container into control of the host. Seccomp profiles cut the number of system calls the process can make, which removes much of the kernel surface that kernel exploits depend on. For code you already know is untrusted, such as customer scripts or code that an AI model wrote, use a stronger boundary: a user-space kernel such as gVisor, or a microVM with its own kernel. Patch runtimes, hypervisors and host kernels too; they get escape fixes like any other software.

AI agents need the same treatment, because running code is their job. An agent that writes and executes scripts is remote code execution by design, and a prompt injection in a page or file the agent reads can steer what that code does. Treat model output as untrusted input and give its execution environment the same least privilege, egress control and sandboxing; AI agent security covers the agent-specific parts.

Alert on the signs that containment is being tested: a web server process that spawns a shell, a service opening outbound connections it has never made, or new executables in a container that should be immutable. Those signals also catch a zero-day, which no scanner can match to a CVE.

Cookies

Cookies Preferences

We run basic, anonymous analytics by default to measure site traffic. By clicking "Accept," you allow additional cookies for advanced app improvements and tailored advertising. Choose what you share by clicking "Customize."