DEV Community

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

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

GnomeMan4201 on November 09, 2026

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 Walke...
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.

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

Collapse
 
glenallen profile image
Glen Allen •

I haven't encountered this exact issue firsthand, but it's a useful edge case to account for when designing agent sandboxes. It highlights why isolation checks should inspect the process's actual open descriptors rather than relying only on namespace and filesystem restrictions. I particularly like the startup and post-connect descriptor checks you added. Do you also plan to test descriptor leakage across child processes or subprocess execution?

Collapse
 
panthpatel profile image
Panth Patel •

The signed-port finding is the one I'd have missed: the request was still blocked, just by a different rule, and only the reason code showed it. In the agent sandbox we run at work, every denied tool call returns its reason so the agent can correct course. Your post is a good argument for asserting on that reason in tests too. Do your jail tests now check the exact reason on every rejection, or only where two rules can overlap?

Collapse
 
ascendra_ventures_92c21f2 profile image
Ascendra Ventures •

"The tests agreed. The problem was what the tests measured." Every isolation test used AF_INET, so the suite shared one blind spot, and 13 of 13 passing said nothing about the filesystem socket sitting in /run. That pattern shows up far beyond sandboxes.

What I liked most is where the thread took the fix. Counting sockets by walking the root is not enough because an inherited descriptor has no name left to find, so you count fds too. A walk that cannot read a directory has to fail rather than report a smaller number, and you prove that with a planted unreadable directory as a red control. Each of those turns an assumption into something that can actually go red.

At Ascendra Ventures we apply the same idea when an agent touches anything outside its box: each boundary gets a test that has been shown to fail with the door open before we trust it passing with the door shut.

When you move to several agents at once, will each one get its own broker socket, or one socket keyed on uid?

Collapse
 
alexshev profile image
Alex Shev •

This is an excellent example of why isolation tests need to describe the capability boundary, not only the syscall family they exercised. Pairing the network namespace with a mount boundary and an explicit allow-list for IPC endpoints makes the broker contract testable. I also like the distinction between an unexpected local channel and direct internet access—it keeps the threat model precise.

Collapse
 
glenallen profile image
Glen Allen •

This is a strong example of why AI-agent security needs defense in depth rather than relying on a single isolation mechanism. At IT Path Solutions, we consider runtime boundaries, resource controls, broker authorization, and adversarial testing together when thinking about secure agentic workflows. The distinction between passing predefined isolation checks and proving that the boundary holds under unexpected conditions is particularly important.

Collapse
 
kursatyz profile image
Kürşat Yılmaz •

The obsession with wrapping remote APIs into multi-layered agent abstractions is creating massive hidden latency and failure cascades in production.

If you profile real-world workloads, bare-metal local inference (via direct C++ / llama.cpp or vLLM bindings) consistently beats fragile cloud wrappers on both predictability and cost. Tooling should eliminate abstraction penalties, not compound them.

Collapse
 
gnomeman4201 profile image
GnomeMan4201 •

Fair i guess, but this one's more about sandboxing than where the model runs. Local inference still needs a boundary.