The Complete Production SOP: How to Deploy and Run Docker Rootless Daemon Installation & Security Hardening in Autonomous AI Agents
Step-by-step SOP to install and harden rootless Docker daemon in Codex, Claude Code, and Cursor. Set up user namespaces, subuid/subgid, and systemd units.
Technical Overview & Architectural Context
Autonomous coding agents frequently default to insecure container configurations when tasked with spinning up Docker environments. Without explicit boundaries, agents often invoke 'sudo apt-get install docker.io', add the unprivileged host user to the root-equivalent 'docker' group, or bind dockerd directly to privileged TCP sockets. These anti-patterns bypass isolation, expose the host kernel to container breakout vulnerabilities (such as CVE-2019-5736 and CVE-2024-21626), and introduce serious privilege escalation risks into local development and CI/CD pipelines. The 'docker-rootless-daemon-hardening' skill forces agents into a strict, deterministic workflow. It mandates checking kernel namespace flags (unprivileged user namespaces), provisioning subordinate UID/GID mappings (/etc/subuid, /etc/subgid), deploying RootlessKit with slirp4netns networking, and establishing systemd user services. By constraining the agent's procedural sequence, the skill guarantees that daemon processes, runc containers, and socket communications run under unprivileged user namespaces where root inside the container maps to an unprivileged UID outside.
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 skill manifest directory and inject verified procedural rules into agent runtime contexts.
Agent runtimes such as Codex, Claude Code, Cursor, and Windsurf parse skill directories to identify actionable triggers and tool constraints. Place the SKILL.md file inside the shared user-level agents directory or the workspace-level root. When the agent detects system administration or container orchestration queries, the YAML frontmatter activates the user-namespace constraints.
mkdir -p ~/.agents/skills/docker-rootless-daemon-hardening && curl -fsSL https://askills.dev/api/skills/docker-rootless-daemon-hardening/raw -o ~/.agents/skills/docker-rootless-daemon-hardening/SKILL.md---
name: "docker-rootless-daemon-hardening"
description: "Run the Docker daemon and containers completely without root privileges to mitigate breakouts."
metadata:
author: "Moby Project"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "install docker rootless"
- "setup rootless subuid subgid"
- "harden docker daemon security"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: true
net_access: true
---Place the SKILL.md in ~/.claude/skills or .cursor/rules to ensure the runtime indexes the trigger tokens without bloating system prompts on every conversational turn.
Do not execute dockerd-rootless-setuptool.sh as root or through sudo. The script must be invoked strictly under the unprivileged runtime user account.
Subordinate UID/GID Verification & Kernel Hardening
Verify user namespace allocation and ensure required kernel parameters are configured.
Rootless containers rely on subordinate user namespaces to map container root (UID 0) to an unprivileged UID range on the host. The agent must verify that the current user exists in /etc/subuid and /etc/subgid with an allocation of at least 65,536 IDs. Additionally, systemd user lingering must be active so the daemon survives session disconnects.
grep -E "^$(whoami):" /etc/subuid || sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 $(whoami) && loginctl enable-linger $(whoami)#!/usr/bin/env bash
set -euo pipefail
USER_NAME=$(whoami)
echo "Checking namespace availability for: ${USER_NAME}"
# Validate sysctl configuration
SYSCTL_VAL=$(sysctl -n kernel.unprivileged_userns_clone 2>/dev/null || echo "1")
if [[ "${SYSCTL_VAL}" -eq 0 ]]; then
echo "ERROR: kernel.unprivileged_userns_clone is 0. Enable via sysctl." >&2
exit 1
fi
# Validate subuid/subgid mapping
if ! grep -q "^${USER_NAME}:" /etc/subuid; then
echo "ERROR: SubUID mapping missing for ${USER_NAME}" >&2
exit 1
fi
echo "Namespace prerequisites satisfied."Ensure XDG_RUNTIME_DIR is properly exported in headless environments like CI runners, otherwise systemctl --user commands fail.
Modifying /etc/subuid requires elevated privilege once during host provisioning; the AI agent must request admin intervention rather than guessing passwords.
Rootless Tooling Execution & Systemd Daemon Service Setup
Execute the rootless installer and configure environment sockets for non-root clients.
The agent runs dockerd-rootless-setuptool.sh, which initializes the RootlessKit supervisor, configures network drivers (slirp4netns or pasta), and registers a user-level systemd unit (docker.service). The agent must then bind the client to the user's isolated Unix socket at /run/user/$UID/docker.sock instead of /var/run/docker.sock.
dockerd-rootless-setuptool.sh install && systemctl --user enable --now docker# Export User Docker Runtime Configuration
export PATH=/usr/bin:$PATH
export DOCKER_HOST="unix://${XDG_RUNTIME_DIR}/docker.sock"
# Audit check to ensure client uses user-space socket
alias docker-info="docker info -f '{{json .SecurityOptions}}'"Use RootlessKit's built-in port driver 'builtin' for maximum performance or 'slirp4netns' when source IP preservation is not required.
Privileged ports below 1024 cannot be bound by default in rootless mode. Set 'sysctl net.ipv4.ip_unprivileged_port_start=80' if lower ports are required.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks to verify user namespace isolation and socket confinement.
Instruct the agent to validate that containers cannot escape their namespace by running an unprivileged alpine container and querying process ownership from host and container perspectives.
docker run --rm alpine id && docker info --format '{{.SecurityOptions}}'#!/usr/bin/env bash
set -euo pipefail
# Ensure root inside container maps to non-root outside
CONTAINER_UID=$(docker run --rm alpine id -u)
if [[ "${CONTAINER_UID}" -ne 0 ]]; then
echo "Container root isolation check failed." >&2
exit 1
fi
# Verify rootless security option is reported by dockerd
SEC_OPTS=$(docker info --format '{{json .SecurityOptions}}')
if [[ "${SEC_OPTS}" != *"rootless"* ]]; then
echo "CRITICAL: Docker daemon reports standard rootful execution!" >&2
exit 1
fi
echo "SUCCESS: Docker rootless isolation verified."Run 'ps aux | grep dockerd' on the host to verify dockerd is running with the developer's host UID, confirming zero root privilege.
Overlay2 storage driver can fail if fuse-overlayfs is missing on kernels older than 5.11. Validate driver status in 'docker info'.
Real-World Scenario: Securely Provisioning Rootless Docker for an Untrusted CI Task
“Set up a hardened rootless Docker environment on this Ubuntu devbox. Ensure the daemon runs under my current unprivileged account, binds to my user socket, passes namespace validation, and runs an alpine smoke test.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent executed systemctl without a valid DBus session or missing XDG_RUNTIME_DIR variable in an SSH/non-interactive shell.
export XDG_RUNTIME_DIR=/run/user/$(id -u) && export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"Root Cause: The container attempted to publish a port lower than 1024 without host kernel sysctl permission for unprivileged port ranges.
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80 || echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/50-rootless-ports.conf && sudo sysctl --systemFrequently Asked Questions (Docker Rootless Daemon Installation & Security Hardening SOP)
Q:Can I use Docker Rootless Daemon Installation & Security Hardening across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. Once installed in ~/.agents/skills/ or workspace root, all tools adhere to identical rootless parameters.
Q:How does Docker Rootless Daemon Installation & Security Hardening 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. Step-by-step diagnostic scripts encapsulate the verification logic.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes. Host-level changes to /etc/subuid and sysctl only require standard one-time admin approval.
Ready to equip your autonomous agent with Docker Rootless Daemon Installation & Security Hardening?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.