Skip to content
seatbelt-sandboxer logo

macOS Seatbelt Sandbox Profiling

seatbelt-sandboxer

Generates minimal macOS Seatbelt sandbox configurations. Use when sandboxing, isolating, or restricting macOS applications with allowlist-based profiles.

trailofbits/skills3.4Kinstalls7.4Kstars

SKILL.md

Full skill instructions

macOS Seatbelt Sandbox Profiling

Generate minimally-permissioned allowlist-based Seatbelt sandbox configurations for applications.

When to Use

  • User asks to "sandbox", "isolate", or "restrict" an application on macOS
  • Sandboxing any macOS process that needs restricted file/​network access
  • Creating defense-in-depth isolation if supply chain attacks are a concern

When NOT to Use

  • Linux containers (use seccomp-bpf, AppArmor, or namespaces instead)
  • Windows applications
  • Applications that legitimately need broad system access
  • Quick one-off scripts where sandboxing overhead isn't justified

Profiling Methodology

Step 1: Identify Application Requirements

Determine what the application needs across these resource categories:

CategoryOperationsCommon Use Cases
File Readfile-read-data, file-read-metadata, file-read-xattr, file-test-existence, file-map-executableReading source files, configs, libraries
File Writefile-write-data, file-write-create, file-write-unlink, file-write-mode, file-write-xattr, file-clone, file-linkOutput files, caches, temp files
Networknetwork-bind, network-inbound, network-outboundServers, API calls, package downloads
Processprocess-fork, process-exec, process-exec-interpreter, process-info*, process-codesigning*Spawning child processes, scripts
Mach IPCmach-lookup, mach-register, mach-bootstrap, mach-task-nameSystem services, XPC, notifications
POSIX IPCipc-posix-shm*, ipc-posix-sem*Shared memory, semaphores
Sysctlsysctl-read, sysctl-writeReading system info (CPU, memory)
IOKitiokit-open, iokit-get-properties, iokit-set-propertiesHardware access, device drivers
SignalssignalSignal handling between processes
Pseudo-TTYpseudo-ttyTerminal emulation
Systemsystem-fsctl, system-socket, system-audit, system-infoLow-level system calls
User Prefsuser-preference-read, user-preference-writeReading/​writing user defaults
Notificationsdarwin-notification-post, distributed-notification-postSystem notifications
AppleEventsappleevent-sendInter-app communication (AppleScript)
Camera/​Micdevice-camera, device-microphoneMedia capture
Dynamic Codedynamic-code-generationJIT compilation
NVRAMnvram-get, nvram-set, nvram-deleteFirmware variables

For each category, determine: Needed? and Specific scope (paths, services, etc.)

If the application has multiple subcommands that perform significantly different operations, such as build and serve commands for a Javascript bundler like Webpack, do the following:

  • Profile the subcommands separately
  • Create separate Sandbox configurations for each subcommand
  • Create a helper script that acts as a drop-in replacement for the original binary, executing the sandboxed application with the appropriate Seatbelt profile according to the subcommand passed.

Step 2: Start with Minimal Profile

Begin with deny-all and essential process operations, saved in a suitably-named Seatbelt profile file with the .sb extension.

(version 1)
(deny default)

;; Essential for any process
(allow process-exec*)
(allow process-fork)
(allow sysctl-read)

;; Metadata access (stat, readdir) - doesn't expose file contents
(allow file-read-metadata)

Step 3: Add File Read Access (Allowlist)

Use file-read-data (not file-read*) for allowlist-based reads:

(allow file-read-data
    ;; System paths (required for most runtimes)
    (subpath "/​usr")
    (subpath "/​bin")
    (subpath "/​sbin")
    (subpath "/​System")
    (subpath "/​Library")
    (subpath "/​opt")                    ;; Homebrew
    (subpath "/​private/​var")
    (subpath "/​private/​etc")
    (subpath "/​private/​tmp")
    (subpath "/​dev")

    ;; Root symlinks for path resolution
    (literal "/")
    (literal "/​var")
    (literal "/​etc")
    (literal "/​tmp")
    (literal "/​private")

    ;; Application-specific config (customize as needed)
    (regex (string-append "^" (regex-quote (param "HOME")) "/\\.myapp(/​.*)?$"))

    ;; Working directory
    (subpath (param "WORKING_DIR")))

Why file-read-data instead of file-read*?

  • file-read* allows ALL file read operations including from any path
  • file-read-data only allows reading file contents from listed paths
  • Combined with file-read-metadata (allowed broadly), this gives:
    • ✅ Can stat/​readdir anywhere (needed for path resolution)
    • ❌ Cannot read contents of files outside allowlist

Step 4: Add File Write Access (Restricted)

(allow file-write*
    ;; Working directory only
    (subpath (param "WORKING_DIR"))

    ;; Temp directories
    (subpath "/​private/​tmp")
    (subpath "/​tmp")
    (subpath "/​private/​var/​folders")

    ;; Device files for output
    (literal "/​dev/​null")
    (literal "/​dev/​tty"))

Step 5: Configure Network

Three levels of network access:

;; OPTION 1: Block all network (most restrictive - use for build tools)
(deny network*)

;; OPTION 2: Localhost only (use for dev servers, local services)
;; Bind to local ports
(allow network-bind (local tcp "*:*"))
;; Accept inbound connections
(allow network-inbound (local tcp "*:*"))
;; Outbound to localhost + DNS only
(allow network-outbound
    (literal "/​private/​var/​run/​mDNSResponder")  ;; DNS resolution
    (remote ip "localhost:*"))                   ;; localhost only

;; OPTION 3: Allow all network (least restrictive - avoid if possible)
(allow network*)

Network filter syntax:

  • (local tcp "*:*") - any local TCP port
  • (local tcp "*:8080") - specific local port
  • (remote ip "localhost:*") - outbound to localhost only
  • (remote tcp) - outbound TCP to any host
  • (literal "/​private/​var/​run/​mDNSResponder") - Unix socket for DNS

Step 6: Test Iteratively

After you generate or edit the Seatbelt profile, test the functionality of the target application in the sandbox. If anything fails to work, revise the Seatbelt profile. Repeat this process iteratively until you have generated a minimally-permissioned Seatbelt file and have confirmed empirically that the application works normally when sandboxed using the Seatbelt profile you generated.

If the program requires external input to function fully (such as a Javascript bundler that needs an application to bundle), find sample inputs from well-known, ideally official sources. For instance, these example projects for the Rspack bundler: https://github.com/rstackjs/rstack-examples/tree/main/rspack/

# Test basic execution
sandbox-exec -f profile.sb -D WORKING_DIR=/​path -D HOME=$HOME /​bin/​echo "test"

# Test the actual application
sandbox-exec -f profile.sb -D WORKING_DIR=/​path -D HOME=$HOME \
  /​path/​to/​application --args

# Test security restrictions
sandbox-exec -f profile.sb -D WORKING_DIR=/​tmp -D HOME=$HOME \
  cat ~/​.ssh/​id_rsa
# Expected: Operation not permitted

Common failure modes:

SymptomCauseFix
Exit code 134 (SIGABRT)Sandbox violationCheck which operation is blocked
Exit code 65 + syntax errorInvalid profile syntaxCheck Seatbelt syntax
ENOENT for existing filesMissing file-read-metadataAdd (allow file-read-metadata)
Process hangsMissing IPC permissionsAdd (allow mach-lookup) if needed

Seatbelt Syntax Reference

Path Filters

(subpath "/​path")           ;; /​path and all descendants
(literal "/​path/​file")      ;; Exact path only
(regex "^/​path/​.*\\.js$")   ;; Regex match

Parameter Substitution

(param "WORKING_DIR")                                    ;; Direct use
(subpath (param "WORKING_DIR"))                          ;; In subpath
(string-append (param "HOME") "/​.config")                ;; Concatenation
(regex-quote (param "HOME"))                             ;; Escape for regex

Operations

File operations:

(allow file-read-data ...)          ;; Read file contents
(allow file-read-metadata)          ;; stat, lstat, readdir (no contents)
(allow file-read-xattr ...)         ;; Read extended attributes
(allow file-test-existence ...)     ;; Check if file exists
(allow file-map-executable ...)     ;; mmap executable (dylibs)
(allow file-write-data ...)         ;; Write to existing files
(allow file-write-create ...)       ;; Create new files
(allow file-write-unlink ...)       ;; Delete files
(allow file-write* ...)             ;; All write operations
(allow file-read* ...)              ;; All read operations (use sparingly)

Process operations:

(allow process-exec* ...)           ;; Execute binaries
(allow process-fork)                ;; Fork child processes
(allow process-info-pidinfo)        ;; Query process info
(allow signal)                      ;; Send/​receive signals

Network operations:

(allow network-bind (local tcp "*:*"))              ;; Bind to any local TCP port
(allow network-bind (local tcp "*:8080"))           ;; Bind to specific port
(allow network-inbound (local tcp "*:*"))           ;; Accept TCP connections
(allow network-outbound (remote ip "localhost:*"))  ;; Outbound to localhost only
(allow network-outbound (remote tcp))               ;; Outbound TCP to any host
(allow network-outbound
    (literal "/​private/​var/​run/​mDNSResponder"))     ;; DNS via Unix socket
(allow network*)                                    ;; All network (use sparingly)
(deny network*)                                     ;; Block all network

IPC operations:

(allow mach-lookup ...)             ;; Mach IPC lookups
(allow mach-register ...)           ;; Register Mach services
(allow ipc-posix-shm* ...)          ;; POSIX shared memory
(allow ipc-posix-sem* ...)          ;; POSIX semaphores

System operations:

(allow sysctl-read)                 ;; Read system info
(allow sysctl-write ...)            ;; Modify sysctl (rare)
(allow iokit-open ...)              ;; IOKit device access
(allow pseudo-tty)                  ;; Terminal emulation
(allow dynamic-code-generation)     ;; JIT compilation
(allow user-preference-read ...)    ;; Read user defaults

Known Limitations

  1. Deprecated but functional: Apple deprecated sandbox-exec but it works through macOS 14+
  2. Temp directory access often required: Many applications need /​tmp and /​var/​folders

Example: Generic CLI Application

(version 1)
(deny default)

;; Process
(allow process-exec*)
(allow process-fork)
(allow sysctl-read)

;; File metadata (path resolution)
(allow file-read-metadata)

;; File reads (allowlist)
(allow file-read-data
    (literal "/") (literal "/​var") (literal "/​etc") (literal "/​tmp") (literal "/​private")
    (subpath "/​usr") (subpath "/​bin") (subpath "/​sbin") (subpath "/​opt")
    (subpath "/​System") (subpath "/​Library") (subpath "/​dev")
    (subpath "/​private/​var") (subpath "/​private/​etc") (subpath "/​private/​tmp")
    (subpath (param "WORKING_DIR")))

;; File writes (restricted)
(allow file-write*
    (subpath (param "WORKING_DIR"))
    (subpath "/​private/​tmp") (subpath "/​tmp") (subpath "/​private/​var/​folders")
    (literal "/​dev/​null") (literal "/​dev/​tty"))

;; Network disabled
(deny network*)

Usage:

sandbox-exec -f profile.sb \
  -D WORKING_DIR=/​path/​to/​project \
  -D HOME=$HOME \
  /​path/​to/​application

References

More skills from trailofbits

supply-chain-risk-auditor logo
trailofbits/skills

supply-chain-risk-auditor

Identifies dependencies at heightened risk of exploitation or takeover. Use when assessing supply chain attack surface, evaluating dependency health, or scoping security engagements.

7.4K 7.3K
View
secure-workflow-guide logo
trailofbits/skills

secure-workflow-guide

Guides through Trail of Bits' 5-step secure development workflow. Runs Slither scans, checks special features (upgradeability/ERC conformance/token integration), generates visual security diagrams, helps document security properties for fuzzing/verification, and reviews manual security areas.

7.4K 7K
View
code-maturity-assessor logo
trailofbits/skills

code-maturity-assessor

Systematic code maturity assessment using Trail of Bits' 9-category framework. Analyzes codebase for arithmetic safety, auditing practices, access controls, complexity, decentralization, documentation, MEV risks, low-level code, and testing. Produces professional scorecard with evidence-based rat...

7.4K 6.7K
View
insecure-defaults logo
trailofbits/skills

insecure-defaults

Detects fail-open insecure defaults (hardcoded secrets, weak auth, permissive security) that allow apps to run insecurely in production. Use when auditing security, reviewing config management, or analyzing environment variable handling.

7.4K 6.5K
View
fp-check logo
trailofbits/skills

fp-check

Systematically verifies suspected security bugs to eliminate false positives. Produces TRUE POSITIVE or FALSE POSITIVE verdicts with documented evidence for each bug.

7.4K 6.4K
View
agentic-actions-auditor logo
trailofbits/skills

agentic-actions-auditor

Audits GitHub Actions workflows for security vulnerabilities in AI agent integrations including Claude Code Action, Gemini CLI, OpenAI Codex, and GitHub AI Inference. Detects attack vectors where attacker-controlled input reaches AI agents running in CI/CD pipelines, including env var intermediar...

7.4K 6.3K
View
Property-Based Testing logo
trailofbits/skills

Property-Based Testing

Property-based testing for multiple languages and smart contracts.

7.4K 6.2K
View
audit-context-building logo
trailofbits/skills

audit-context-building

Enables ultra-granular, line-by-line code analysis to build deep architectural context before vulnerability or bug finding.

7.4K 6.2K
View
sharp-edges logo
trailofbits/skills

sharp-edges

Identifies error-prone APIs, dangerous configurations, and footgun designs that enable security mistakes. Use when reviewing API designs, configuration schemas, cryptographic library ergonomics, or evaluating whether code follows 'secure by default' and 'pit of success' principles. Triggers: foot...

7.4K 6.1K
View
Variant Analysis logo
trailofbits/skills

Variant Analysis

Find similar vulnerabilities across codebases via pattern-based analysis.

7.4K 5.8K
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View