C++20 RuntimeAlpine 3.20 · Cgroups v2

Linux containers from bare syscalls

A container isn't magic or a mini VM. It's an ordinary Linux app locked in a private room with a hard RAM cap, built from scratch in C++20.

How a normal app becomes a container. Five simple steps in order.

Hold the new process before it runs

First, Trishanku verifies Alpine 3.20 is unpacked on disk and opens a one-way walkie-talkie pipe. The new child process waits here until all fences are locked.

Think of it like: You finish childproofing the room and locking the safety gate before letting someone step inside.
Step 1 of 5
packages/runtime/src/main.cpp:361-366pipe2(O_CLOEXEC)
REAL PC SEES (HOST)
Real PC OSArch Linux 7.2
Walkie-talkiepipe2[0..1] open
Alpine checketc/os-release OK
Sandbox stateNot started yet
SANDBOX SEES (CONTAINER)
PID inside-
Machine name-
Visible drive-
Starting gateWaits on pipe read
// Open a parent-to-child pause signal before starting
int sync_pipe[2];
pipe2(sync_pipe, O_CLOEXEC);
config.sync_pipe_read = sync_pipe[0];
// Confirm the unpacked Alpine folder is present
if (fs::exists(path / "etc" / "os-release", ec))
  return fs::canonical(path, ec).string();
Syscall boundary: pipe2(O_CLOEXEC)Enforced in C++20

Run it live or replay every step.

Connects to your local C++ engine on port 8080 when running, or lets you test every container lock right in the browser.

Browser sim
EXECUTION LOG (1)click row to inspect
sim-os-release(SIMULATOR)
1. pipe2
2. clone
3. cgroup
4. pivot
5. exec
memory.max: 0 MB / 64MEXIT 0
Sandbox PID: 1Host: trishanku-sandboxRootFS: Alpine 3.20 (/)Swap: 0 MB
SIMULATOR MODEReplaying in browser. Clone repo to run real C++ syscalls on Linux.main.cpp ↗
[trishanku-parent] Initializing Trishanku Runtime Engine...
[trishanku-parent] Host PID : 444401
[trishanku-parent] Memory Limit : 64 MB
[trishanku-parent] Using RootFS : packages/runtime/rootfs
[trishanku-parent] Child spawned with Host PID: 444402
[trishanku-parent] Attached Host PID 444402 to Cgroup: /sys/fs/cgroup/trishanku/box-sim
[trishanku-parent] Waiting for container process to finish...
========================================================
◆ [TRISHANKU CONTAINER SANDBOX INITIALIZED]
Inside Container PID : 1 (Expected: 1)
Hostname : trishanku-sandbox
Root Filesystem : Jailed (Alpine Linux)
Command : /bin/sh
========================================================
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.20.0
PRETTY_NAME="Alpine Linux v3.20"
HOME_URL="https://alpinelinux.org/"
[trishanku-parent] Container exited normally with status code: 0
Host OS is Arch Linux, yet reading /etc/os-release inside the sandbox prints Alpine Linux v3.20 because pivot_root swapped the mount tree.pids.max: 64

No Docker magic under the hood. Four simple Linux tricks build the entire sandbox.

Hides the rest of your computer

clone() drops the app inside private IDs and hostname views so it feels completely alone at PID 1.

Locks files inside Alpine Linux

pivot_root(2) swaps the / folder pointer to an 8.1 MB Alpine folder and detaches your host drive.

Stops memory greed instantly

Writing memory.max and swap=0 forces Linux to kill any process the instant it crosses its RAM budget.

Streams C++ logs live via Bun

A lightweight TypeScript server launches the compiled binary and pushes every terminal line over WebSockets.

Core runtime principleZero hypervisor · Native Linux syscalls

A container is not a mini VM — it is one ordinary app wearing Linux blinders for privacy and strict fences for memory.

PID 1

Private namespace bubble

clone() isolates PIDs, hostname, and mounts without booting a guest OS.

8.1 MB

Atomic Alpine filesystem jail

pivot_root(2) swaps the mount root and detaches the host drive cleanly.

0 MB

Zero-swap memory enforcement

memory.swap.max = 0 ensures page breaches trigger instant exit 137.

Host PC vs Inside Container. What actually changes when the walls close.

DimensionHost OS (Arch Linux)Inside Trishanku Sandbox
Process IDs (ps aux)Sees 200+ user and system daemons; container shell appears as PID 427575.Remounted /proc hides host processes; container runs cleanly as PID 1.
Filesystem root (/)Full host NVMe directories including /home, /etc, and host pacman packages.Swapped atomically via pivot_root(2) to unpacked Alpine 3.20 (8.1 MB rootfs).
Memory & swap capsShares system RAM and swap space across desktop applications.Bounded by memory.max + memory.swap.max=0; exceeding cap triggers exit 137.
Fork-bomb guardSystem-wide ulimit permits thousands of concurrent threads.Leaf cgroup sets pids.max=64, rejecting extra clone or fork calls from the kernel.
Disk size (df -h)Shows host NVMe partition capacity (/dev/nvme0n1p2, 467.8G).Still shows 467.8G because statvfs('/') reads the shared partition superblock while path escape stays blocked.

Questions anyone would ask

Plain-English answers to the four trickiest kernel bugs hit while building Trishanku.

Test scenarios in the workbench

Why swap the root with pivot_root instead of chroot?

chroot only changes folder names — a clever program can keep an old folder handle open and escape. pivot_root switches the real drive mount and unmounts your host disk completely.

Why pause the child process with a pipe?

Without a pause signal, the new child might race ahead and allocate memory before the parent finishes writing its cgroup caps. Waiting for 1 byte guarantees limits lock first.

Why turn disk swap off (memory.swap.max = 0)?

When physical RAM runs out, Linux quietly moves extra pages onto your SSD instead of stopping the app. Setting swap to zero triggers a clean OOM exit 137 right at the limit.

Why reset PATH inside the Alpine sandbox?

Arch Linux keeps tools in /usr/bin, while Alpine BusyBox links sit inside /bin. Resetting PATH prevents bare commands like ls or uname from failing with exit 127.