Skip to main content
coreydaley.dev
Docs menu

Make a Mac app work in the App Sandbox

What the Mac App Sandbox blocks, which entitlements you need, and each failure's cause and fix, from building Purrchiver, a file-heavy archive app.

A sandboxed Mac app can use its own container and whatever the person hands it, and little else. Most of the work is one idea: a grant covers what was picked, not the folder around it. Several of the sandbox bugs in Purrchiver’s history come down to that.

You probably need fewer entitlements than you think. Apple requires the sandbox for the App Store. Purrchiver reads and writes archives wherever the person points it with two entitlements, and its Quick Look extension has one. I read these from the App Store build of Purrchiver 1.1, on macOS 27.2:

TargetSandbox entitlements in the signed build
Purrchiver.appcom.apple.security.app-sandbox, com.apple.security.files.user-selected.read-write
Quick Look extensioncom.apple.security.app-sandbox

It has no network entitlement, though it sells an in-app unlock through StoreKit. It has no Downloads entitlement, no bookmark entitlement and no Hardened Runtime exceptions.

This guide is for developers. If you’re looking at a prompt on your own Mac, you want Mac permissions instead.

Xcode's App Sandbox capability with User Selected File set to Read/Write

Find your symptom

What you seeCauseFix
Writing next to a picked or dropped file fails (“Failed to open … for writing”, or EPERM)The grant covers the file, not its folderAsk with a Save panel, or use a related item
The other parts of a split file can’t be readOnly the part they picked was grantedAsk for the folder
Work beside a Save panel’s file fails, though the panel succeededA Save panel grants the name it returns, not the folderWork in temp, then copy to that name
Writing photos.zip.sha256 was refused in Purrchiver, photos.sha256 wasn’tOne measurement in this app, on macOS 27: the written name that worked kept the file’s name and changed only the extensionReplace the extension
A related item with a good name is refusedCheck the declaration: role None was refused in one measurement in this appDeclare it, with role Editor
It works in your tests and fails for peopleThe test files sit in the app’s own containerTest from outside it, through a real panel
A saved path, or a restored window, stops working after a relaunchA path doesn’t carry a grantStore a bookmark, or ask again
A bookmark resolves but the file can’t be readResolving doesn’t start accessCall start, then stop
After a long run, panels and bookmarks stop adding accessLeaked access; a relaunch clears itBalance every start with a stop
hdiutil attach fails with “Device not configured”A sandboxed app can’t mount a disk imageUse a command that doesn’t mount
An embedded tool crashes at launch with a code signing errorThe tool has other entitlements tooSign it with only the two Apple lists
App Review rejects under 2.4.5(i), and your output is in your containerOutput sits where nobody can reach itHand back data, and delete the temp copy
Quick Look previews leave files behindThe extension can be killed mid-previewSweep on the next preview
The project looks clean, the signed app has an extra capabilityA build setting added itRead the signed app
EPERM or EACCES, and no denial in the logProbably not the sandbox, if you searched right after reproducing itCheck the other causes

In this guide

What went wrong along the way

  • The code assumed a parent folder came with the file. Create Archive used to build its output path next to a dragged-in file, and failed for anyone who did that. A later change said extracting beside an archive was fine because the parent was “inside the scope”. It isn’t when one file was picked. Decompress and Decrypt had the same bug until shortly before 1.1.
  • App Review rejected 1.0 under guideline 2.4.5(i). My notes on it point to Shortcuts actions that returned files from the sandbox’s temp folder, which stayed in the container.
  • My tests passed where the limit doesn’t apply. Fixtures in the app’s own container said nothing about a file in Downloads.
  • The conventional checksum name didn’t work for writing. A probe in this app refused it, and that’s why Purrchiver writes the shorter name. The related items page says how far that evidence goes.

What I tested, and what I didn’t

On a Mac with macOS 27.2 and Xcode 27.2, I ran codesign and plutil against the installed App Store build of Purrchiver 1.1 (build 116), ran the log predicates against real denials from other apps on that Mac, and type-checked the Swift on these pages with swiftc -typecheck.

I didn’t run a sandboxed test program for this guide. The first launch of one creates a container in ~/Library/Containers, and I wanted these tests to leave nothing behind. Panel behavior needs a real panel too. So anything about what the sandbox allows or refuses comes from Apple’s documentation, or from Purrchiver’s code, tests and commit history, and each page says which. Everything from Purrchiver here shipped by 1.1; the 1.1.1 changes since then don’t touch sandbox behavior.