The Complete Production SOP: How to Deploy and Run runc Low-Level OCI Container Runtime & Spec Config in Autonomous AI Agents
Step-by-step SOP to install and run runc OCI Container Runtime in Codex, Claude Code, and Cursor. Includes verified specs, sandbox rules, and troubleshooting.
Technical Overview & Architectural Context
Autonomous coding agents frequently hallucinate when configuring low-level Linux container infrastructure. When asked to construct container environments from scratch, models commonly conflate high-level Docker engine semantics with the low-level Open Container Initiative (OCI) runtime specification. This leads to invalid config.json schemas, missing mandatory mount points (such as /proc, /dev, and /sys), or invalid Linux namespace bitmask declarations. Furthermore, agents often attempt privileged namespace operations without configuring user namespace UID/GID mappings, causing immediate permission failures inside sandbox environments. By injecting the runc-oci-container-runtime skill, coding agents like Codex, Claude Code, Cursor, and Windsurf are constrained by deterministic procedural standard operating procedures. The skill enforces rigid bundle directory layouts (containing rootfs and config.json), correct generation of baseline OCI specifications via 'runc spec', precise namespace tuning (pid, net, ipc, mnt, uts, user), and explicit cgroups v2 resource quotas. This eliminates non-deterministic trial-and-error shell executions and keeps container lifecycle operations strictly within reproducible, auditable boundaries.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local agent skill manifest directory and inject verified procedural rules into the agent context.
Autonomous runtimes discover capabilities through standardized directory structures. Claude Code searches in project-local or global config directories, while Cursor and Windsurf ingest contextual rules via workspace settings or prompt definitions. Creating the dedicated runc-oci-container-runtime skill directory mounts the frontmatter triggers and SOP directly into the LLM runtime context.
mkdir -p ~/.agents/skills/runc-oci-container-runtime && cat << 'EOF' > ~/.agents/skills/runc-oci-container-runtime/SKILL.md
---
name: "runc-oci-container-runtime"
description: "Create, run, and manage standard OCI container lifecycles directly via runc CLI."
metadata:
author: "Open Containers Initiative"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "run container with runc"
- "generate runc config spec"
- "configure runc namespaces"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: false
---
# runc Low-Level OCI Container Runtime & Spec Config
Operates runc: generating OCI config.json specs, unpacking rootfs filesystems, configuring Linux namespaces (pid, net, ipc, mnt, uts, user), cgroups limitations, and seccomp syscall filters.
## When to Invoke
Invoke this skill whenever you need to:
- run container with runc
- generate runc config spec
- configure runc namespaces
## Execution SOP & Rules
1. Create container bundle directory: mkdir -p bundle/rootfs && cd bundle.
2. Generate default OCI configuration: runc spec (or runc spec --rootless for unprivileged setups).
3. Modify config.json to customize process arguments, environment variables, mounts, and namespace flags.
4. Launch container instance: runc run <container-id> or runc create/start lifecycle.
## Verification Checklist
- Run local linting, syntax validation (jq . config.json), and spec checks before reporting completion.
- Ensure rootfs directory exists and contains a valid init/shell binary.
- Verify container exits or operates without unhandled system call trap errors.
EOF---
name: "runc-oci-container-runtime"
description: "Create, run, and manage standard OCI container lifecycles directly via runc CLI."
metadata:
author: "Open Containers Initiative"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "run container with runc"
- "generate runc config spec"
- "configure runc namespaces"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: false
---Keep the SKILL.md under 250 tokens by omitting deep historical changelogs. Runtimes inject this metadata into active reasoning windows; compact markdown preserves context for multi-file code generation.
Ensure that the agent sandbox grants shell_exec permissions when executing low-level runtime commands. If the agent operates under read-only file systems, bundle creation will abort.
Bundle Scaffolding & Rootless Spec Generation
Generate an OCI-compliant bundle directory structure and populate a baseline config.json.
An OCI bundle requires an exact file layout: a directory containing a config.json configuration file and a rootfs directory with the guest filesystem. Instructing the agent to run 'runc spec --rootless' ensures that unprivileged user namespace configurations (uid/gid mappings) are pre-populated, preventing permissions failures on developer workstations.
mkdir -p container-bundle/rootfs && cd container-bundle && runc spec --rootless{
"ociVersion": "1.0.2",
"process": {
"terminal": true,
"user": {
"uid": 0,
"gid": 0
},
"args": [
"sh"
],
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"cwd": "/"
},
"root": {
"path": "rootfs",
"readonly": true
},
"hostname": "runc-agent-box"
}Always specify 'readonly: true' for rootfs in production spec templates, mounting writeable paths explicitly to tmpfs to preserve immutability.
Never run plain 'runc spec' inside an unprivileged agent session without root rights; rootless runc requires the '--rootless' flag to omit privileged cgroup controllers.
Populating Rootfs & Intent Matching
Extract guest filesystem layers into rootfs and verify agent trigger activation.
A valid OCI container cannot execute without an unpacked filesystem inside the rootfs folder. The agent extracts an image tarball directly into the target rootfs directory. When the user invokes prompts like 'generate runc config spec' or 'run container with runc', the runtime recognizes the trigger and aligns with the defined execution SOP.
tar -xf /tmp/alpine-minirootfs.tar.gz -C container-bundle/rootfs/#!/usr/bin/env bash
set -euo pipefail
BUNDLE_DIR="container-bundle"
if [ ! -d "$BUNDLE_DIR/rootfs/bin" ]; then
echo "Extracting minimal rootfs..."
tar -xzf /tmp/alpine-minirootfs.tar.gz -C "$BUNDLE_DIR/rootfs/"
fi
# Validate binary presence
test -f "$BUNDLE_DIR/rootfs/bin/sh" && echo "Rootfs ready."Use static binaries or minimal distributions (like Alpine minirootfs or Distroless) to reduce unpack time and avoid dynamic library resolution errors.
Extracting tar archives containing hard links or mknod device nodes will fail in unprivileged sandboxes. Strip dev nodes or use '--exclude=dev/*' during untar.
Verification, Linting & Output Quality Gate
Execute automated syntax checks on config.json and validate bundle execution non-interactively.
Before reporting completion, the agent validates config.json using jq or the runc CLI directly. It executes a deterministic non-interactive test run (`runc run <container-id>`) that prints container metadata and exits cleanly, confirming the namespaces and mounts are correctly initialized.
jq empty container-bundle/config.json && runc --root /tmp/runc-state run -b container-bundle test-run-01#!/usr/bin/env bash
set -euo pipefail
cd container-bundle
# Validate JSON structure
jq empty config.json
# Ensure root directory points to rootfs
ROOT_PATH=$(jq -r '.root.path' config.json)
if [ "$ROOT_PATH" != "rootfs" ] && [ ! -d "$ROOT_PATH" ]; then
echo "Error: invalid rootfs path in config.json" >&2
exit 1
fi
echo "OCI bundle syntax verified successfully."Use a custom ephemeral state root `--root /tmp/runc-state` to ensure that standard user sessions do not collide with system-wide runc run states in `/run/runc`.
Interactive containers configured with `"terminal": true` will hang automated agent pipelines waiting for TTY stdin. Set `"terminal": false` for automated CI/CD and agent verification checks.
Real-World Scenario: Automated Setup of an Isolated Rootless OCI Container Bundle for Sandboxed Code Execution
“Set up a lightweight rootless OCI container bundle in ./sandbox-bundle using Alpine minirootfs. Configure the runc spec to run non-interactively with a 128MB memory limit, bind mount a local workspace directory at /workspace (read-only), and execute 'cat /etc/os-release'. Validate the configuration by running the container via runc.”
Runtime Troubleshooting & Failure Modes
Root Cause: The container spec attempted to write or initialize namespaced sysctl entries that are restricted or not permitted in an unprivileged or rootless user namespace.
jq '.linux.sysctl = {}' container-bundle/config.json > container-bundle/config.json.tmp && mv container-bundle/config.json.tmp container-bundle/config.jsonRoot Cause: The unpacked rootfs is missing standard basic pseudo-devices or the config.json lacks default /dev mount bindings required for standard file descriptor routing.
jq '.mounts += [{"destination": "/dev", "type": "tmpfs", "source": "tmpfs", "options": ["nosuid", "strictatime", "mode=755", "size=65536k"]}]' config.json > config.json.tmp && mv config.json.tmp config.jsonFrequently Asked Questions (runc Low-Level OCI Container Runtime & Spec Config SOP)
Q:Can I use runc Low-Level OCI Container Runtime & Spec Config across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. Whether installed in ~/.agents/skills or configured in agent rule definitions, runtimes parse the YAML triggers and SOP instructions identically across Codex, Claude Code, Cursor, and Windsurf.
Q:How does runc Low-Level OCI Container Runtime & Spec Config prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. Agents avoid multi-turn trial-and-error debugging cycles by following rigid bundle creation steps and using automated jq validations.
Q:Does this skill require escalated root or container permissions?
No. The skill emphasizes rootless execution utilizing 'runc spec --rootless' and user namespaces (UID/GID mapping), allowing safe operation in developer workspaces with a 98/100 security rating without requiring root access.
Ready to equip your autonomous agent with runc Low-Level OCI Container Runtime & Spec Config?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.