What is runc?

Architecture

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

Docker, Kubernetes via containerd or CRI-O, and Podman all prepare an OCI bundle and call runc; runc calls the kernel to create namespaces, cgroups, capabilities and seccomp around one process, then exits docker → dockerd images · networks kubelet CRI → containerd kubelet CRI → CRI-O podman daemonless containerd + shim-runc-v2 writes the bundle · shim stays as parent CRI-O + conmon conmon stdio · exit code OCI bundle = config.json + rootfs/ runc create · start · state · kill · delete · exec one process per call, then it exits clone · cgroupfs writes · pivot_root · execve Linux kernel namespaces what it sees cgroups v2 what it uses caps · seccomp what it may do pivot_root which / it has
Four front ends, one runtime. Docker and containerd-based Kubernetes reach runc through containerd-shim-runc-v2; CRI-O and Podman reach it through conmon. Each of them prepares an OCI bundle and calls the same CLI verbs. Podman and CRI-O can be configured to call crun instead — same spec, same verbs.

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:

fielddefault from runc spec
linux.namespacespid, network, ipc, uts, mount, cgroup — no user
process.capabilities.boundingCAP_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 / readonlyPaths10 masked (e.g. /proc/kcore), 5 read-only (e.g. /proc/sys)
linux.seccompnull — no syscall filter at all
root.readonlytrue
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 create leaves a runc init process blocked on exec.fifo inside the new namespaces and exits; runc start opens the fifo, runc init execs the user program with the same pid; runc kill and runc delete stop it and remove its state and cgroup runc create namespaces · cgroup · mounts then exits runc start opens exec.fifo then exits runc kill · delete signal · remove state and the cgroup pid 90 — one process for its whole life runc init blocked on exec.fifo · created sleep 300 after execve · running stopped then gone No runc process is alive between the calls: each verb is a short CLI run that reads and writes state.json under /run/runc/<id>. Parent of pid 90: whoever is left — the lab's PID 1 here, containerd's shim under Docker, conmon under Podman.
The created state is a real process: 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:

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):

Container start-to-exit latency, p50 of three interleaved trials pinned to the same four CPUs: runc run 31.3, 18.6 and 26.0 ms; docker run 235.4, 236.2 and 230.4 ms 0 p50, ms 50 100 150 200 runc run t1 31.3 ms t2 18.6 ms t3 26.0 ms docker run t1 235.4 ms t2 236.2 ms t3 230.4 ms
p50 of each trial: wall-clock time from spawn to exit for a container that runs /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.
runtimetrialloadnmin (ms)p50 (ms)p90 (ms)max (ms)
runc127.210014.731.339.944.6
runc222.310013.118.636.748.1
runc3 (median)19.610014.526.039.845.9
docker1 (median)27.250207.1235.4601.61066.6
docker222.350207.6236.2269.3458.6
docker319.650203.5230.4243.7258.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:

runtimelanguagehow it isolatesnote
runcGo + C (nsexec)namespaces + cgroups on the host kernelreference implementation; default for Docker and containerd
crunCsamesmaller binary, faster start; default in Podman on Fedora/RHEL
youkiRustsameOCI-compliant, memory-safe implementation
runsc (gVisor)Goa user-space kernel intercepts syscallsstronger boundary, higher syscall cost
Kata Containers 2.xGo + Rusta lightweight VM per podseparate 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:

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). create leaves runc init blocked on a FIFO inside the fences; start makes it execve your 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

Questions? Let's Chat :)

docker