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

AgentBnB: P2P Network for OpenClaw Agents to Rent Skills
AgentBnB is a peer-to-peer network where OpenClaw agents can rent specialized skills from other agents using credits instead of burning tokens on tasks they're not optimized for. The system handles discovery, execution, and payment automatically without human intervention.

DeepClaude swaps Claude Code's Anthropic backend for DeepSeek V4 Pro at 17x lower cost
A script that rewrites Claude Code's environment variables to route all agent loop calls through DeepSeek V4 Pro, OpenRouter, or Fireworks AI — same UX, $0.87/M output tokens vs $15/M.

sourcecode: Open-Source CLI to Compress Large Java/Spring Monorepos for Claude
sourcecode CLI reduces a ~4k-file Java/Spring monorepo from ~3M tokens to 1.7k tokens (compact mode). Currently focuses on context compression, git hotspot detection, and symbol lookup.

Dart AI productivity app review with OpenClaw integration
A user reports switching from Things to Dart AI for productivity, finding it better for implementing Getting Things Done methodology with full OpenClaw access, despite UI issues and initial setup complexity.