Exploring macOS's sandbox-exec for Secure Application Execution

sandbox-exec is a command-line utility built into macOS, designed to execute applications within a sandboxed environment. This tool helps in creating a secure, restricted space where applications can run with limited access to system resources, thereby minimizing the risks from malicious code or unintended behavior.
Key Details
Application sandboxing with sandbox-exec is aimed at protecting against malicious code, limiting damage from compromised applications, and enhancing privacy and resource control. To use sandbox-exec, you need a sandbox profile, which is a configuration file that outlines the rules for the secure environment. The basic command syntax is:
sandbox-exec -f profile.sb command_to_runHere, profile.sb specifies the rules, and command_to_run is the application to be executed within these constraints.
Sandbox profiles are written using a Scheme-like syntax and include version declarations, default policies, and specific rules. There are two fundamental approaches to setting up these profiles:
- Deny by Default: Restricts all operations initially and allows only necessary ones. Example:
(version 1) (deny default) (allow file-read-data (regex "^/usr/lib")) (allow process-exec (literal "/usr/bin/python3"))- Allow by Default: Permits all except specific operations. Example:
(version 1) (allow default) (deny network*) (deny file-write* (regex "^/Users"))For practical use, you might set up a sandbox terminal session with no network access:
# terminal-sandbox.sb (version 1) (allow default) (deny network*) (deny file-read-data (regex "/Users/[^/]+/(Documents|Pictures|Desktop)")Run it using:
sandbox-exec -f terminal-sandbox.sb zshAdditionally, macOS provides pre-built profiles in /System/Library/Sandbox/Profiles for common restriction scenarios, such as the no-network profile.
Who It's For
This tool is ideal for developers and security professionals who need to test applications in a controlled environment or impose strict security policies.
📖 Read the full source: HN LLM Tools
👀 See Also

OpenLobster: Self-Hosted AI Agent in Go with 30MB RAM Footprint
OpenLobster is a self-hosted AI assistant written in Go that runs as a single binary with 30MB RAM usage and 200ms cold start. It supports multiple LLM providers including Ollama, OpenRouter, and any OpenAI-compatible endpoint, with memory stored in a graph database.

Sociality.io Releases MCP Server for Claude: Live Social Media Intelligence via OAuth
Sociality.io launched a remote HTTP MCP server that lets Claude access live reporting and competitor data across Instagram, TikTok, Facebook, YouTube, X, and LinkedIn. Free to try.

Custom Status Line for Claude Code Shows Context Usage, Cost, and Git Branch
A Reddit user created a bash script that leverages Claude Code's statusLine setting to display real-time information including context window usage, session cost, active model, and current git branch. The script requires jq and is available on GitHub.

ClawProxy: Self-Hosted AI Routing Proxy for Rotating Free-Tier API Keys
ClawProxy is a self-hosted AI routing proxy that manages multiple free-tier AI API keys to avoid rate limits and provider overloads. It features in-flight key rotation, weighted load balancing, model translation, and a dashboard with deep-parsed logs.