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

Implementing a Local Voice Assistant with Qwen3 on RTX 5060 Ti
A fully local home automation voice assistant using Qwen3 ASR, LLM, and TTS on an RTX 5060 Ti, featuring Morgan Freeman voice cloning and a variety of integration tools.

Qwen 3.6 27B with MTP on V100 32GB: 54 t/s via llama.cpp Branch
am17an's MTP branch of llama.cc runs Qwen 3.6 27B at 54 t/s on V100 32GB via PCIe adapter, dropping to 29-30 t/s without MTP.

Weejur: A Simple UI Front-End for GitHub Pages Publishing
Weejur is a free tool that provides a simplified UI for publishing websites via GitHub Pages, allowing users to paste HTML or upload files after OAuth login.

HTML Artifacts Replace Google Docs for Technical Docs, but Lack Commenting
Claude-generated HTML artifacts are replacing Google Docs for long-form technical content like spike readouts and architecture notes, but the sandboxed iframe nature prevents inline commenting and review features.