2

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?
mahal tertin
  • 3,239
  • 24
  • 41
jeff-h
  • 2,184
  • 1
  • 22
  • 33
  • 4
    Is there something that makes you expect OS X playgrounds code to be sandboxed? – pvg Jan 01 '18 at 10:34
  • 3
    What you are saying doesn't make sense. When you specify a file path that the user doesn't choose with NSOpenPanel, you revoke the sandbox scheme. – El Tomato Jan 01 '18 at 11:08
  • lol sorry for the ambiguity — maybe I shouldn't post at midnight! Clarifying now. – jeff-h Jan 01 '18 at 20:19

0 Answers0