Sub topic 3
How Containers Isolate: Namespaces, Cgroups, Capabilities, Seccomp
This chapter assumes you can use the Linux command line, run basic Docker commands, and understand Linux users and file permissions. It explains the four kernel features that make a container a boundary. You need them to judge how strong that boundary is for a coding agent.
A container is a normal process with restrictions
A container is not a small virtual machine. It is an ordinary Linux process that runs on the host kernel, with four kinds of restrictions applied to it. Each kernel feature answers a different question:
| Feature | Question it answers | What it limits |
|---|---|---|
| Namespaces | What can the process see? | Processes, mounts, network, users, hostname |
| Cgroups | How much can it use? | CPU, memory, process count |
| Capabilities | Which privileged actions may it perform? | Pieces of root power |
| Seccomp | Which system calls may it make? | Kernel entry points |
Namespaces: a restricted view
A namespace gives a process its own view of a system resource. Inside a container, ps shows only the container's processes, because it has its own PID namespace. Other namespaces cover mounts (the filesystem tree), network interfaces, hostnames, and user IDs.
You can see this directly:
docker run --rm python:3.12-slim sh -c 'echo "PID: $$"; ls /proc | head -n 5'The shell reports a very low PID, often 1. On the host, the same process has a much larger PID. It is the same process seen through two views.
Namespaces hide things. They do not stop a process from making system calls that reach the kernel.
Cgroups: a resource budget
Control groups (cgroups) account for and cap what a group of processes consumes. Docker's --memory, --cpus, and --pids-limit flags set cgroup limits. If an agent starts a fork bomb or a runaway build, the cgroup stops it from taking the whole host. Chapter "Limiting CPU, memory, and process count" covers the settings in detail.
Capabilities: root split into pieces
Traditionally, root could do everything. Linux capabilities split that power into separate units, such as CAP_NET_ADMIN (change network configuration) and CAP_SYS_ADMIN (a very broad set of administrative actions). Docker gives containers a reduced default set. For an agent, drop all of them and add back only what is needed:
docker run --rm --cap-drop=ALL --security-opt no-new-privileges python:3.12-slim \
sh -c 'grep Cap /proc/self/status'CapEff should be all zeros. The no-new-privileges option also stops a process from gaining privileges through setuid binaries.
Seccomp: a system call filter
Seccomp (secure computing mode) filters system calls. Docker applies a default profile that blocks dozens of risky calls, such as loading kernel modules. A blocked call returns an error instead of reaching the kernel code behind it. This matters because most kernel vulnerabilities are reached through system calls.
Why the kernel is still shared
All four features are enforced by one kernel, and the container uses that same kernel. A kernel bug that a permitted system call can trigger can let code escape the container. The controls reduce this risk but do not remove it. That is why later chapters add stronger boundaries such as gVisor and microVMs.
Exercise
An agent in a container runs a fork bomb. Which feature limits the damage, and which feature would not help?
Show answer
Cgroups limit it, through the process count limit (--pids-limit) and memory limit. Namespaces would not help, because they only change what the process can see, not how much it can consume.