Git command run within the app

Hi, I'm working on an app that uses git command. When I enabled sandbox, it works when the app is run within Xcode. When I run the app manually, it shows error:


xcrun: error: cannot be used within an App Sandbox.


Here is sample code to reproduce the problem:


let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = ["git", "--version"]


let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
task.waitUntilExit()


let data = pipe.fileHandleForReading.readDataToEndOfFile()


let alert = NSAlert()
if let output = String(data: data, encoding: .utf8) {
    alert.messageText = output
} else {
    alert.messageText = "***"
}
alert.runModal()

Replies

The

/usr/bin/git
tool is actually a trampoline that bounces to the version of
git
embedded in the Xcode selected via
xcode-select
. That trampoline does not work inside a sandbox.

Are you sandboxing the app in order to ship it via the Mac App Store? If so, I recommend that you build your own version from source and include that built version within your app.

IMPORTANT Whenever you use third-party code like this, it’s important to consider the licence under which it’s distributed.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"