在macOS中默认配置App Sandbox,对于第三方CLI工具则必须配置App Sandbox,否则无法上传到App Store Connect。
App Sandbox的相关知识和权限可以查看《macOS管理App Sandbox权限》。
本文介绍的App Sandbox权限通常为手动配置到 .entitlements文件或 entitlements.plist文件的字段。

下面是沙盒中最常见的 entitlement 列表:
1、App 基础沙盒权限
com.apple.security.app-sandbox:开启 App Sandbox(主开关);
com.apple.security.inherit:子进程继承父进程的沙盒权限(只用于子进程)。
2、文件系统访问
com.apple.security.files.user-selected.read-only:允许读取用户选择的文件(例如通过 NSOpenPanel);
com.apple.security.files.user-selected.read-write:允许读写用户选择的文件;
com.apple.security.files.downloads.read-only:访问 ~/Downloads,只读;
com.apple.security.files.downloads.read-write:访问 ~/Downloads,可写;
com.apple.security.files.documents.read-only:访问 ~/Documents,只读;
com.apple.security.files.documents.read-write:访问 ~/Documents,可写;
com.apple.security.files.all:访问所有文件(高权限,不推荐);
com.apple.security.files.home-relative-path.read-only:指定访问 home 子路径(只读);
com.apple.security.files.absolute-path.read-only:指定绝对路径访问(只读);
com.apple.security.temporary-exception.files.absolute-path.read-only:允许访问临时例外路径(比如 /tmp)。
3、网络访问
com.apple.security.network.client:允许进行出站网络连接;
com.apple.security.network.server:允许作为服务器监听端口(入站)。
4、图形界面相关
com.apple.security.print:允许打印;
com.apple.security.device.audio-input:允许访问麦克风;
com.apple.security.device.camera:允许访问摄像头;
com.apple.security.device.usb:访问 USB 设备(仅部分 API 支持)。
5、Keychain / 加密相关
keychain-access-groups:允许访问 Keychain 的特定组(用于共享钥匙串)。
6、App Group(数据共享)
com.apple.security.application-groups:允许 App 和其扩展使用共享容器(App Group)。
7、临时例外(不推荐用于发布)
com.apple.security.temporary-exception.files.absolute-path.read-only:临时允许读取指定绝对路径(如 /tmp/xxx);
com.apple.security.temporary-exception.shared-preference.read-only:读取特定偏好设置(如 plist);
com.apple.security.temporary-exception.mach-lookup.global-name:与其他服务通信(如通信桥)。
临时例外类 entitlements 在 App Store 审核中几乎必被拒绝,仅供调试/内部使用。
总结
主应用和外部二进制文件,都必须配置com.apple.security.app-sandbox,否则无法上传到App Store Connect,在Xcode16中主应用默认配置App Sandbox。
对于CLI工具,如果想要访问文件系统和路径等信息,必须配置com.apple.security.inherit,否则就是独立的沙盒环境,无法访问其他的信息。
相关文章
1、How to sandbox a command line tool?:https://stackoverflow.com/questions/12959958/how-to-sandbox-a-command-line-tool
2、macOS管理App Sandbox权限:https://fangjunyu.com/2025/06/20/macos%e7%ae%a1%e7%90%86app-sandbox%e6%9d%83%e9%99%90/
3、macOS App Sandbox和Hardened Runtime的关系:https://fangjunyu.com/2025/06/22/macos-app-sandbox%e5%92%8chardened-runtime%e7%9a%84%e5%85%b3%e7%b3%bb/
4、macOS启用App Sanbox后CLI工具无法访问路径的问题:https://fangjunyu.com/2025/07/17/macos%e5%90%af%e7%94%a8app-sanbox%e5%90%8ecli%e5%b7%a5%e5%85%b7%e6%97%a0%e6%b3%95%e8%ae%bf%e9%97%ae%e8%b7%af%e5%be%84%e7%9a%84%e9%97%ae%e9%a2%98/
5、Xcode打包报错:App sandbox not enabled. The following executables must include the “com.apple.security.app-sandbox” entitlement with a Boolean value of true in the entitlements property list:https://fangjunyu.com/2025/07/17/xcode%e6%89%93%e5%8c%85%e6%8a%a5%e9%94%99%ef%bc%9aapp-sandbox-not-enabled-the-following-executables-must-include-the-com-apple-security-app-sandbox-entitlement-with-a-boolean-value-of-true-in-the/
6、Xcode创建entitlements.plist配置文件:https://fangjunyu.com/2025/07/17/xcode%e5%88%9b%e5%bb%baentitlements-plist%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6/