MiniBox runs containers as isolated Linux processes using PID, UTS, mount, and network namespaces combined with cgroups v2 resource controls. This page covers every stage of the container lifecycle — from launching your first container withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/chaitu426/minibox/llms.txt
Use this file to discover all available pages before exploring further.
minibox run all the way through inspecting it with stats and cleaning up with rm.
Prerequisites
The daemon must be running before you issue any container commands:minibox run flags
Detached mode. The container starts in the background and its 8-hex-character ID is printed to stdout.
Memory limit in megabytes. Written to
memory.max in the container’s cgroup v2 slice under /sys/fs/cgroup/minibox/<id>/.CPU limit as a percentage of one core (1–100). MiniBox converts this to the cgroup v2
cpu.max format: <quota> 100000, where quota = value × 100000 / 100.Port mapping in
host:container format (e.g. -p 8080:80). Repeat the flag for multiple mappings. MiniBox programs an iptables DNAT rule and a kernel-bypass TCP proxy listener for each pair.command, MiniBox uses the image’s default CMD from its OCI metadata.
Container lifecycle
Namespace isolation
Every container is launched with four Linux namespace clone flags set simultaneously:| Namespace | Clone flag | What it isolates |
|---|---|---|
| PID | CLONE_NEWPID | Process tree — container processes can only see each other |
| UTS | CLONE_NEWUTS | Hostname (set to the container ID by default) |
| Mount | CLONE_NEWNS | Filesystem tree — overlayfs rootfs is private to the container |
| Network | CLONE_NEWNET | Network interfaces, routing table, iptables rules |
The parent daemon also sets
CLONE_NEWIPC to isolate System V IPC resources (shared memory segments, semaphores) from the host.chroots into the container rootfs, then mounts /proc (with hidepid=2 to prevent cross-process info leaks), a read-only /sys, and a minimal /dev tmpfs.
Cgroups v2 resource controls
MiniBox creates a cgroup slice at/sys/fs/cgroup/minibox/<containerID>/ and writes resource knobs before the workload starts. The parent slice’s cgroup.subtree_control is set to +cpu +memory +io so all three controllers are actually enforced.
| cgroup file | CLI flag | Notes |
|---|---|---|
memory.max | -m <MB> | Hard memory ceiling in bytes (MB × 1 048 576) |
cpu.max | -c <percent> | <quota> 100000 — e.g. -c 50 writes 50000 100000 |
cpuset.cpus | ContainerOptions.CPUSet | Pinned CPU set (API only, no CLI flag yet) |
io.weight | ContainerOptions.IOWeight | 1–1000; db run sets this to 800 |
/proc/self/oom_score_adj | ContainerOptions.OOMScoreAdj | Adjusts OOM-killer priority; db run sets -900 |
Security hardening
MiniBox applies several layers of defence-in-depth inside the child process before executing the workload:Capability Drop
All Linux capabilities are cleared from the ambient set (
PR_CAP_AMBIENT_CLEAR_ALL) and dropped from the bounding set (PR_CAPBSET_DROP) via prctl after chroot. Containers cannot re-acquire dropped capabilities thanks to PR_SET_NO_NEW_PRIVS.Seccomp Deny-List
A seccomp BPF filter blocks a curated deny-list of dangerous syscalls (implemented in
seccomp_linux.go). The filter is installed after PR_SET_NO_NEW_PRIVS.rlimits
Resource limits (
RLIMIT_*) are applied via setrlimit to bound file descriptor counts, process counts, and core dump sizes.hidepid=2 on /proc
/proc is mounted with hidepid=2, so container processes cannot read /proc/<pid>/ entries of other PIDs — a common info-leak vector.Tiny PID 1 init / reaper
After all security controls are applied, the container does not exec the workload directly. Instead it execs a tiny init shim —/proc/self/exe init -- <cmd...> — that becomes PID 1 inside the container’s PID namespace.
The init shim (RunInit() in internal/runtime/init.go) does three things:
- Starts the target command as a child process.
- Forwards signals received by PID 1 to the child’s process group, so
SIGTERMfromminibox stoppropagates correctly. - Reaps zombies with
wait4(-1, ...)so forked grandchildren that exit never accumulate as zombie entries.
wait on them.
Container ID format
Container IDs are exactly 8 hexadecimal characters (e.g.a1b2c3d4). The ID is printed when you run in detached mode or when you list containers with ps. Use it with every subsequent command:
Running interactive shells with exec
minibox exec enters a running container’s namespaces (using nsenter from util-linux) and runs an arbitrary command:
-it flag allocates a PTY, attaches stdin/stdout/stderr to your terminal, and sets up a session leader so the shell behaves correctly. nsenter enters all six namespaces (-m -u -n -i -p plus the mount namespace).
exec runs nsenter from the host side via the daemon. It requires nsenter (part of util-linux) to be installed on the host system.Live resource metrics with stats
minibox stats reads cgroup v2 metrics and host veth counters for a single container and refreshes them every second:
Container states
| State | Meaning |
|---|---|
created | Container record registered but process not yet confirmed running |
running | Child process is alive (verified by kill -0 <pid>) |
exited | Process has exited; EXIT column shows the numeric exit code |
DataRoot/state.json and survives daemon restarts. On each ps call, MiniBox performs a live kill -0 check and transitions any running container whose PID is gone to exited.
Examples
- Foreground
- Detached + ports
- Resource limits
- Custom command