Engineering Notes · Containers · 2026-11-14

Five Container Isolation Pitfalls in Offline Security Test Harnesses.

We run adversarial verification workloads in offline, single-purpose containers. Every pitfall below cost us a red CI run or an escaped file handle before it became a checklist item. None are theoretical; all have reproductions.

Posted 2026-11-14 · 13 min read · Companion harness: Silvauren/patch-verify-sandbox (staging)

TL;DR Isolation in offline harnesses fails at the seams, not the center: archives that resolve symlinks after you validated them, build contexts that ship .git, secrets baked into layers instead of injected per run, workers that still hold Linux capabilities, and base images whose package repos silently die. Each has a one-line-or-less fix; together they are the difference between a sandbox and a suggestion.

1. Symlink and parent-path escapes during extraction and mounting

Symptom. A submitted archive contained a symlink assets -> /etc followed by a regular file assets/cron.d/pwn. The validation pass walked the archive entries (all paths looked in-bounds), the extraction pass followed the symlink, and the "contained" workload wrote outside the workdir.

Failure shape. Any pipeline that validates path strings, then hands extraction to a library that resolves symlinks or accepts .. segments, has a time-of-check-to-time-of-use gap measured in milliseconds.

Fix. Validate on normalized, resolved paths at the moment of write; extract with symlink dereferencing disabled; mount scratch as tmpfs so even a successful escape lands in memory that dies with the container:

import os, tarfile

def safe_extract(member, dest_root, workdir):
    # normalize + lexical cleanup BEFORE any filesystem touch
    target = os.path.realpath(os.path.join(dest_root, member.name))
    if os.path.commonpath([target, workdir]) != os.path.realpath(workdir):
        raise EscapeError(member.name)
    if member.issym() or member.islnk():
        # materialize symlinks only inside the workdir, never across it
        link = os.path.realpath(os.path.join(os.path.dirname(target), member.linkname))
        if os.path.commonpath([link, workdir]) != os.path.realpath(workdir):
            raise EscapeError(member.linkname)
    return target

Runtime side: docker run --read-only --tmpfs /work:rw,size=64m,exec. A read-only root filesystem converts most escape attempts into loud EROFS failures.

2. .git history and build-cache context leaks

Symptom. A harness image built from a repo directory shipped the full .git database, including objects from a branch where a live credential had briefly been committed and rotated. Anyone with image pull access (or docker history on a shared runner) had the history.

Failure shape. Build context is the whole directory unless excluded; multi-stage builds help only if the sensitive tree is never COPYed, and BuildKit --mount=type=cache directories persist across builds of unrelated PRs on the same runner.

Fix. Three lines, in order of leverage:

# .dockerignore, the cheapest security control you will write today
.git
.env
**/__pycache__
node_modules

3. Static .env secrets versus dynamic flag injection

Symptom. A scoring harness embedded its verification secret in the image as a static ENV FLAG=.... Two failure modes followed: the secret was recoverable from the image manifest by any process inside the sandbox (breaking the integrity of what was being measured), and because it was static, a leaked value stayed valid across every subsequent run.

Fix. Treat harness secrets as per-run capabilities, not configuration:

Static .env in imageDynamic per-run injection
LifetimeForever, until image rebuiltOne container start
Recoverable from layersYes (docker inspect, manifest)No, never enters a layer
Cross-run replayValid in all runsUseless after the run exits
Audit signalNonePer-run id in logs ties usage to one execution
FLAG="FLAG{$(uuidgen)}"          # generated by the orchestrator, per run
docker run --rm --env FLAG --read-only ... patch-verify-sandbox
unset FLAG                       # orchestrator forgets it immediately after start

Anything that must persist (scores, verdicts) is written by the harness to a mounted output directory, data flows out, capabilities never flow in.

4. --cap-drop=ALL and the non-root worker

Symptom. A workload escaped its workdir (see pitfall 1) and, from inside the container, attached to neighboring processes with ptrace to read another test's memory. The container was "isolated" by namespace, but the worker still held CAP_SYS_PTRACE and ran as root.

Fix. One canonical runtime line, plus build-time ownership:

docker run --rm \
  --cap-drop=ALL \                 # no ptrace, no mknod, no net-admin, nothing
  --security-opt no-new-privileges:true \
  --pids-limit 64 --memory 1g --cpus 1 \
  --user 65532:65532 \             # non-root uid/gid; chown at build time
  --read-only --tmpfs /work:rw,size=64m,exec \
  --network none \                 # offline means offline
  patch-verify-sandbox

5. EOL base-image repository rot

Symptom. A harness that had built cleanly for four months failed overnight: apt-get update returned 404s for every package mirror. The Debian release had hit end-of-life; the mirrors moved to archive.debian.org with no warning inside the build.

Failure shape. Reproducibility decays silently. Security harnesses are the worst place for this, because a rebuild six months later, exactly when you need to re-verify an old finding, is when the rot bites.

Fix. Pin by digest, not tag; if you must stay on an EOL release, pin its archive explicitly and accept the stale-package risk in writing:

# digest pin: the only reference that cannot silently change
FROM debian@sha256:4b0e3c2fb5b1f1e5c3a2d6... 

# if pinned to an EOL release, freeze its world:
RUN printf 'deb [check-valid-until=no] https://archive.debian.org/debian buster main\n' \
      > /etc/apt/sources.list \
 && apt-get -o Acquire::Check-Valid-Until=false update

The checklist that fell out

ControlCatchesCost
.dockerignore with .git, .envPitfalls 2, 3Minutes
Digest-pinned base + lock filePitfall 5Minutes, quarterly
Per-run secret injectionPitfall 3Small orchestrator change
--cap-drop=ALL --user 65532 --read-only --network nonePitfalls 1, 4 (blast radius)One flag set
Realpath validation at extraction + tmpfs scratchPitfall 1~40 lines
Image audit (dive/docker history) in CIRegressions of 2 and 3One CI step

All of the above ships as the default profile of Silvauren/patch-verify-sandbox. If your harness runs other people's code, or your own, which during an incident is the same trust level, start from this list before writing a single test.