M
MercyNews
Home
Back
Fence CLI: Sandbox Commands with Network Restrictions
Technology

Fence CLI: Sandbox Commands with Network Restrictions

Hacker News6h ago
3 min read
📋

Key Facts

  • ✓ Fence is a command-line tool that wraps any command in a sandbox, blocking network access by default and restricting filesystem writes.
  • ✓ The tool uses OS-native sandboxing technologies, specifically macOS sandbox-exec and Linux bubblewrap, to enforce isolation.
  • ✓ Network filtering is handled through a local HTTP/SOCKS proxy, which requires applications to respect the HTTP_PROXY environment variable.
  • ✓ It was originally developed to sandbox services under test during API test replays, blocking localhost connections to force the use of mocks.
  • ✓ Fence offers a monitor mode that allows developers to see what would be blocked without actually enforcing the restrictions.
  • ✓ The tool can import existing permission sets from other tools, such as Claude Code, using a specific import command.

In This Article

  1. A New Layer of Security for the Command Line
  2. Core Functionality and Modes
  3. Technical Architecture
  4. Use Cases and Applications
  5. Limitations and Considerations
  6. Looking Ahead

A New Layer of Security for the Command Line#

Developers frequently run commands that carry inherent risks, from installing new packages to executing scripts from unfamiliar repositories. A new command-line tool aims to mitigate these risks by wrapping any command in a sandboxed environment.

Named Fence, the tool blocks network access by default and restricts filesystem writes. This creates a controlled environment for executing code, preventing unintended side effects or unauthorized data transmission.

The primary goal is to provide a safety net for running semi-trusted code. Whether it is a build script, a package installation, or a tool that might "phone home," Fence offers a way to execute these commands with predictable, limited behavior.

Core Functionality and Modes#

Fence operates by intercepting system calls and network requests, effectively isolating the target command from the host system. By default, it blocks all outbound network connections and prevents write operations outside of a designated directory.

The tool offers several operational modes to suit different scenarios:

  • Default Mode: Blocks all network traffic and restricts filesystem writes.
  • Template Mode: Applies pre-configured rules, such as allowing specific registries for package managers.
  • Monitor Mode: Runs the command while logging what would be blocked, providing visibility without enforcement.

For example, running fence curl https://example.com results in a blocked connection. In contrast, using a template with fence -t code -- npm install allows access to necessary npm registries while still maintaining other restrictions.

"I quickly realized that this could be a general purpose tool that would also be useful as a permission manager across CLI agents."

— Fence Developer

Technical Architecture#

The tool leverages OS-native sandboxing technologies to enforce isolation. On macOS, it utilizes sandbox-exec, while on Linux, it relies on bubblewrap. These underlying mechanisms provide a strong foundation for restricting process capabilities.

For network filtering, Fence employs a local HTTP/SOCKS proxy. This proxy intercepts network requests and applies domain-based filtering rules. However, this approach has a specific limitation: it requires the programs being sandboxed to respect the HTTP_PROXY environment variable.

The architecture is designed to be lightweight and non-intrusive, using standard system utilities rather than requiring kernel modules or complex virtualization layers.

Use Cases and Applications#

The tool was originally conceived to solve a specific problem in API testing. The developer behind Fence works on Tusk Drift, a system for recording and replaying real traffic as API tests. During test replays, it was necessary to sandbox the service under test to block localhost outbound connections to databases like Postgres and Redis, forcing the application to use mocks instead of real services.

This utility extends to broader use cases, particularly with AI coding agents. Running agents with fewer interactive permission prompts can be risky. Fence allows developers to sandbox these agents, reducing the risk of unintended actions.

For instance, an agent can be run with a command like: fence -t code -- claude --dangerously-skip-permissions. Additionally, Fence can import existing permission sets, such as those from Claude Code, using the command fence import --claude.

"I quickly realized that this could be a general purpose tool that would also be useful as a permission manager across CLI agents."

Limitations and Considerations#

While Fence provides a valuable layer of security, it is not a silver bullet. The documentation explicitly states that it is not strong containment against malware. Sophisticated malicious code may find ways to bypass the proxy-based filtering or exploit other system vulnerabilities.

The reliance on proxy-based filtering means that applications which do not honor the HTTP_PROXY environment variable will not have their network traffic filtered. This is a critical consideration for developers evaluating the tool for their specific stack.

Despite these limitations, Fence represents a practical step toward safer command-line execution. It offers a balance between security and usability, allowing developers to run necessary but potentially risky commands with greater confidence.

Looking Ahead#

Fence addresses a common pain point in modern development workflows: the need to run untrusted or semi-trusted code without compromising system integrity. By providing a simple, command-line interface to powerful sandboxing technologies, it lowers the barrier to entry for secure code execution.

The tool is currently available for macOS and Linux, covering the majority of development environments. Its open-source nature invites community feedback and potential contributions to expand its capabilities.

As development workflows increasingly incorporate AI agents and third-party scripts, tools like Fence will likely become essential components of a secure development toolkit. The developer is actively seeking feedback and use cases from the community.

Continue scrolling for more

AI Transforms Mathematical Research and Proofs
Technology

AI Transforms Mathematical Research and Proofs

Artificial intelligence is shifting from a promise to a reality in mathematics. Machine learning models are now generating original theorems, forcing a reevaluation of research and teaching methods.

Just now
4 min
314
Read Article
OpenAI Deploys Age Prediction to Restrict Teen Access on ChatGPT
Technology

OpenAI Deploys Age Prediction to Restrict Teen Access on ChatGPT

OpenAI now uses behavioral signals to identify accounts likely belonging to minors and automatically apply content limits, while experts warn of errors and bias.

21m
3 min
0
Read Article
Venezuela to Use US Oil Funds to Stabilize Currency
Politics

Venezuela to Use US Oil Funds to Stabilize Currency

Interim President Delcy Rodriguez has confirmed that $300 million in revenue from US oil sales will be directed toward stabilizing the nation's currency, marking a significant economic development.

33m
5 min
6
Read Article
HKU Ranks 7th Globally in Education as East Asia Surges
Education

HKU Ranks 7th Globally in Education as East Asia Surges

Hong Kong's oldest university has achieved a top-ten position in the latest global league table for education, while East Asian institutions continue their upward trajectory in international rankings.

43m
5 min
6
Read Article
Japan's Political Earthquake: New Centrist Alliance Emerges
Politics

Japan's Political Earthquake: New Centrist Alliance Emerges

Japan's political landscape faces a historic shift as the Constitutional Democratic Party and Komeito announce a surprise merger, forming a new centrist alliance that could challenge the long-standing ruling coalition.

43m
5 min
6
Read Article
Technology

The Best AirPods to Buy in 2026: A Complete Guide

Whether you're buying your first pair or upgrading, Apple's ecosystem offers distinct advantages. Here’s a breakdown of the four current AirPods models to help you choose.

44m
5 min
2
Read Article
Japan's Long Game: Investment and Resilience
Economics

Japan's Long Game: Investment and Resilience

As global leaders gather to discuss preparedness for geopolitical and climate risks, Japan's strategic approach to long-term investment and resilience emerges as a key model for navigating an uncertain world.

52m
5 min
6
Read Article
Japan Awaits Sentencing in Abe Assassination Case
Crime

Japan Awaits Sentencing in Abe Assassination Case

The man who admitted to assassinating Japan's former Prime Minister Shinzo Abe is scheduled for sentencing this Wednesday, as the nation grapples with the complex legacy of the shocking crime.

55m
5 min
7
Read Article
Hugh Grant and Esther Ghey Back Under-16s Social Media Ban
Politics

Hugh Grant and Esther Ghey Back Under-16s Social Media Ban

A high-profile coalition including actor Hugh Grant and Esther Ghey has urged Westminster party leaders to back a ban on social media for under-16s ahead of a crucial Lords vote.

56m
5 min
6
Read Article
Catalan Rail Network Suspended After Deadly Derailments
Accidents

Catalan Rail Network Suspended After Deadly Derailments

The entire Rodalies de Catalunya rail network faces indefinite suspension after two separate derailments resulted in one death and fifteen injuries. Adif has halted all services pending a full infrastructure safety review.

56m
5 min
6
Read Article
🎉

You're all caught up!

Check back later for more stories

Back to Home