5

In my XCode project, I have a Python script I'm running as one of my build phases. However, it's failing to open a file with the error:

Sandbox: Python(22805) deny(1) file-read-data <file_name>

How can I give Xcode/Python permission to read this file?

6
  • Do you know the path to the file? Have you inspected the full disk access tab pf system preferences? Those two items might give us a clue where to start on the OS side of things without needing to try to run the script from the command line.
    – bmike
    Commented Oct 17, 2023 at 16:17
  • I know the path. How do I check those preferences? Commented Oct 17, 2023 at 16:18
  • 1
    I’ll see if I can answer more specific than this summary link. support.apple.com/guide/security/…
    – bmike
    Commented Oct 17, 2023 at 16:21
  • Also, is it feasible to run only the python script from terminal app? If so let’s see that as an edit here please.
    – bmike
    Commented Oct 17, 2023 at 16:42
  • 1
    Wow - that’s a very promising sign. For sure clean the project often as you triage this. Please edit my answer or make your own if you learn something good here!
    – bmike
    Commented Oct 17, 2023 at 16:51

2 Answers 2

9

Well, I'm not sure how this option got set but User Script Sandboxing was turned on in MyTarget > Build Settings > Build Options. Turning it off fixed the issue.

Screenshot of the Build Options in Xcode with the 'User Script Sandboxing' turned off

1
  • 1
    Very nice catch!
    – bmike
    Commented Oct 17, 2023 at 18:02
0

I would probably give Xcode full disk access to simplify things settings wise

Open System Settings and search for “Full Disk Access”

  • select the +
  • Use Touch ID or your password or other admin auth step to unlock the change
  • find Xcode and “open” it
  • Retest and quit Xcode if needed
  • Clean the project inside Xcode (Go to Product -> Clean)

You might need to add terminal.app if that’s forged to execute the python script in the background.

Of course, your script needs to be executable with chmod or choosing a shell path and script to execute the python script.

4
  • Does the Python interpreter need access as well? Commented Oct 17, 2023 at 16:32
  • Probably not @DanielWalker but you could add that explicitly and delete it later. All the shells should inherit permissions if you add terminal.app (which you’ll likely need to test and debug your scripts there) so I presume python would piggyback off Xcode or terminal since they launch the script.
    – bmike
    Commented Oct 17, 2023 at 16:35
  • I gave both the terminal and Xcode full disk access and restarted both. Same error. Commented Oct 17, 2023 at 16:37
  • Hmm - hopefully we don’t need to get into your build targets and such. Can you upload these changed screen shots to the question and let others see the problem? Which file or dialog shows the error message? Including a little more detail there might help…
    – bmike
    Commented Oct 17, 2023 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .