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

cc-lens: Local Dashboard for Claude Code Session Analysis
A developer built cc-lens, a local-first dashboard that reads Claude Code session files from ~/.claude/ and provides usage analytics, cost tracking, and session replay. It runs entirely on your machine with no cloud sync, sign-ups, or telemetry.

AgentPeek: Open-source dashboard for monitoring Claude Code agent teams
AgentPeek is a local dashboard that hooks into Claude Code to provide visibility into agent teams, showing orchestration hierarchies, execution traces, token costs, and file operations. Installation requires cloning the GitHub repo and running pipx install.

Session Memory Feature Introduced in Claude Code
Claude Code now includes a 'Session Memory' feature, generating and maintaining session summaries in summary.md files. Unlock it with tweakcc for interactive sessions exceeding specific token and tool call thresholds.

Ultimate Unreal Engine MCP: Claude Code Can Now Build and Verify Unreal Engine Levels with 132 Tools
Open-source MCP server exposes 132 tools across 26 domains, letting Claude spawn actors, set UPROPERTY values, take viewport screenshots, navigate cameras, and self-correct after mutations.