Show HN: Fence – Sandbox CLI commands with network/filesystem restrictions

github.com

67 points by jy-tan 5 days ago


Hi HN!

Fence wraps any command in a sandbox that blocks network by default and restricts filesystem writes. Useful for running semi-trusted code (package installs, build scripts, unfamiliar repos) with controlled side effects, or even just blocking tools that phone home.

> fence curl https://example.com # -> blocked

> fence -t code -- npm install # -> template with registries allowed

> fence -m -- npm install # -> monitor mode: see what gets blocked

One use-case is to use it with AI coding agents to reduce the risk of running agents with fewer interactive permission prompts:

> fence -t code -- claude --dangerously-skip-permissions

You can import existing Claude Code permissions with `fence import --claude`.

Fence uses OS-native sandboxing (macOS sandbox-exec, Linux bubblewrap) + local HTTP/SOCKS proxies for domain filtering.

Why I built this: I work on Tusk Drift, a system to record and replay real traffic as API tests (https://github.com/Use-Tusk/tusk-drift-cli). I needed a way to sandbox the service under test during replays to block localhost outbound connections (Postgres, Redis) and force the app to use mocks instead of real services. I quickly realized that this could be a general purpose tool that would also be useful as a permission manager across CLI agents.

Limitations: Not strong containment against malware. Proxy-based filtering requires programs to respect `HTTP_PROXY`.

Curious if others have run into similar needs, and happy to answer any questions!

uwemaurer - 5 days ago

I like it. Is it also possible to block all filesystem access and only allow certain directories / files?

Currently it seems to allow read access by default and only allows to block some paths with with "denyRead"

will_wright - 9 hours ago

pretty close to anthropic’s version, yes? or am I mistaken

https://github.com/anthropic-experimental/sandbox-runtime

vivzkestrel - 3 hours ago

- can i run user submitted untrusted code in this? and can it do a pip install if user wants or an npm install?

kxbnb - 5 days ago

Nice work on Fence! The network/filesystem restriction approach is exactly what's needed for running untrusted commands safely.

We're working on similar containment problems but at the API/MCP layer at keypost.ai - enforcing what outbound calls an agent can make rather than what local filesystem/network it can access. The two layers complement each other well.

The "restrictions as code" pattern is powerful. Are you thinking about extending to other resource types (API calls, token budgets, etc.)?

foresto - 8 hours ago

Can fence wrap applications that do their namespace-based sandboxing?

This could allow finer control than the application's own sandbox offers. For example, Flatpak apps run in bubblewrap containers with all-or-nothing network permissions. Being able to restrict access by domain name would be useful.

_pktm_ - 5 days ago

Thank you for sharing. Why do you say that it’s not strong protection against malware? Seems like it might be pretty handy there, at least with respect to untrusted code.

luckman212 - 5 hours ago

Is there anything like this for macOS?

Marceltan - 5 days ago

Nice, this was helpful for us internally. Good call on allowing importing of existing .claude/settings.json, makes my life easier on personal projects.

gregpr07 - 9 hours ago

Wow this is really cool