█

AI/TLDR

Buy me a coffee
Buy me a coffee

Fence

Wrap any command in a container-free sandbox that blocks the network by default and limits what it can write

Code Sandboxes & IsolationOpen source
Language
Go
License
Apache-2.0
$curl -fsSL https://cli.fencesandbox.com/install.sh | sh
IN SHORT

What is Fence?

Fence is a command-line tool that wraps a command in a sandbox which blocks network access by default and restricts filesystem operations according to configurable rules. It sits in the Code Sandboxes & Isolation category of the Agents & Automation tools and is open-source, written in Go and licensed Apache-2.0.

Overview

Fence is a command-line tool that wraps a command in a sandbox which blocks network access by default and restricts filesystem operations according to configurable rules. You put fence in front of the command — fence npm install, fence -- claude — and it runs with no outbound network unless you allowlist domains, and with writes limited to the paths you choose. It is aimed at semi-trusted code: package installs, build scripts, CI jobs and unfamiliar repositories, where you want controlled side effects rather than "run it and hope".

It is deliberately lightweight. Instead of a container or VM, Fence uses process-level operating-system primitives: sandbox-exec on macOS and bubblewrap on Linux, with outbound traffic filtered through a proxy so that domain allowlists can be enforced. Rules live in a fence.jsonc (or fence.json) file that Fence finds in the current directory or its parents, falling back to a user config under ~/.config/fence. Configs can extend built-in templates such as code, and fence config show prints the inheritance chain and the fully resolved policy as JSON.

Fence also works as a permission manager for CLI coding agents. Its code template is listed as working with Claude Code, Codex, Gemini CLI, OpenCode, Amp, Droid, GitHub Copilot and others, and agent hooks can rewrite an agent's shell tool calls to run through fence -c. The project is explicit about its limits: it is not a hardened containment boundary for actively malicious code, it does not cap CPU, memory or disk, and allowing a domain means code can send data to that domain. For stronger isolation its docs point to Firecracker, gVisor or Kata Containers. Fence can be used as a CLI or as a Go package.

What it does

  • Network isolation: all outbound traffic blocked by default, with domains allowlisted in config
  • Filesystem restrictions on read and write paths, plus built-in protection that blocks writes to files such as .git/hooks, shell startup files and IDE config directories
  • Command blocking for dangerous commands like rm -rf /, git push or npm publish, and SSH filtering of allowed hosts and commands
  • Built-in templates, including code and code-relaxed for guarding CLI coding agents, that configs can extend
  • Monitor mode (-m) that logs blocked requests and violations in real time, optionally to a separate log file
  • Cross-platform on macOS (sandbox-exec) and Linux (bubblewrap), usable as a CLI or a Go library

Getting started

Install the CLI, watch it block a network call, then allowlist what you need in a config file and wrap a coding agent with a built-in template.

Install Fence

Use the install script on macOS or Linux, or Homebrew on macOS. go install github.com/fencesandbox/fence/cmd/fence@latest also works.

bashbash
curl -fsSL https://cli.fencesandbox.com/install.sh | sh

# or, on macOS
brew tap fencesandbox/tap
brew install fencesandbox/tap/fence

Add the Linux dependencies

On Linux, Fence needs bubblewrap for sandboxing and socat for network bridging. Root is not normally required; fence --linux-features shows what your environment supports.

bashbash
# Ubuntu/Debian
sudo apt install bubblewrap socat

Run your first sandboxed command

With no config, every outbound request is blocked, so this fails with a 403 from the CONNECT tunnel. Use -c for compound shell commands.

bashbash
fence curl https://example.com
# curl: (56) CONNECT tunnel failed, response 403

fence -c "echo hello && ls -la"

Allowlist domains and writes in a config

fence config init writes a starter config that extends the code template. A project's fence.jsonc can add allowed domains, writable paths and denied commands on top of it.

jsonjson
{
  "$schema": "https://raw.githubusercontent.com/fencesandbox/fence/main/docs/schema/fence.schema.json",
  "extends": "code",
  "network": { "allowedDomains": ["private.company.com"] },
  "filesystem": { "allowWrite": ["."] },
  "command": { "deny": ["git push", "npm publish"] }
}

Wrap a coding agent and watch what it tries

Run an agent under the code template, and use monitor mode to see blocked requests. For full-screen TUIs, send Fence's logs to a file and follow them in another terminal. Use -- to separate Fence's flags from the command's.

bashbash
fence -t code -- claude

fence -m --fence-log-file /tmp/fence.log -- claude
tail -f /tmp/fence.log
Terminal recording of Claude Code running under Fence: asked to show ~/.netrc, it reports that it has no permission to read the file.
Under Fence, Claude Code is asked to read ~/.netrc and the sandbox denies the read.Fence README ↗

Expose a dev server port

-p lets your machine connect to a server inside the sandbox (bound to 127.0.0.1) while outbound network stays restricted.

bashbash
fence -p 3000 -c "npm run dev"

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Running npm install, pip install or a build script in an unfamiliar repository with default-deny egress and writes scoped to the workspace
  • Adding a tool-agnostic, defense-in-depth layer around CLI coding agents such as Claude Code, Codex or Gemini CLI, with one policy shared across them
  • Committing a reviewed sandbox config once and applying the same rules on developer machines and in CI jobs
  • Auditing what a command tries to reach with monitor mode before deciding which domains to allow

How Fence compares

Fence alongside other open-source code sandboxes & isolation tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Daytona★ 71.2kDaytona is an open-source runtime that spins up isolated sandboxes in under 90ms so agents can safely run and persist AI-generated code.
NVIDIA NemoClaw★ 23.1kNVIDIA's reference stack for running OpenClaw, Hermes and LangChain Deep Agents Code inside OpenShell sandboxes, adding managed inference, network policy, snapshots and CLI lifecycle control.
OpenShell★ 22.1kNVIDIA's open-source runtime that runs autonomous AI agents in sandboxes, enforcing a declared policy on every file access, syscall and network connection and formally verifying policy changes.
OpenSandbox★ 18kOpenSandbox gives AI agents a safe place to run code and commands, with one unified API across Docker and Kubernetes runtimes and SDKs in five languages.
E2B★ 15.1kE2B is open-source infrastructure that runs AI-generated code inside secure, isolated cloud sandboxes, controlled from JavaScript or Python SDKs.
AX (Agent Executor)★ 15kGoogle's declarative orchestrator for agent workloads: a Task runs untrusted agent code in a sandbox, while Workspace, Gateway and Model resources wire up its repos, network allowlist and LLM credentials.
Astrid★ 10.3kA portable Rust runtime that executes software as sandboxed WebAssembly capsules, where every file, network, process and tool call is gated by a signed, revocable, per-principal capability instead of ambient authority.
Fence★ 1kWrap any command in a container-free sandbox that blocks the network by default and limits what it can write