What is runc?
Every container you have ever started on Linux — docker run, a Kubernetes pod, podman run — ends in the same place: a single binary called runc is handed a directory and a JSON file, creates one process inside a set of kernel namespaces and cgroups, and exits. runc is the reference implementation of the OCI Runtime Specification. It has no daemon, no image store, no network, no registry client. Everything above it exists to produce its two inputs.
One sentence to carry the whole way down: runc reads config.json, asks the kernel for exactly what it says, execves your program — and leaves.
This article drives runc by hand, with no Docker or containerd in the path, and shows the real output. Every block below was produced by the script at the end on Linux 7.0 with cgroup v2, using Alpine’s runc package:
$ runc --version
runc version 1.3.7
commit: a78754feb393d108d3da36700decf1e228a53a7f
spec: 1.2.1
go: go1.24.13
libseccomp: 2.6.1
$ apk info -s runc
runc-1.3.7-r0 installed size:
11 MiB
Where it sits
The OCI Runtime Specification is the contract: a bundle is a directory holding config.json and a root filesystem, and a runtime must implement five operations — state, create, start, kill, delete. runc is the implementation the spec was extracted from (Docker donated its libcontainer in 2015) and is still the default runtime of Docker and containerd.
The input: a bundle you can build with tar
A bundle needs no image format, no layers and no registry. Here the root filesystem is just the files of an Alpine install copied into a directory, and runc spec writes a default config.json next to it:
$ du -sh rootfs
8.6M
$ runc spec && wc -c config.json
2500 config.json
What runc puts in that default, read straight out of the JSON:
| field | default from runc spec |
|---|---|
linux.namespaces | pid, network, ipc, uts, mount, cgroup — no user |
process.capabilities.bounding | CAP_AUDIT_WRITE, CAP_KILL, CAP_NET_BIND_SERVICE — 3 of 41 |
mounts | /proc proc · /dev tmpfs · /dev/pts devpts · /dev/shm tmpfs · /dev/mqueue mqueue · /sys sysfs · /sys/fs/cgroup cgroup |
linux.maskedPaths / readonlyPaths | 10 masked (e.g. /proc/kcore), 5 read-only (e.g. /proc/sys) |
linux.seccomp | null — no syscall filter at all |
root.readonly | true |
process.args | ["sh"], with terminal: true |
Two things stand out. The runc default is tighter than Docker on capabilities (Docker grants 14) but looser on syscalls: there is no seccomp profile unless the caller writes one into config.json. Docker writes its default profile in; runc never invents one. runc enforces exactly what the JSON says, nothing more. Every security property you associate with “a container” is a field some layer above runc chose to fill.
runc spec --rootless adds a user namespace and a one-entry uidMappings, and drops the network namespace:
$ runc spec --rootless
["pid","ipc","uts","mount","cgroup","user"] ← .linux.namespaces
[{"containerID":0,"hostID":0,"size":1}] ← .linux.uidMappings
hostID is the uid of whoever ran runc spec — 0 here because the lab runs as root; run as uid 1000 it would be 1000, and root inside the container maps to that unprivileged user outside.
Running it
Point process.args at a command, set terminal: false, and run:
$ runc run demo1
pid=1
runc
uid=0(root) gid=0(root)
3
0::/
Line by line: the shell is PID 1 of a new PID namespace; the hostname is runc (the spec’s default hostname, set in a new UTS namespace); it is root; /proc shows 3 processes (the shell, ls, grep) where the host shows hundreds; and its cgroup path is / because the cgroup namespace hides everything above it.
create and start are two different moments
runc run is a shortcut for create + start + wait + delete. Splitting them is what lets containerd and CRI-O set up networking between the two calls — and it exposes how runc works inside:
$ runc create demo2
$ runc state demo2 → {"status":"created","pid":90}
$ cat /proc/90/cmdline → runc init
$ readlink /proc/90/exe → /runc
$ grep PPid /proc/90/status → 1
$ runc start demo2
$ runc state demo2 → {"status":"running","pid":90}
$ cat /proc/90/cmdline → sleep 300
$ ps -o pid,ppid,comm
PID PPID COMMAND
1 0 sh
90 1 sleep
runc init already sits inside the new namespaces and cgroup, blocked on a FIFO. runc start unblocks it and it execves your program — same PID, new image. In the run above, ps found 0 runc processes once the container was running.Four details from that output, each one a piece of runc’s design:
runc initis runc re-executing itself. The child that becomes your container starts as runc, so it can finish setup from inside the namespaces. Its first code is C, not Go (nsexec, run as a constructor before the Go runtime starts): joining a mount or user namespace requires a single-threaded process, and the Go runtime is multi-threaded from its first instruction./proc/90/exeis/runc, not the installed binary. Since CVE-2019-5736 — a container overwriting the host’s runc through/proc/self/exe— runc runs a sealed, read-only copy of itself (recent releases mount it from a private read-only overlayfs, older ones used a sealed memfd).- PPid is 1.
runc createexited; the kernel reparentedrunc init. That is why Docker keeps a shim and Podman a conmon: something long-lived has to hold stdio and collect the exit code, and runc deliberately is not that thing. - Same PID before and after
start.execvereplaces the program, not the process — the container’s PID 1 is therunc initthat was created.
Namespace inodes confirm the fencing. The lab itself is a privileged Docker container, so the left column is the lab’s namespaces (its PID 1), not the machine’s — except user: 4026531837 is the kernel’s initial user namespace — readlink /proc/self/ns/user on the host prints the same user:[4026531837] — shared by the lab, the host and the runc container. The runc container differs from the lab in six types and matches in the one the spec did not ask for:
pid lab=pid:[4026549966] ctr=pid:[4026549863]
mnt lab=mnt:[4026549962] ctr=mnt:[4026549856]
uts lab=uts:[4026549964] ctr=uts:[4026549857]
ipc lab=ipc:[4026549965] ctr=ipc:[4026549858]
net lab=net:[4026549968] ctr=net:[4026549867]
cgroup lab=cgroup:[4026549967] ctr=cgroup:[4026549866]
user lab=user:[4026531837] ctr=user:[4026531837] ← host's
The shared user namespace is the line to remember: without one, uid 0 inside the container is uid 0 on the host, held back only by the dropped capabilities, the masked paths and whatever seccomp profile the caller added.
Limits are files runc writes
linux.resources in config.json becomes writes into the container’s cgroup v2 directory. Set a 16 MiB memory limit and print what the process sees:
# "memory": {"limit": 16777216, "swap": 16777216}
16777216 ← memory.max
0 ← memory.swap.max
max ← pids.max (not set)
Then make a child hold 64 MiB:
Killed
sort exit=137 (shell still alive)
oom_kill 1
The kernel’s OOM killer picked sort (exit 137 = 128 + SIGKILL) inside the cgroup and left the shell running; memory.events counted one kill.
With only a memory limit, nothing is killed. The same 64 MiB under {"limit": 16777216} alone, on a host with swap:
16777216 ← memory.max
max ← memory.swap.max
sort exit=0
oom_kill 0
67235840 ← memory.swap.peak: 64.1 MiB went to swap
runc left memory.swap.max at max, the kernel paged the excess out and sort finished. OCI swap is memory + swap combined, so swap == limit translates to memory.swap.max = 0. Docker hides the same rule: --memory without --memory-swap allows as much swap again as the memory limit.
A PID limit works the same way — "pids": {"limit": 5} and a shell that starts 8 background sleeps, then wait; echo done:
sh: can't fork: Resource temporarily unavailable
runc exit=2
done never prints: busybox sh treats a failed fork as fatal and exits with status 2, which runc run passes through as its own exit code.
What it costs
runc’s own overhead is a short chain of fork, exec and cgroupfs writes. Timed with bench.sh: three interleaved trials, each 100 × runc run of /bin/true in the lab followed by 50 × docker run --rm … /bin/true, both pinned to the same four CPUs (--cpuset-cpus=4-7):
/bin/true. runc alone: 18.6–31.3 ms. Through dockerd → containerd → shim → runc: 230.4–236.2 ms. The difference is the layers above runc, not runc.| runtime | trial | load | n | min (ms) | p50 (ms) | p90 (ms) | max (ms) |
|---|---|---|---|---|---|---|---|
| runc | 1 | 27.2 | 100 | 14.7 | 31.3 | 39.9 | 44.6 |
| runc | 2 | 22.3 | 100 | 13.1 | 18.6 | 36.7 | 48.1 |
| runc | 3 (median) | 19.6 | 100 | 14.5 | 26.0 | 39.8 | 45.9 |
| docker | 1 (median) | 27.2 | 50 | 207.1 | 235.4 | 601.6 | 1066.6 |
| docker | 2 | 22.3 | 50 | 207.6 | 236.2 | 269.3 | 458.6 |
| docker | 3 | 19.6 | 50 | 203.5 | 230.4 | 243.7 | 258.6 |
Median batch by p50: runc 26.0 ms, Docker 235.4 ms — 9.1×; across the three trials the p50 spread is 18.6–31.3 ms for runc and 230.4–236.2 ms for Docker. The machine was not idle: load is the 1-minute load average on 32 hardware threads at the start of each trial, from other jobs, and the pinned CPUs were shared with them. Pinning both sides to the same cpuset and interleaving the trials makes the comparison fair under that load; the absolute numbers on an idle machine will be lower. Docker’s p90/max in trial 1 show what the daemon path adds under contention — runc’s tail stayed under 50 ms in every trial. The pinning covers the container processes and, for runc, the runc binary itself; dockerd and containerd are host daemons and ran unpinned.
runc is one of several OCI runtimes
Because the interface is a spec, the runc binary can be swapped for another OCI runtime CLI — containerd, CRI-O and Podman take a runtime path. One row below is not a CLI at all:
| runtime | language | how it isolates | note |
|---|---|---|---|
| runc | Go + C (nsexec) | namespaces + cgroups on the host kernel | reference implementation; default for Docker and containerd |
| crun | C | same | smaller binary, faster start; default in Podman on Fedora/RHEL |
| youki | Rust | same | OCI-compliant, memory-safe implementation |
| runsc (gVisor) | Go | a user-space kernel intercepts syscalls | stronger boundary, higher syscall cost |
| Kata Containers 2.x | Go + Rust | a lightweight VM per pod | separate guest kernel; no runc-compatible CLI — it plugs in one level up, as the containerd shim containerd-shim-kata-v2 (CRI-O uses the same shim API) |
crun and youki are drop-in replacements for the runc binary: same CLI verbs, same namespaces, same cgroups, same kernel. runsc is also an OCI runtime CLI but changes the boundary. Kata changes the boundary too, but replaces the shim + runc pair rather than runc alone.
Security: runc is the boundary
runc usually runs as root and is the last code that executes on the host side before the container’s program. Its CVEs are therefore container escapes:
- CVE-2019-5736 — a malicious container overwrote the host runc binary through
/proc/self/exe. Fixed by the sealed copy seen above. - CVE-2024-21626 (“Leaky Vessels”) — a file descriptor to the host’s
/sys/fs/cgroupleaked into the container, reachable through a crafted working directory. Fixed in 1.1.12. - CVE-2025-31133, CVE-2025-52565, CVE-2025-52881 (November 2025) — races around
maskedPathsand/dev/consolebind mounts that could redirect runc’s writes into/proc. Fixed in 1.2.8, 1.3.3 and 1.4.0-rc.3.
What to take from that list: keep runc current (it ships through your distribution or containerd package, not with Docker’s version number), and treat a shared host kernel as a real boundary only as strong as the runtime and the profile above it. The default config.json above has no seccomp filter and no user namespace — whatever builds the bundle decides how much of that gap is closed.
TL;DR: runc is the OCI reference runtime: a short-lived CLI, not a daemon. It takes a bundle —
config.json+rootfs/— and turns it into one process inside new namespaces, a cgroup whose limits it writes as files, a reduced capability set and whatever seccomp profile the JSON contains (the default contains none).createleavesrunc initblocked on a FIFO inside the fences;startmakes itexecveyour program with the same PID; runc then exits, which is why Docker keeps a shim and Podman a conmon. Measured here, runc alone starts and reaps a container in tens of milliseconds (median p50 26.0 ms, pinned, on a busy host), Docker’s full stack in hundreds (235.4 ms) — 9.1×. crun and youki are drop-in alternatives; gVisor’s runsc keeps the CLI but moves the boundary, Kata replaces the shim + runc pair with a VM.
Method
Everything ran in one throwaway privileged container — no Docker or containerd inside it, runc from Alpine’s package:
docker run --rm --privileged --cgroupns=private \
-v "$PWD/lab.sh":/lab.sh:ro \
alpine:3.22@sha256:49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f \
sh /lab.sh
lab.sh:
#!/bin/sh
set -e
# cgroup v2 "no internal processes": leave the root so runc can create children with controllers
mkdir -p /sys/fs/cgroup/init && echo $$ > /sys/fs/cgroup/init/cgroup.procs
echo '+memory +pids +cpu' > /sys/fs/cgroup/cgroup.subtree_control
mkdir -p /lab/bundle/rootfs && cd /lab/bundle
# rootfs = this Alpine's own files, copied before runc is installed
tar -C / -cf - bin etc lib sbin usr var 2>/dev/null | tar -C rootfs -xf -
mkdir -p rootfs/proc rootfs/sys rootfs/dev rootfs/tmp
apk add -q runc jq coreutils >/dev/null 2>&1
runc --version; apk info -s runc; du -sh rootfs | cut -f1
runc spec; wc -c config.json
jq -c '[.linux.namespaces[].type]' config.json
jq -c '.process.capabilities.bounding' config.json
jq -r '.mounts[] | "\(.destination) \(.type)"' config.json
jq -c '[(.linux.maskedPaths|length), (.linux.readonlyPaths|length)]' config.json
jq -c '.linux.seccomp' config.json
mkdir -p /lab/rl && (cd /lab/rl && runc spec --rootless \
&& jq -c '[.linux.namespaces[].type]' config.json && jq -c '.linux.uidMappings' config.json)
# foreground run
jq '.process.terminal=false | .process.args=["sh","-c","echo pid=$$; hostname; id; ls /proc | grep -c \"^[0-9]\"; cat /proc/self/cgroup"]' config.json > c2 && mv c2 config.json
runc run demo1
# create / start split
jq '.process.args=["sleep","300"]' config.json > c2 && mv c2 config.json
runc create demo2
runc state demo2 | jq -c '{status,pid}'
PID=$(runc state demo2 | jq .pid)
tr '\0' ' ' < /proc/$PID/cmdline; echo; readlink /proc/$PID/exe
awk '/^PPid/{print $2}' /proc/$PID/status
for n in pid mnt uts ipc net cgroup user; do
echo "$n lab=$(readlink /proc/1/ns/$n) ctr=$(readlink /proc/$PID/ns/$n)"; done
runc start demo2
runc state demo2 | jq -c '{status,pid}'
tr '\0' ' ' < /proc/$PID/cmdline; echo
ps -o pid,ppid,comm | grep -c runc || true
ps -o pid,ppid,comm; runc list
runc kill demo2 KILL; sleep 0.3; runc state demo2 | jq -c '{status}'; runc delete demo2
# cgroup limits — first a memory limit without a swap cap
jq '.linux.resources.memory={"limit":16777216} | .process.args=["sh","-c","cat /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory.swap.max; head -c 67108864 /dev/zero | tr \\\\0 a | sort > /dev/null; echo sort exit=$?; grep oom_kill /sys/fs/cgroup/memory.events; cat /sys/fs/cgroup/memory.swap.peak"]' config.json > c2 && mv c2 config.json
runc run oomA
# then with swap capped: OCI swap = memory + swap
jq '.linux.resources.memory={"limit":16777216,"swap":16777216} | .process.args=["sh","-c","cat /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory.swap.max /sys/fs/cgroup/pids.max"]' config.json > c2 && mv c2 config.json
runc run mem1
jq '.process.args=["sh","-c","head -c 67108864 /dev/zero | tr \\\\0 a | sort > /dev/null; echo \"sort exit=$? (shell still alive)\"; grep oom_kill /sys/fs/cgroup/memory.events"]' config.json > c2 && mv c2 config.json
set +e; runc run oom1; echo "exit=$?"; set -e
jq '.linux.resources.pids={"limit":5} | .process.args=["sh","-c","for i in 1 2 3 4 5 6 7 8; do sleep 2 & done; wait; echo done"]' config.json > c2 && mv c2 config.json
set +e; runc run pid1; echo "runc exit=$?"; set -e
On the host itself, readlink /proc/self/ns/user printed user:[4026531837].
The timing numbers come from bench.sh, run on the host (Docker Engine 29.1.3, default runtime runc), with timing.sh next to it:
#!/bin/bash
# 3 interleaved trials: runc run (in the lab container) vs docker run, both pinned to the same cpuset
set -e
CPUS=${CPUS:-4-7}
IMG=alpine:3.22@sha256:49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f
cd "$(dirname "$0")"
stats() { sort -n | awk -v L="$1" '{a[NR]=$1} END{printf "%s n=%d min=%.1f p50=%.1f p90=%.1f max=%.1f ms\n", L, NR, a[1]/1000, a[int(NR/2)]/1000, a[int(NR*0.9)]/1000, a[NR]/1000}'; }
for t in 1 2 3; do
echo "trial $t load=$(cut -d' ' -f1 /proc/loadavg)"
docker run --rm --privileged --cgroupns=private --cpuset-cpus="$CPUS" -e N=100 \
-v "$PWD/timing.sh":/timing.sh:ro "$IMG" sh /timing.sh | stats "runc_run t$t"
for i in $(seq 50); do
s=$(date +%s%N); docker run --rm --cpuset-cpus="$CPUS" "$IMG" /bin/true; e=$(date +%s%N); echo $(( (e-s)/1000 ))
done | stats "docker_run t$t"
done
timing.sh (runs inside the lab container):
#!/bin/sh
set -e
N=${N:-100}
mkdir -p /sys/fs/cgroup/init && echo $$ > /sys/fs/cgroup/init/cgroup.procs
mkdir -p /lab/bundle/rootfs && cd /lab/bundle
tar -C / -cf - bin etc lib sbin usr var 2>/dev/null | tar -C rootfs -xf -
mkdir -p rootfs/proc rootfs/sys rootfs/dev rootfs/tmp
apk add -q runc jq coreutils >/dev/null 2>&1 # coreutils: busybox date has no %N
runc spec
jq '.process.terminal=false | .process.args=["/bin/true"]' config.json > c2 && mv c2 config.json
i=0
while [ $i -lt $N ]; do
s=$(date +%s%N); runc run t$i; e=$(date +%s%N); echo $(( (e-s)/1000 )); i=$((i+1))
done
The companion article How Docker works under the hood follows the layers above runc.
Sources
- OCI Runtime Specification — bundle, config, runtime operations
- runc (GitHub) — README,
libcontainer/nsenter - runc releases — 1.1.12, 1.2.8, 1.3.3 security notes
- CVE-2019-5736 — runc container breakout
- CVE-2024-21626 — runc working-directory fd leak
- Docker — runtime options: memory and swap
- Docker — default seccomp profile
- Linux kernel — Control Group v2 (memory.max, memory.swap.max, pids.max)
- crun · youki · gVisor · Kata Containers