cd /news/ai-agents/non-root-compose-for-claude-bughunte… · home › topics › ai-agents › article
[ARTICLE · art-176705] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Non-Root Compose for Claude-BugHunter: Stopping Mount Escapes and Preserving Build Caches

A developer hardened the elementalsouls/Claude-BugHunter AI bug-hunting agent by splitting its Dockerfile into a BuildKit-cached dependency stage and a non-root runtime stage running as UID 10001, then locking down Compose with a read-only root filesystem, dropped capabilities, no-new-privileges, tmpfs scratch space, read-only skill mounts and a named reports volume. The changes address two failures: a prior root-running image where a bind mount over node_modules let a shell-out skill write to the host, and a COPY-before-npm-ci ordering that busted the dependency layer on every skill edit. The setup also uses tini as PID 1 to reap zombies from skills spawning git or ripgrep, and routes model calls through a single configured base URL.

recommendation

Run agent containers as a non-root UID with read_only, cap_drop ALL and no-new-privileges, mount worktrees read-only, and use a BuildKit npm cache mount so skill edits don't bust the dependency layer.

more in playbook: Securing agents and AI tools
by read5 min views5 publishedNov 26, 2026

Picture this: 3 a.m., your phone pings with an on-call alert. You realize the AI agent you just integrated for bug hunting has just attempted a privilege escalation on your development machine. That's the nightmare scenario that prompted this hardened setup. When evaluating elementalsouls/Claude-BugHunter—a repository packed with 85 skills, 16 slash commands, and patterns covering two dozen vulnerability classes—I had to ensure the UID it runs as and the host paths it can access stay under lock and key.

The failure that actually burned me wasn't a sophisticated kernel exploit. A previous runner image ran as root. Compose bind-mounted the worktree, and someone had mounted a host directory over node_modules "to speed installs." A skill that performed a shell-out wrote through that mount. The container boundary was mere theater. The quieter failure occurred at build time. COPY . . sat above npm ci, so any skill-file edit would bust the dependency layer and reinstall hundreds of megabytes. Root plus a bad mount equals a host-integrity bug. Cache invalidation is a productivity bug. Same Dockerfile, both fixable.

The split is small but critical. The build stage resolves locked dependencies with a BuildKit cache mount. The runtime stage copies production modules and the skill tree, then drops to a dedicated UID. Compose publishes nothing, mounts no Docker socket, and mounts no host home directory. When attaching a worktree, it is read-only and serves as a tree I intend to review. Reports land on a named volume. Model calls route through one configured base URL.

Build with BuildKit. The cache mount keeps the npm tarball cache out of the image layer hash. The lockfile stays in the layer key, so a real dependency change still triggers a rebuild.

FROM node:22-bookworm-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
    npm ci --omit=dev

FROM node:22-bookworm-slim AS runtime
RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates tini \
 && rm -rf /var/lib/apt/lists/* \
 && groupadd --gid 10001 hunter \
 && useradd --uid 10001 --gid hunter --create-home --shell /usr/sbin/nologin hunter
WORKDIR /app
COPY --from=deps --chown=hunter:hunter /app/node_modules ./node_modules
COPY --chown=hunter:hunter package.json package-lock.json ./
COPY --chown=hunter:hunter skills ./skills
COPY --chown=hunter:hunter src ./src
ENV NODE_ENV=production \
    HOME=/home/hunter \
    npm_config_update_notifier=false
USER hunter
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["node", "src/runner.js"]

tini runs as PID 1 because mem_limit eventually sends a SIGKILL to the cgroup. A skill that spawns git or rg can leak zombies if nothing reaps them. The nologin shell is deliberate. Any skill insisting on an interactive shell gets rewritten, not a root bash.

services:
  bughunter:
    build:
      context: .
      dockerfile: Dockerfile
    image: local/claude-bughunter:dev
    read_only: true
    user: "10001:10001"
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=64m
      - /home/hunter:rw,nosuid,size=32m
    volumes:
      - ./skills:/app/skills:ro
      - reports:/home/hunter/reports
    environment:
      OPENAI_BASE_URL: https://b-lost.com/v1
      OPENAI_API_KEY: ${OPENAI_API_KEY}
      SKILL_ROOT: /app/skills
    networks:
      - hunter_net
    mem_limit: 1536m
    memswap_limit: 1536m
    cpus: "1.5"
    pids_limit: 256
    restart: "no"
    healthcheck:
      test: ["CMD", "node", "-e", "require('fs').accessSync('/home/hunter/reports/.healthy')"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 20s

networks:
  hunter_net:
    driver: bridge

volumes:
  reports:

hunter_net is a dedicated bridge network, not host networking, and it publishes nothing. I am not setting internal: true. That flag would drop all egress, which also drops the model API, and the healthcheck would go red for what looks like an application bug. For an offline pass over a local pattern corpus, internal: true is the right tightening, and the base URL should be unset. Any run that actually invokes skills against a model needs egress. The constraints I keep are no published ports, no extra_hosts into lab subnets, and no socket mount.

When comparing multi-provider fallback, the client is pinned to baseURL: "https://b-lost.com/v1". One relay, one error shape, one place to read latency. Skills in a pack this size will hardcode a vendor host if you let them. They do not get to override that setting.

Cache mounts are not free correctness. A warm cache makes the second local build feel finished, which hides a lockfile that no longer matches the import graph until a cold CI builder. Use npm ci, and copy the lockfile before the rest of the tree. I also refuse a host node_modules bind. That shortcut is how a postinstall script becomes a write on the workstation: the same escape as the root mount, only earlier.

Read-only root and cap_drop: ALL will break skills that apt-get, bind privileged ports, or open raw sockets. Those stay disabled. Memory and pid limits will also kill an oversized walk of the pattern library. I split the run rather than lift the cap. The image stays non-root when a specific repository is attached for a review I already intend to do. Add that bind per invocation, read-only, same uid. Do not bake workspace paths into the compose file, and do not leave a long-lived container sitting on a credential directory because the last session needed a token. The pack can hold a lot of procedure. The runtime should hold as little privilege as a Node process that writes a report and makes HTTPS calls.

As Principal Systems Architect, the single hardest operational dilemma I've faced is balancing the functional requirement for outbound connectivity to invoke model APIs with the uncompromising isolation of a non-root, capability-dropped sandbox. This setup shows that thoughtful layering of Docker features can secure complex AI agent workflows without sacrificing essential capabilities.

What’s the toughest security trade-off you’re navigating when containerizing your own AI-driven tools? Share your architecture scars and lessons learned in the comments.

── more in #ai-agents 4 stories · sorted by recency
── more on @elementalsouls/claude-bughunter 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/non-root-compose-for…] indexed:0 read:5min 2026-11-26 · —