{"by":"jy-tan","descendants":23,"id":46695467,"kids":[46704188,46757863,46758355,46769116,46704404,46695642,46761289,46760369,46757580,46708202],"score":78,"text":"Hi HN!<p>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.<p>&gt; fence curl <a href=\"https:&#x2F;&#x2F;example.com\" rel=\"nofollow\">https:&#x2F;&#x2F;example.com</a>  # -&gt; blocked<p>&gt; fence -t code -- npm install        # -&gt; template with registries allowed<p>&gt; fence -m -- npm install               # -&gt; monitor mode: see what gets blocked<p>One use-case is to use it with AI coding agents to reduce the risk of running agents with fewer interactive permission prompts:<p>&gt; fence -t code -- claude --dangerously-skip-permissions<p>You can import existing Claude Code permissions with `fence import --claude`.<p>Fence uses OS-native sandboxing (macOS sandbox-exec, Linux bubblewrap) + local HTTP&#x2F;SOCKS proxies for domain filtering.<p>Why I built this: I work on Tusk Drift, a system to record and replay real traffic as API tests (<a href=\"https:&#x2F;&#x2F;github.com&#x2F;Use-Tusk&#x2F;tusk-drift-cli\" rel=\"nofollow\">https:&#x2F;&#x2F;github.com&#x2F;Use-Tusk&#x2F;tusk-drift-cli</a>). 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.<p>Limitations: Not strong containment against malware. Proxy-based filtering requires programs to respect `HTTP_PROXY`.<p>Curious if others have run into similar needs, and happy to answer any questions!","time":1768932303,"title":"Show HN: Fence – Sandbox CLI commands with network/filesystem restrictions","type":"story","url":"https://github.com/Use-Tusk/fence"}