I am looking for more information on how macOS Swift Playgrounds handle sandboxing. I'd like to test how some macOS code runs inside a sandbox, but from what I'm seeing, the Playground isn't sandboxed, at least for macOS.
https://stackoverflow.com/a/38987133/2778502 says that iOS playgrounds are sandboxed, as you'd expect.
However, the following suggests macOS playgrounds are also sandboxed: https://stackoverflow.com/a/31087421/2778502
To test this, I created a new Swift macOS playground in Xcode 9.2 and put the following code into it. It's basically checking the "reachability" and readability of /etc/hosts
. I chose that file just because I wanted one that I knew should not be accessible from a sandboxed MacOS app.
//: Playground - noun: a place where people can play
import Cocoa
var directory = URL(fileURLWithPath: "/etc/hosts")
do {
if try directory.checkResourceIsReachable() {
print("file URL \(directory) is reachable")
}
else {
print("file URL \(directory) returned false")
}
} catch {
print("file URL threw error: \(error)")
}
var isReadableFile = FileManager.default.isReadableFile(atPath: "/etc/hosts")
Swift tells me the file URL is reachable, and isReadableFile
is true
ie no sandbox is in play.
So my questions are:
- am I correct in thinking sandboxing is in effect for iOS playgrounds but not macOS playgrounds?
- is it possible to turn on sandboxing for a macOS playground?