DEV Community

Cover image for What unshare -n leaves behind: building a boundary for an AI recon agent
GnomeMan4201
GnomeMan4201

Posted on Edited on AI-assisted

What unshare -n leaves behind: building a boundary for an AI recon agent

How local Unix sockets bypass network namespaces

Update: the comments on this post found more gaps, including a real hole and a fix that got bypassed. Follow-up: The Fix Passed CI. io_uring Walked Right Through It.

Why the boundary has to hold

My AI agent's sandbox passed all 13 of its isolation tests on a real GitHub runner, and the jailed process could still talk to an unauthorized program outside the jail, not just the broker it was meant to be limited to. It took one Unix socket.

I'm building a bug-bounty pipeline that runs entirely on GitHub Actions. An AI agent does recon, but it never touches the network itself. Every request goes through a broker that checks a signed authorization: which hosts, which methods, how many requests, until when.

That boundary is the whole safety story. An agent that reaches the network directly can hit out-of-scope systems, blow through rate limits, or follow instructions planted on a target's page. Any of those can get a hunter banned, and for me a ban ends a goal I've worked toward for years.

So the boundary has to hold when the agent is actively trying to escape, not just when it behaves. This is the record of finding a path through it, closing that path, and testing what replaced it.

The setup

The pipeline splits power three ways. The agent is untrusted and gets no network. The broker holds the policy and makes every request. The signed authorization record says what the broker may do, and only I can sign it.

The intended design gives the agent one communication path: a Unix socket to the broker. Every layer after that must agree before a byte leaves.

Two AI systems did the engineering. ChatGPT built each change as a candidate and ran what it could in its own container. Claude reviewed every candidate independently: read the diffs, reran the suites on its own Linux sandbox, and checked results against GitHub's own records. The repository is private, so the test results here are my records; the socket reproduction below is the part you can run yourself.

I controlled repository approvals. During the work, we tightened that rule to require the repository, branch, operation and exact commit (more on why below).

Why the first jail passed its tests

The first jail looked solid. The agent dropped to uid 65534 (nobody) with no-new-privs inside its own network namespace, and the runtime log recorded its effective and bounding capabilities as zero. A later probe used this variant, which adds a user namespace: -r maps the agent to root inside that namespace only, and after the final setpriv the probe again recorded zero effective and bounding capabilities:

setpriv --reuid 65534 --regid 65534 --clear-groups \
  unshare -Urn \
  setpriv --no-new-privs --bounding-set -all --inh-caps -all \
  python3 -I agent.py
Enter fullscreen mode Exit fullscreen mode

The tests agreed. 18 out of 18 authorization checks passed, and 13 out of 13 isolation checks passed on a GitHub-hosted runner. The probe above added raw TCP and UDP and passed 19 out of 19, with every direct connection failing ENETUNREACH.

The problem was what the tests measured. Every egress check was an AF_INET socket: TCP, UDP, HTTP. The jail did block those. Nobody had asked what else a process can talk to without an IP stack.

The hole: filesystem Unix sockets crossed the network boundary

A network namespace isolates the IP stack. Filesystem Unix sockets live in the filesystem, and the jail still shared the host's mount namespace. Any socket file the agent could reach and connect to was a channel to a process outside the jail, bypassing the broker.

The reproduction uses two Python scripts and the launch commands below. Run it in a disposable Linux test environment with Python 3, util-linux, and permission to create the required namespaces. First, save listener.py, a host listener on a world-writable socket:

# listener.py: runs on the host, outside any jail
import os, socket, sys
path = sys.argv[1]
if os.path.exists(path):
    os.unlink(path)
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.bind(path)
os.chmod(path, 0o666)
s.listen(1)
s.settimeout(8)
conn, _ = s.accept()
print("HOST GOT:", conn.recv(100))
Enter fullscreen mode Exit fullscreen mode

Second, save client.py, which will run inside the jail:

# client.py: run inside the jail by the commands below
import os, socket, sys
print("agent netns:", os.readlink("/proc/self/ns/net"))
try:
    socket.create_connection(("127.0.0.1", 9), timeout=1)
except OSError as e:
    print("inet:", e.errno)                      # 101, ENETUNREACH
u = socket.socket(socket.AF_UNIX)
u.connect(sys.argv[1])
u.sendall(b"crossed netns via unix socket")      # host receives this
print("unix: sent")
Enter fullscreen mode Exit fullscreen mode

Then run the listener, and the client inside the exact jail from above:

# run as root, from a folder uid 65534 can read (chmod 755)
mkdir -p /tmp/demo && chmod 755 /tmp/demo
echo "host netns: $(readlink /proc/self/ns/net)"
python3 -I listener.py /tmp/demo/s.sock & sleep 0.5
setpriv --reuid 65534 --regid 65534 --clear-groups \
  unshare -Urn \
  setpriv --no-new-privs --bounding-set -all --inh-caps -all \
  python3 -I "$PWD/client.py" /tmp/demo/s.sock
wait
Enter fullscreen mode Exit fullscreen mode

The output tells the whole story:

host netns: net:[4026531833]
agent netns: net:[4026532265]
inet: 101
unix: sent
HOST GOT: b'crossed netns via unix socket'
Enter fullscreen mode Exit fullscreen mode

The agent was in a different network namespace and TCP was unreachable, yet the host got the bytes. To be precise about scope: this shows communication with a host-side listener outside the intended broker path, not direct internet access or control of the host. On a GitHub runner that matters: services like systemd-resolved and the D-Bus system bus listen on filesystem sockets, so a reachable one could become a DNS-based exfiltration channel. I didn't test that on a runner; the point is that the class of path existed.

Two details from the same probing are worth knowing. Abstract Unix sockets (the \0name kind) are scoped to the network namespace; a host listener refused the connection (ECONNREFUSED). And the original jail also shared the host's PID namespace, so the agent could see every process and its command line.

The fix: give the agent its own world, then test it

The first fix attempt masked /run, /tmp and /var/tmp with tmpfs. It passed its own check, which only scanned those directories. A full-filesystem scan from inside that jail still found a socket under the home directory, protected only by file permissions. Masking is a denylist; the next socket lives somewhere you didn't list.

The real fix builds the agent a fresh root and throws the host's tree away:

  1. New mount, network, PID, IPC and UTS namespaces (unshare --mount --net --pid --ipc --uts --fork).
  2. A tmpfs root holding only what the agent needs: read-only /usr (later narrowed further), /dev/null, /dev/zero, /dev/urandom, the agent script, and one bind-mounted broker socket.
  3. pivot_root into it, detach the old root, mount a fresh /proc for the new PID namespace.
  4. Only then drop to uid 65534 with no capabilities and no-new-privs.

The test changed too. The agent now walks its entire visible filesystem and tries to connect to every socket it finds. It passes only if exactly one socket exists, /run/broker.sock, and only it connects. It also requires ECONNREFUSED on a host abstract socket, ENOENT on a world-writable host socket, ENETUNREACH for TCP and UDP, and at most three visible processes. In practice it sees one: itself. The scan is a regression check, not a proof: it sees only what the agent can list, not inherited file descriptors or other IPC. The fresh root is the actual control.

Real CI broke the fix, which is the point of real CI

The fixed jail passed 21 out of 21 locally. On GitHub it timed out after 45 seconds and produced no output at all, because the timeout threw away the agent's stdout.

Version Where Result What was wrong
v1 Reviewer sandbox 20/21, then 21/21 Interpreter symlink pointed through /etc, missing in the jail; a test expected zero ledger spend after a legitimate request
v2 GitHub runner Timed out at 45 s Most likely the socket scan, walking all of the runner's /usr: Android SDK, .NET, Swift and more
v3 Reviewer sandbox Crashed before the jail A stray trailing comma turned the command list into a tuple; the jail also lacked /etc/ld.so.cache
v4 GitHub runner 21/21 Scan covered 1,347 entries in 0.024 s

The /usr mount was the leading explanation for the timeout. Narrowing it resolved the failure in v4, although v2's missing output prevented a definitive diagnosis. Locally, /usr held 166,207 entries and the walk took about 2 seconds. A stock runner image carries far more. Instead of raising the timeout, v3 stopped exposing /usr at all: the jail binds only the interpreter, its standard library, setpriv and the shared libraries ldd resolves. That made the scan fast and shrank what the agent can read.

v3 also added timestamped phase markers and kept partial output on timeout, so the next failure would say where it stopped. I tested that path deliberately by making the agent hang: the log showed the exact phase, and no agent process survived.

Five more layers, and what review caught

Once the new jail passed on GitHub, the same loop added five more layers. Every one was merged with CI green, and review shaped or caught something in each before merge.

Layer What it enforces What review or CI caught
Automatic CI The isolation gate runs on every push and pull request touching boundary code A checksum manifest proves files match, not that the gate wasn't weakened; workflow diffs need human reading
Loopback-only gate The broker refuses any destination that isn't loopback, even with a valid signature Review set the design before it was built: resolve once, connect to the checked IP, verify with getpeername(); two IPv6 tests could only run on GitHub
Non-root broker + kernel firewall Broker runs as uid 65532 with no capabilities; iptables and ip6tables owner rules reject its non-loopback traffic The firewall was proven in one namespace and only checked for presence in the broker's; then the broker couldn't read its own code on GitHub's 0750 home directory
Signed port limits Schema v2 signs allowed_ports; unsigned ports are rejected before DNS and at the socket The port check ran first, so the jail's "wrong host" test was blocked by the port rule and no longer tested the host rule
Firewall launcher The real launcher installs and verifies both owner rules before the broker starts, stops it if a rule disappears, and the kernel kills the broker if the launcher dies The new supervisor-kill test matched two processes, because the unshare --fork parent carries the same arguments; a red control without the parent-death signal left the broker running

The kernel firewall finding deserves a sentence. A rule installed in the wrong namespace looks correct and blocks nothing. The fix probes the rule inside the running broker's own namespace, as the broker's uid: synthetic IPv4 and IPv6 destinations are rejected for uid 65532 and reachable for root. With the rule removed, the same probe sends 12 bytes and fails the test.

The signed-port change exposed a quieter testing failure. Nothing leaked, the request was still blocked, but a check that used to guard one rule had silently started guarding a different one. Only reading the reason code exposed it.

What made the failures easier to catch

The code matters less than the habits that caught its bugs. These are the ones I'd keep for any AI-built security code.

  • Pin identities, not descriptions. Every candidate had a manifest hash; every commit was checked byte-for-byte against the tree that was tested. "The tests pass" meant nothing until it named a SHA.
  • Red controls for every check. Delete the thing being tested and confirm the test fails. The port gate, the loopback gate and the kernel firewall probe were all checked this way. A test that can't fail proves nothing.
  • Run on the real platform. My reviewer's sandbox and my own local test machine both had world-traversable home directories; GitHub's runner doesn't. Two of the bugs above only existed on the runner.
  • Use more than one machine on purpose. The reviewer's sandbox had no IPv6; my local test machine couldn't mount a fresh /proc in a nested jail. Between them and GitHub, every check ran somewhere real.
  • Fail closed, and make failure talk. Every setup failure refused to run the agent unconfined. After the timeout, failures also had to say where they stopped.
  • Approvals name the commit. Early on, a "go ahead" after a recommendation was taken as merge approval. It matched what I meant, but it could easily not have. From then on, writes to main needed the repo, branch, operation and exact SHA.
  • Archive evidence before it expires. This workflow keeps artifacts for 30 days. Batches AB-04 through AB-06 were bundled, and every included artifact checked against the SHA-256 digest GitHub recorded for it. AB-07 remains to be archived.

What is still unproven

This is a synthetic baseline, not a production qualification. Every test was written by the same process that built the code. No independent attacker and no live AI model has tried to break out, and the broker, which parses everything the agent sends, hasn't been fuzzed.

Three known engineering blockers remain before I would even consider live-target testing:

  • The loopback-only gate is still on. Removing it is its own reviewed change, and comes only after the two items below.
  • No filesystem sandbox around the broker. It can read anything world-readable on the runner. That's a remaining exposure; I've deferred it while all traffic is held to the local machine for synthetic testing.
  • No resource limits. No cgroups or seccomp yet, so a runaway agent could exhaust the runner.

The real launcher now installs both firewall rules, refuses to start the broker without them, and takes the broker down if the launcher itself is killed: in CI, the broker was gone about 3 milliseconds after a SIGKILL to the launcher. The code still refuses to send traffic anywhere but the local machine.

Evidence

All runs are in the private bounty-pipeline repo. Final main: ddbeef2b78585b88f7f7fac621860b03c86ae388.

Archive GitHub runs What it shows Bundle SHA-256 (abbreviated)
AB-04 #5–#11 Repaired jail 21/21; CI restoration; loopback gate e4929d9f…236a
AB-05 #12–#16 Non-root broker: two startup failures, then 30/30 04ffd337…901b
AB-06 #17–#19 Signed port limits: authorization 60/60, isolation 31/31 4ba16946…6f30
AB-07 #20–#22 Firewall launcher: 17/17, supervisor kill in about 3 ms to be archived

Every artifact in AB-04 through AB-06 was checked against the SHA-256 digest GitHub recorded for it. AB-07 remains to be archived. The repository is private, so these are my traceability records, not evidence readers can check themselves; the workflow keeps artifacts for 30 days, which is why they were bundled. The socket reproduction above is the part anyone can run.

Update (Nov 10): the second counter

Comments on this post pointed at the same blind spot from three directions. The filesystem scan walks names, and a descriptor inherited from before the new root has no name left to find. Thanks to Mudassir Khan, Vladimir Mikhalev and Kartik N V J K for pushing on it.

What the jail checks now, merged to main and passing on a hosted CI runner:

  • Startup descriptor inventory. Before doing anything else, the agent reads /proc/self/fd from the jail's own /proc and requires exactly {0,1,2}. Each of those must resolve to an allowed target: a pipe, /dev/null, a regular file or a tty. A socket on stdio fails closed.
  • Post-connect recount. After connecting to the broker, and before every request, the agent requires stdio plus exactly one socket, matched by inode to the broker connection. An extra descriptor means the agent exits before any request bytes leave.
  • No descriptors over the allowed channel. The broker rejects SCM_RIGHTS and closes anything passed to it.
  • A scan that can't look is a failure. A directory the walk can't list fails the run instead of shrinking the count.

Each check has a red control: a leaked socket, a leaked file, a socket as stdin, a socket as stdout, a socket planted after connect, and an unlistable directory. Each red control failed in CI before its fix landed. The isolation suite is now 47 checks.

One thing I learned along the way: getpeername() on the broker connection returns the broker's host bind path, not the path it is bind-mounted at inside the jail. A check that compares paths fails on every run, and recording the path tells the jailed process a host directory name. Inode matching avoids both problems.

Still open: libraries glibc loads on its own at runtime (NSS, gconv) aren't visible to ldd. The agent doesn't use them today, and a missing library fails loudly rather than widening the view.

Next: The Fix Passed CI. io_uring Walked Right Through It., where the comments here turned into red tests.

Top comments (41)

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

13 out of 13 isolation tests passing while the jailed process could still reach an unauthorized program through one Unix socket is the whole lesson — the tests proved the jail you designed, not the jail you had. The broker holding the only network path is the right split, but the socket itself was the leak. What closes it in the end — removing the socket entirely, or putting the broker behind it too?

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

Small correction, since it's the crux: the broker socket wasn't the leak. That one is the intended path. The leak was every other filesystem socket on the host, which the agent could see because it shared the host's mount namespace.
So the fix kept the broker socket and removed everything else: the agent gets a fresh root where the broker socket is the only socket that exists. The broker side got hardened separately. It runs as its own non-root user, only accepts connections from the agent's uid (checked with SO_PEERCRED), verifies the signed authorization on every request, and a kernel firewall rule blocks it from anything off loopback even if its own checks fail.

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

Fair correction — I had the leak backwards. The broker socket being the intended path makes the fix cleaner: a fresh root where it's the only socket that exists, and the broker hardened on its own side. The SO_PEERCRED check plus signed authorization on every request is the part I'd steal — two independent checks, so one failure doesn't open the door. Is the fresh root per-agent, or do agents share one?

Thread Thread
 
gnomeman4201 profile image
GnomeMan4201 •

Per launch. Every run gets its own fresh root, and it's gone when the agent exits. If I know what you're getting at, though: right now it's one agent at a time. Run a few at once and they'd all share the same uid, so the broker couldn't tell them apart. That'd need a uid or socket per agent first. Good catch, honestly.

Thread Thread
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

Per-launch fresh root is the cleanest answer to my question — the boundary is rebuilt every run instead of trusted to persist. The uid-per-agent point is the real scaling constraint though: until the broker can tell agents apart, concurrency is a shared-identity problem, not a scheduling one. Would you give each agent its own socket path, or keep one socket and key identity off the uid?

Thread Thread
 
gnomeman4201 profile image
GnomeMan4201 •

I'd give each agent its own socket, mounted only into that agent's fresh root, so it can't even see the others. Then check the uid on the broker side as a backup. With one shared socket, everything depends on the uid mapping being right, and a mistake there silently merges two agents.

Thread Thread
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

Per-agent socket is the cleaner fix — it removes the shared-uid failure mode entirely instead of patching around it. The broker-side uid check as a backup is the right defense-in-depth: it should never be the thing that decides, only the thing that catches a mistake. That's the boundary the original design was missing.

Collapse
 
analista_83 profile image
Sammi De Blas •

unshare -n closes the outbound network path but leaves the filesystem writes open, so an agent can still move data through a mounted directory. A read-only root plus a tmpfs for the working set covers what the namespace alone does not. Worth adding to the checklist, since most sandbox writeups stop at the network rule.

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

agreed, and that's roughly where the jail landed. each launch gets a fresh tmpfs root owned by root, so the agent's uid can't write to it. the only host files mounted in are read-only runtime pieces (python, stdlib, libs) plus /dev/null, zero and urandom, and the broker socket is the only IPC endpoint. the one writable dir is a private tmpfs /tmp, and that's exactly where the next hole showed up: not moving data out, but binding a socket a host process could reach. writeup: dev.to/gnomeman4201/the-fix-passed...

Collapse
 
mp3sss31 profile image
mp3sss •

Unix sockets living outside the network namespace is the classic gotcha — unshare -n only isolates the net stack, not the filesystem paths and abstract-socket namespace, so a process can still reach a daemon through /run or an abstract socket even with no TCP route. That's why the broker-as-policy point matters: the boundary has to sit on the allowed channel itself, rather than relying on the jail's missing routes to deny everything. The follow-up about io_uring walking through the CI-passed fix is a good reminder that namespace isolation tests prove the known paths, not the kernel interface an agent will actually probe next.

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

I agree on /run. Filesystem-path sockets were the real leak. Small correction though: abstract sockets are tied to the net namespace, so unshare -n does cut those off. The exposure comes from bind mounted paths and inherited fds, not the abstract namespace. Curious if you've seen a setup where abstract sockets leaked anyway, e.g. a shared netns via nsenter or --net=host.

Collapse
 
alexcodebytes profile image
Oleksandr •

"The tests agreed. The problem was what the tests measured." That's the whole article in two sentences, and it's the most useful thing I've read about sandbox verification.

The AF_INET-only blind spot is a genuinely good illustration of a general failure mode: the threat model was written around network egress, so the isolation tests were written around network egress, and the Unix socket — which isn't network in the model's terms but absolutely is in the attacker's — was invisible to the whole verification suite. Eighteen checks passing means nothing if they all ask the same question.

Your point about masking being a denylist is the other one worth pinning somewhere permanent. "Mask /run, /tmp, /var/tmp" is a reasonable-looking fix that's structurally worse than it appears, because the next socket lives where you didn't look. Building a fresh root and throwing away the host tree inverts the logic correctly: the agent sees only what you gave it, not everything minus what you remembered to remove.

The "run on the real platform" lesson deserves more emphasis than it usually gets. Two bugs only existed on the runner, and one of them — the timeout with stdout discarded — is the kind of thing that silently burns a day. The v3 fix (phase markers plus partial output on timeout) is the pattern I'd steal from this piece even if I never build a jail: the failure has to say where it stopped.

What I appreciate most is the "still unproven" section. No independent attacker, no live model, no fuzzing of the broker that parses everything the agent sends — that's a real gap, and the fact that it's written down rather than glossed over is what makes the rest of the write-up trustworthy. The 30-day artifact expiry is worth a second look, though; if those bundles are the only record of a CI run, a private repo with a 30-day window means the evidence ages out faster than anyone will want it.

One question: you noted abstract Unix sockets are scoped to the network namespace, so a host listener refused the connection. Did you rely on that scoping anywhere, or is it just a useful property you observed and documented?

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

Thanks, and good question. It's a property I rely on, but not one I treat as the control.
Abstract sockets are scoped to the network namespace, and the agent gets its own network namespace anyway, so host abstract sockets are out of reach as a side effect of that. The broker connection deliberately doesn't use one: it's a pathname socket, bind-mounted as the only socket in the agent's fresh root.
I do test it, though. The jail suite requires ECONNREFUSED when the agent tries a host abstract socket. That's there as a tripwire for a future change: if someone ever shares the network namespace to give the agent loopback access, abstract-socket isolation disappears with it, and that check is what would catch it.
On the 30-day expiry: agreed, that's why each batch gets pulled out of GitHub and bundled with the digests GitHub recorded, so the record outlives the run. It's still my record rather than something readers can check, which is why the reproduction is the part I put in front.

Collapse
 
alexcodebytes profile image
Oleksandr •

The abstract-socket check as a tripwire for a future change is the smart part — it's testing the assumption, not just the current state. That's the difference between a regression test and a real guard.

Fair enough on the bundling too. If the reproduction is public and the records are archived with digests, the trust boundary is honest rather than hidden.

Thread Thread
 
gnomeman4201 profile image
GnomeMan4201 •

Exactly. The check is worth more for the assumption it pins down than for today's result. That's the pattern I'd generalize: when a guarantee comes "for free" from another control, write a test that fails if that control ever changes. Thanks for reading it this closely.

Thread Thread
 
alexcodebytes profile image
Oleksandr •

"Free" guarantees are the most dangerous ones because they're invisible until the day the other control changes and everything collapses silently. Writing a test for the implicit dependency is exactly how you make it explicit. Great discussion!

Thread Thread
 
gnomeman4201 profile image
GnomeMan4201 •

agreed ...i appreciate this conversation.

Collapse
 
eye_java_420f1faa10ae8b86 profile image
Nan •

The config tree only tells you what you asked for. The boundary is only real where you can name the exit.

A cheaper test than trusting unshare: run the agent, have it try to exfiltrate through every syscall class you can think of (open socket on an existing fd, write to an inherited mount, msg to a known IPC key), and assert each one fails. If any succeed, the boundary has a hole regardless of what netns says.

The tricky part is already-open connections — a socket opened before the namespace was created keeps working. So the checklist has to start with "no fds survive the boundary," not "no new connections possible."

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

Good catch. unshare -n only blocks new connections, not ones already open. I'm adding a startup check that fails if the agent has any open fds beyond the basics plus the broker socket. Your "try every exit and assert it fails" test is going on the list too

Collapse
 
maxbuildsdev profile image
Max Kaya •

The part that stings is that all 13 isolation tests used AF_INET sockets, so the whole test suite shared one blind spot. I've replicated the socket-file bypass in a throwaway container and it's exactly as you describe: netns isolates the IP stack, the mount namespace is what carries the channel.

Two questions on the v2 fix: you mention "no connecting to unix sockets outside a whitelist" — is the whitelist path-based (checked at connect time in the broker?) and does an agent with write access to an allowed directory still risk creating a socket file that a privileged helper later connects to? Also, did the user-namespace variant (-Urn, root-inside-ns) change anything here, or was it equally exposed since userns gives no protection against shared mounts?

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

update on all three:
1: no connect time whitelist, that was loose wording on my part. the control is the mount namespace. the agent walks the whole jail root (minus /proc and /sys) and requires exactly one socket, /run/broker.sock, plus zero abstract sockets in /proc/net/unix
2: yes, and it was real. in the pre fix jail the agent ran as 65534, bound /tmp/agent.sock after startup, and a host process running as the same uid connected through /proc//root/tmp/agent.sock on the CI runner. fixed with a dedicated uid (65531) + seccomp returning EPERM on bind/listen. the first version of that filter got bypassed through io_uring's own bind/listen ops (6.11+), so io_uring_setup/enter/register are denied now too
3: the jail doesn't use a user namespace at all, it's root run unshare then setpriv to the dedicated uid. separately, in a quick test outside the repo, unshare -rn left a host path socket connectable, since file access maps back to the outer uid
full writeup, your question is section 4: dev.to/gnomeman4201/the-fix-passed...

Collapse
 
mudassirworks profile image
Mudassir Khan •

the part that stuck with me is that 13 passing isolation tests and an open Unix socket coexisted, because the tests only asked whether the network was blocked, not what else the process could reach. i have seen the same shape with agent tool sandboxes, the allowlist is checked at the tool layer while a descriptor inherited from the parent sits outside it entirely. after you closed that path, did you add a test that enumerates every open descriptor in the jail at startup, or is it still a hand written list of cases?

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

It's enumerated now, not a list of cases. The first thing the agent does is read /proc/self/fd from the jail's own /proc and require exactly {0,1,2}, and each of those has to resolve to an allowed target (pipe, /dev/null, a regular file or a tty). A socket on stdio fails closed. After the broker connect it counts again and requires exactly one extra fd, matched by inode to the broker connection, before every request. Anything else and the agent exits before a request goes out. On the other side, the broker rejects SCM_RIGHTS and closes anything passed to it.

Each check has a red control (leaked socket, leaked file, socket as stdin/stdout, a socket planted after connect), and each one failed in CI before its fix landed.

Collapse
 
kartik-nvjk profile image
Kartik N V J K •

Masking /run, /tmp and /var/tmp and then passing a check that only scanned those three directories is a loop I recognize. Binding only the interpreter, the stdlib and what ldd resolves got the scan down to 1,347 entries in 0.024 seconds and shrank what the agent can read at the same time. Did anything in the agent's stack load libraries at runtime that ldd missed, or did the stdlib set cover it?

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

ldd isn't only run on the interpreter. It runs on the interpreter, setpriv, and every extension module in lib-dynload, so _ssl → libssl, _ctypes → libffi and the rest are resolved and bound up front. Any "not found", unrecognised output, or dependency outside /usr aborts the jail build rather than falling back to a wider mount.

What ldd still can't see is what glibc loads on its own at runtime: NSS modules and gconv. The agent doesn't touch name resolution or charset conversion, and the failure is loud if it ever does (an error, not a wider view). The stronger version would record what actually gets mapped in a run and diff that against the bind list.

Collapse
 
rosana_e4663528aeaba0b05b profile image
Rosana •

This is an excellent example of why security boundaries need to be tested against what an untrusted process can actually access, rather than what we assume a particular isolation mechanism prevents. The Unix socket finding is especially important: blocking TCP and UDP does not mean a process is truly disconnected from the outside world. Different communication mechanisms can cross boundaries that appear secure on the surface.

What I find most valuable is the willingness to treat every successful test as a hypothesis that still needs to be challenged. The red-control approach, testing on the actual CI platform, pinning approvals to exact commit hashes, and preserving evidence all demonstrate a level of rigor that is particularly important when AI agents are involved in security-sensitive work.

The update about inherited file descriptors is another strong reminder that isolation is not just about filesystem visibility. A process can retain access through resources it inherited before entering the restricted environment. That makes descriptor auditing and lifecycle control just as important as namespace and filesystem configuration.

I also appreciate the transparency about what remains unproven. Passing 47 checks is meaningful progress, but acknowledging the need for broker fuzzing, resource limits, independent adversarial testing, and further runtime scrutiny makes the work more credible—not less.

The real measure of a security boundary isn't how many tests it passes, but whether it continues to hold when someone deliberately looks for the path you forgot to test.

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

Thanks, appreciate you reading it closely. The fd issue surprised me the most. Have you run into inherited descriptors leaking past a sandbox in your own setups?

Collapse
 
heyvaldemar profile image
Vladimir Mikhalev •

Thirteen of thirteen is the number I'd stop trusting first: no test in that suite had ever been shown a jail with a Unix socket open. A check that has only ever passed hasn't proven it can see.

In the sandbox repo I run, the boundary probe makes eight planted escape attempts, and CI first runs it in a container with every door open, where each has to get through. One of the eight is a Docker socket. Your post found what that misses: every other socket file the jail can reach.

The check I'd add counts instead of naming. From inside the jail, find / -type s should return exactly one path, the broker's. Run it once with the host's mount namespace shared, and it should report your reproduction's listener.

ADR 6, a probe trusted only after it has failed

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

counting's the right idea, but find can't be the only counter. it never sees sockets already open as fds, and it skips dirs it can't list. count fds too or "exactly one" can pass with a way still open

Collapse
 
heyvaldemar profile image
Vladimir Mikhalev •

Both gaps are real. find walks names, and a descriptor inherited from before the new root has no name left to find, so a count of one passes with that socket still open.

The probe I linked has the same blind spot. It connects to four fixed Docker socket paths and to SSH_AUTH_SOCK, and it never lists its own descriptors. Yours would be the second counter:

ls -l /proc/<agent pid>/fd
Enter fullscreen mode Exit fullscreen mode

Any socket:[...] entry there besides the broker's connection is a way out.

The directories find can't list I'd make a failure of their own. A check that could not look has no count to report.

Thread Thread
 
gnomeman4201 profile image
GnomeMan4201 •

Both counters are in. The walk runs with onerror wired in and requires zero traversal errors alongside exactly one socket, and a planted unreadable directory is a red control in CI, so a check that couldn't look fails rather than reporting a smaller count.

I took your second counter all the way: fds are counted at startup (stdio only, with each target checked) and again after connect (stdio plus one inode matched broker socket). A socket planted after connect exits before any request goes out.

Thread Thread
 
heyvaldemar profile image
Vladimir Mikhalev •

The planted unreadable directory is the part I'd keep longest. A count that can't be made to fail is thirteen of thirteen again, one layer down.

ADR 6 carries a caveat on the same control. Two of its open-door checks come back blocked on Docker Desktop, because the PID namespace and file ownership there belong to the VM, so the open-door run only counts on a Linux runner.

I'd write down which runner your red control has to go red on, next to the result.

Thread Thread
 
gnomeman4201 profile image
GnomeMan4201 •

yep, did that. all four workflows pin ubuntu-24.04, and the jail gates (isolation, unix socket, seccomp) record ImageOS, ImageVersion and uname next to the result, since the label's pinned but the image under it isn't. the unlistable-dir control is in too: the walk hits EACCES (13), the agent exits 2, and the broker never gets a request

Thread Thread
 
heyvaldemar profile image
Vladimir Mikhalev •

Exit 2 with an empty broker log is the pair I'd want. The agent's verdict and the far side's record agree, and neither one can stand in for the other.

The image record does the same job across time. ADR 6 treats any run outside CI as a measurement of that sandbox on that day, with its versions written next to it, and the repo claims nothing past that. Your ImageVersion line turns each green into that kind of claim.

A pass with a date on it can be checked again.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.