fence

fencesandboxApache-2.0活跃维护

给编码 Agent 用的轻量沙箱,不依赖容器就能限制命令的网络和文件系统访问,基于 bubblewrap、Landlock、seccomp 等机制实现隔离。

Lightweight, container-free sandbox for running commands with network and filesystem restrictions

v0.1.67发布于 2026-09-01 19:22 UTC1,018star +3 / 7 天44fork同步于 2026-11-10 17:53 UTC

怎么上手

由 README 提炼,执行前请确认
curl -fsSL https://cli.fencesandbox.com/install.sh | sh
硬件要求按 README 说明

README 未说明显存或 GPU 要求;macOS 用 sandbox-exec,Linux 用 bubblewrap,Windows 仅提到 WSL 下可用 Nix 运行。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

轻量无容器沙箱,默认断网并按规则限制文件系统,用来跑半可信代码

给编码 Agent 用的轻量沙箱,不依赖容器就能限制命令的网络和文件系统访问,基于 bubblewrap、Landlock、seccomp 等机制实现隔离。

核心能力

  • 默认阻断全部出站网络,按域名白名单放行
  • 用配置控制文件读写路径的访问范围
  • 按命令拒绝规则拦截 rm -rf /、git push 等危险操作
  • 内置 code 等模板,一条命令套用常用规则集
  • -m 监控模式实时输出被拦截的违规请求

容易踩的坑

Linux 需额外安装 bubblewrap 和 socat,bpftrace 为可选;项目已从 Use-Tusk/fence 迁移到 fencesandbox/fence,旧 Homebrew tap 或 go install 路径需重装;给被运行命令传参数要用 -- 分隔,否则会被当成 Fence 自己的参数。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.1.67
  1. v0.1.67最新正式版2026-09-01 · 2026-09-01 19:22 UTC

    Changelog

    Bug fixes

    • 20d3077c9de909ae0c7ec31896ed35662b7a8855: fix: explain argv EBUSY under WSL mirrored networking (#225) (@jy-tan)
    • 6d6e0c6dd141263fbdfb3b8c317fc0dd565882bb: fix: permit AF_UNIX bind/connect under fence's own TMPDIR on macOS (#217) (@reneleonhardt)
  2. v0.1.662026-08-06 · 2026-08-06 04:43 UTC
    查看更新说明

    Changelog

    Bug fixes

    • 5e3cee041cce3eccdb3f21355943a2a73ceddf16: fix: canonicalize Linux cross-mount bind paths (#209) (@jy-tan)
    • 9adadfee24863529cb85ceae760457a78682273e: fix: prevent hook policy substitution via nested Fence commands (#214) (@jy-tan)
    • 75bd8c4217f24f7fdc3921dacfdf4cefed6142e4: refactor: make Linux bootstrap independent of shell utilities (#203) (@jy-tan)
  3. v0.1.652026-08-01 · 2026-08-01 02:19 UTC
    查看更新说明

    Changelog

    New Features

    • 467121767d8ee42a45afda4434242c670bbd5614: feat(linux): bridge localhost-outbound ports over IPv6 as well as IPv4 (#206) (@hwalinga)

    Bug fixes

    • 9603143d38396bb5f552f204261f40246bdf94af: fix: allow MiniMax API endpoints in code template (#207) (@octo-patch)
    • 88f5cd154346694c0beba227a11d2f9332194037: fix: keep explicitly allowed dangerous files readable on Linux (#208) (@jy-tan)
  4. v0.1.642026-07-26 · 2026-07-26 12:07 UTC
    查看更新说明

    Changelog

    New Features

    • 2611d1b01274124845b680571727168073a2711d: feat: allow writes to .claude agents and commands dirs (#200) (@jy-tan)

    Bug fixes

    • 88c755b179c66a225b60404a63e186b8bd560b41: fix: limit Codex hooks to Bash tool calls (#198) (@jy-tan)
  5. v0.1.632026-07-19 · 2026-07-19 22:30 UTC
    查看更新说明

    Changelog

    New Features

    • dcf105424610d84e78191e55ff897856b957671a: feat: add Codex hook integration (#192) (@jy-tan)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Fence Banner

    GitHub Release Build and test Docs Ask DeepWiki License

    Fence wraps commands in a sandbox that blocks network access by default and restricts filesystem operations based on configurable rules. It's most useful for running semi-trusted code (package installs, build scripts, CI jobs, unfamiliar repos) with controlled side effects, and it can also complement AI coding agents as defense-in-depth.

    # Block all network access (default)
    fence curl https://example.com  # → 403 Forbidden
    
    # Allow specific domains
    fence -t code npm install  # → uses 'code' template with npm/pypi/etc allowed
    
    # Block dangerous commands
    fence -c "rm -rf /"  # → blocked by command deny rules
    

    Fence is also a permission manager for your CLI agents. Works with popular coding agents like Claude Code, Codex, Amp, Gemini CLI, GitHub Copilot, OpenCode, Factory (Droid) CLI, and many more - see agents.md.

    Install

    [!NOTE] Fence has moved from github.com/Use-Tusk/fence to github.com/fencesandbox/fence. If you installed with Homebrew from the old Tusk tap, switch to the new tap:

    brew uninstall use-tusk/tap/fence
    brew untap use-tusk/tap
    brew tap fencesandbox/tap
    brew install fencesandbox/tap/fence
    

    If you installed with go install, reinstall from the new module path:

    go install github.com/fencesandbox/fence/cmd/fence@latest
    

    macOS / Linux:

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

    Homebrew (macOS):

    brew tap fencesandbox/tap
    brew install fencesandbox/tap/fence
    

    Nix (macOS, Linux, Windows (WSL)):

    nix run nixpkgs#fence -- --help
    

    This runs it directly from the repository, without installing fence. If you want to install it, follow the guidelines from NixOS or nix-darwin.

    Go install:

    go install github.com/fencesandbox/fence/cmd/fence@latest
    

    Build from source:

    git clone https://github.com/fencesandbox/fence
    cd fence
    go build -o fence ./cmd/fence
    

    Additional requirements for Linux:

    • bubblewrap (for sandboxing)
    • socat (for network bridging)
    • bpftrace (optional, for filesystem violation visibility when monitoring with -m)

    Usage

    Basic

    # Run command with all network blocked (no domains allowed by default)
    fence curl https://example.com
    
    # Run with shell expansion
    fence -c "echo hello && ls"
    
    # Enable debug logging
    fence -d curl https://example.com
    
    # Use a template
    fence -t code -- claude  # Runs Claude Code using `code` template config
    
    # Monitor mode (shows violations)
    fence -m npm install
    
    # Send Fence's own monitor/debug logs to a file
    fence -m --fence-log-file /tmp/fence.log -- claude
    tail -f /tmp/fence.log
    
    # Inspect the config inheritance chain and active merged config
    fence config show
    
    # Show all commands and options
    fence --help
    

    [!TIP] Need to pass flags to the command you are running? Use -- to separate Fence flags from command flags, for example:

    fence -- claude --dangerously-skip-permissions
    

    Configuration

    When --settings is not provided, Fence first looks for fence.jsonc (or fence.json) in the current directory and parent directories. If none is found, it falls back to ~/.config/fence/fence.{jsonc,json}. Both extensions are treated as JSONC (comments and trailing commas are allowed). See configuration reference for more details.

    {
      "$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"] }
    }
    

    For repo-local overrides on top of each user's normal Fence config, use:

    {
      "extends": "@base",
      "filesystem": { "allowWrite": ["."] }
    }
    

    Use fence --settings ./custom.json to specify a different config.

    Inspect the active config without running a command:

    fence config show
    fence config show --settings ./custom.json
    fence config show --template code
    

    fence config show prints the config chain to stderr and the fully resolved config as plain JSON to stdout, so you can pipe the JSON to tools like jq.

    Create a starter config with sensible defaults:

    # Creates config at the default path with:
    # { "extends": "code" }
    fence config init
    
    # Include scaffold arrays as editable hints
    fence config init --scaffold
    

    Import from Claude Code

    fence import --claude --save
    

    Features

    • Network isolation - All outbound blocked by default; allowlist domains via config
    • Filesystem restrictions - Control read/write access paths
    • Command blocking - Deny dangerous commands like rm -rf /, git push
    • SSH Command Filtering - Control which hosts and commands are allowed over SSH
    • Built-in templates - Pre-configured rulesets for common workflows
    • Violation monitoring - Real-time logging of blocked requests (-m)
    • Cross-platform - macOS (sandbox-exec) + Linux (bubblewrap)

    Fence can be used as a Go package or CLI tool.

    Documentation

    Full docs are hosted at fencesandbox.com/docs.

    Quick links:

    Attribution

    Inspired by Anthropic's sandbox-runtime.