MiniBox is a lightweight Linux container engine consisting of two binaries:Documentation 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 (CLI) and miniboxd (daemon). The CLI is a pure HTTP client; all container logic lives in the daemon. This page describes the full system — from parsing a MiniBox file to a running container process with networking, cgroups, and health checks.
Two-Binary Architecture
| Binary | Entry point | Responsibility |
|---|---|---|
miniboxd | cmd/daemon/main.go | HTTP API, builder, runtime, networking, state |
minibox | cmd/cli/main.go | CLI commands → HTTP requests → formatted output |
miniboxd over HTTP (http://127.0.0.1:8080 by default).
End-to-End Flowchart
Build Pipeline
1. Parse phase
internal/parser/parser.go reads a MiniBox file and produces a Cfile model containing:
BaseImage— the base rootfs to pullBlocks— a list of named DAG build unitsCmd,Env,Workdir— image-level defaultsHealthcheckCmd,HealthcheckIntervalSec— for health monitoringInstructions— legacy linear mode fallback
| Directive | Meaning |
|---|---|
BASE <image> | Base rootfs (Alpine supported) |
BLOCK <name> | Named build unit |
NEED <block> | Dependency edge |
RUN ... | Shell command in block context |
COPY <src> <dst> | Copy from context or another block (COPY FROM=) |
WORKDIR <path> | Set working directory |
ENV KEY=VAL | Environment variable |
PKG <name> | Expands to apk add --no-cache <name> |
AUTO-DEPS | Detects manifests and runs installers (npm, pip, go) |
START ... | Image default command |
HEALTHCHECK [--interval=N] <cmd> | Health check definition |
2. Base image prep
internal/builder/fetch_oci.go pulls the base image from Docker Hub (or any Docker V2 registry):
- Fetches the manifest from
auth.docker.io - Resolves multi-arch manifest lists to
linux/amd64 - Downloads layer blobs
- Caches extracted rootfs in
DataRoot/base_layers/<image_tag>
3. DAG execution (wave-based parallelism)
builder.BuildImage() calls buildFromBlocks():
Compute wavefronts
Identify all blocks whose
NEED dependencies are already complete. These form a wave and run concurrently.Execute each block
For each block:
- Create a temp overlay root (
tmp/<hash>/{upper,work,root}) - For
RUNinstructions: mount overlay and executechroot /bin/sh -c ... - For
COPYinstructions: copy from the host context or from another block’s layer - For
WORKDIR: create path and update effective working directory
Cache check
The cache key is derived from: parent hash + dependency names + workdir + instruction stream + COPY source content hash. If
DataRoot/layers/<hash> exists, the block is CACHED.BNEED) are executed but excluded from the final image layer stack unless files are explicitly copied from them.
4. OCI finalization
After all blocks complete:- Tar + gzip each layer →
blobs/sha256/<digest> - Generate
OCIConfigblob (cmd, env, workdir, healthcheck labels, layer diff IDs) - Generate
OCIManifestblob (config + layer descriptors) - Upsert image reference into
index.jsonwith annotationorg.opencontainers.image.ref.name = <imageName>
Build log format
Runtime Execution Path
Parent launcher (internal/runtime/process.go)
RunCommand() / RunCommandStream():
- Resolve image config and layer stack from OCI index
- Prepare
DataRoot/containers/<id>/and mount overlay rootfs (MountRootfs) - Spawn child as
/proc/self/exe child ...with clone flags:CLONE_NEWPID | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWNET | CLONE_NEWIPC - Call
SetupContainerNetwork(pid, id, ip, portMap) - Register container in
state.jsonviaRegisterContainer() - Start health monitor goroutine (if image has healthcheck labels)
- Wait for child; record exit code; teardown network
Child runtime (internal/runtime/container.go)
RunContainer():
- Validate args and container ID
- Ensure mount namespace isolation (env guard + optional unshare fallback)
- Apply cgroup writes:
memory.max,cpu.max,cgroup.procs,io.weight - Set hostname
chrootinto container rootfs- Mount
/proc, minimal/dev - Apply security: capability drop, rlimits,
PR_SET_NO_NEW_PRIVS, seccomp deny-list - Exec tiny init:
/proc/self/exe init -- <cmd...>
Tiny init / PID 1 (internal/runtime/init.go)
RunInit():
- Starts the target command
- Forwards signals to the process group
- Reaps zombie processes with
wait4(-1, ...) - Exits with child status/signal semantics
Networking Architecture
Implemented ininternal/network/network.go.
Host bridge setup (SetupBridge)
- Creates
minibox0bridge and assigns172.19.0.1/24 - Enables IP forwarding sysctls
- Adds iptables NAT masquerade rules
When
MINIBOX_BRIDGE_ON_STARTUP=0, bridge creation is deferred to the first container run, making daemon startup near-instant.Per-container networking (SetupContainerNetwork)
For each container:
- Create veth pair:
veth-<id>(host) andvetp-<id>(peer) - Attach host veth to
minibox0bridge - Move peer veth into the container’s network namespace (via PID)
- Inside the container netns: bring up loopback, rename peer to
eth0, assign IP, add default route via172.19.0.1 - Program iptables DNAT and FORWARD rules for each
-p host:containermapping
Teardown
TeardownContainerNetwork()removes veth pairs and per-container iptables rulesTeardownBridge()removesminibox0and the base NAT setup (called on daemon shutdown)
Security Controls
API layer
- Method-scoped routes enforce correct HTTP verbs
- Body size limits: 4 MB (run/exec), 64 MB (build)
- Optional bearer token authentication middleware
- Input validation via
internal/security/security.go(image names, container IDs, path traversal)
Runtime layer
| Control | Implementation |
|---|---|
| Namespace isolation | PID, UTS, mount, network, IPC via clone flags |
| Seccomp | Deny-list filter in internal/runtime/seccomp_linux.go |
| Capability drop | internal/runtime/drop_linux.go (skipped in db_mode) |
| No new privileges | PR_SET_NO_NEW_PRIVS set before seccomp |
| Path traversal | Container ID and path validation before any file operations |
Build context restrictions
Build contexts are validated againstMINIBOX_BUILD_PREFIXES using security.ResolveAllowedPath(). Requests with contexts outside the allowed prefixes are rejected at the handler level.
Health Checks
HEALTHCHECK [--interval=N] <cmd>is parsed from the MiniBox file- Stored as OCI config labels:
mini.healthcheck.cmd,mini.healthcheck.interval - On container start, a monitor goroutine runs
nsenter ... /bin/sh -c <cmd>periodically - Container
Healthfield transitions:starting→healthyorunhealthy minibox psshows the currentHEALTHcolumn value
Health check support is basic. Retries, start-period thresholds, and full OCI
HealthConfig semantics are not yet implemented.Compose Orchestration
cmd/cli/main.go implements the compose orchestrator on top of the daemon API:
Service DAG
minibox-compose.yamlis parsed withgopkg.in/yaml.v3- A dependency graph is built from
depends_ondeclarations - Topological sort determines startup order: services with no dependencies start first
Automated builds
- Services with a
buildcontext triggerPOST /containers/buildbefore starting - The resulting image is tagged
<project>-<service>
Service discovery
When a container starts as part of a project:- The daemon fetches all running containers in the same project
- Builds a hosts-file mapping service names and container IDs → IP addresses
- Writes the mapping to
rootfs/etc/hostsbefore PID 1 executes
web to connect to db:5432 without any DNS configuration.
File Map
| Path | Responsibility |
|---|---|
cmd/daemon/main.go | Daemon entry point |
cmd/cli/main.go | CLI + compose orchestrator |
internal/api/router.go | HTTP route registration, body limits, middleware chain |
internal/api/auth.go | Bearer token middleware |
internal/api/handler/*.go | Per-endpoint request handlers |
internal/builder/builder.go | DAG build orchestration |
internal/builder/fetch_oci.go | OCI image pulling from registries |
internal/parser/parser.go | MiniBox file parser |
internal/runtime/process.go | Parent container launcher |
internal/runtime/container.go | Child namespace + chroot setup |
internal/runtime/init.go | PID 1 tiny init / zombie reaper |
internal/runtime/state.go | Container state persistence |
internal/runtime/seccomp_linux.go | Seccomp deny-list filter |
internal/runtime/drop_linux.go | Capability dropping |
internal/network/network.go | Bridge, veth, iptables |
internal/storage/image_archive.go | save / load tar operations |
internal/storage/prune.go | Blob garbage collection |
internal/models/oci.go | OCI data model types |
internal/security/security.go | Input validation helpers |
internal/config/config.go | Daemon configuration from env vars |