Technical Q&A QA1888

Sandboxing and Automation in OS X

Q:  How does sandboxing affect my scriptable app, AppleScript app, or Automator action in OS X?

A: As explained in App Sandbox Design Guide, a non-sandboxed app has the full rights of the user who is running that app and can access any resources that the user can access. If that app or the frameworks it is linked against contain security holes, an attacker can potentially exploit those holes to take control of that app. In doing so, the attacker gains the ability to do anything that the user can do.

A sandboxed app, on the other hand, has limited access to resources. Instead of having free rein of the OS, a sandboxed app must request entitlements for the resources it needs. See Entitlement Key Reference. By limiting access to resources in this manner, App Sandbox provides a last line of defense against the theft, corruption, or deletion of user data if an attacker successfully exploits security holes in your app or the frameworks it is linked against.

Because sandboxing limits interaction with files and folders and between apps in OS X, there are certain impacts on automation-related apps, such as scriptable apps, AppleScript apps, and Automator actions.

Sandboxing OS X Apps, Including Scriptable Apps and AppleScript Apps

Requirements

For security reasons, Apple encourages all developers to sandbox their apps. Sandboxing is a requirement if you intend to distribute your app via the Mac App Store.

Restrictions

Currently, when you adopt sandboxing in an app, your app retains the ability to:

  • Receive Apple events

  • Send Apple events to itself

  • Respond to Apple events it receives

Your app cannot, however, send Apple events to other apps unless you request a scripting-targets entitlement or an apple-events temporary exception entitlement. In the same way, regardless of whether your app is sandboxed, any external sandboxed app that attempts to interact with your app must also request the appropriate entitlements to do so.

About scripting-targets entitlements

A scripting-targets entitlement is a request to access a specific subset of scripting terminology, known as an access group, in the target app. For example, your app might create messages in Mail. In this situation, your app would request an entitlement for the compose access group in Mail. Scripting-targets entitlements provides the OS with fine-grained knowledge of the inter-application tasks your app is supposed to perform. This ensures that your app does only what the user expects, and isn’t being exploited by an attacker for some malicious function. For more information on scripting-targets entitlements, see Enabling Scripting of Other Apps in Entitlement Key Reference.

About apple-events temporary exception entitlements

An apple-events temporary exception entitlement is needed when an app doesn’t implement the necessary access groups for the scripting terminology your app needs to use. Note that this type of entitlement is intended to be temporary, and your app should not plan to use it indefinitely. If an Apple app doesn’t implement the access groups you need, you should file a bug report indicating that you need this support. If the app is a third-party app, you should contact the developer and request that they implement this support in a future version of their app. For more information about apple-events temporary exception entitlements, see Apple Event Temporary Exception in Entitlement Key Reference.

Sandboxing Automator Actions

Automator actions are plug-in bundles that are loaded and run by Automator and the OS. Automator actions can be installed into /Library/Automator/ and ~/Library/Automator/. If you’re an app developer, actions can also be embedded into the /Contents/Library/Automator/ directory within your app bundle. Regardless of where your action is installed and whether your app itself is sandboxed, the action runs within the context of the app that loads it. When actions are loaded and run by Automator or the OS, they are run outside of a sandbox, and can access any file, folder, or app that the user can access.

Best Practices for Submitting Scriptable and AppleScript Apps to the Mac App Store

General Sandboxing Resources

Sandboxing Resources for Automation



Document Revision History


DateNotes
2015-05-23

Updated link to App Sandboxing FAQ document.

2015-02-05

New document that provides information about how sandboxing affects a scriptable app, AppleScript app, or Automator action in OS X.