Fix "Command PhaseScriptExecution failed with a nonzero exit code" in Xcode
Command PhaseScriptExecution failed with a nonzero exit code
- error: Command PhaseScriptExecution failed with a nonzero exit code (in target 'Runner' from project 'Runner')
- Sandbox: rsync.samba(13105) deny(1) file-write-create /Users/me/Library/Developer/Xcode/DerivedData/App/Build/Products/Debug-iphonesimulator/App.app/Frameworks/Alamofire.framework
- error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
- Run script build phase 'Bundle React Native code and images' : Command PhaseScriptExecution failed with a nonzero exit code
- Showing Recent Messages: Command PhaseScriptExecution failed with a nonzero exit code
A "Run Script" phase of the Xcode build (CocoaPods, React Native, Flutter…) exited with an error. This message is only the summary: open the full log of the phase in the Report navigator to read the real error, then fix it (often pod install, node not found or script sandboxing).
What this error means
An iOS project contains "Run Script" build phases: [CP] Check Pods Manifest.lock and [CP] Embed Pods Frameworks added by CocoaPods, Bundle React Native code and images for React Native, a Run Script calling xcode_backend.sh for Flutter, or your own scripts (SwiftLint, Crashlytics…). Xcode runs each one in a non-interactive shell; if the script returns an exit code other than 0, Xcode stops the build with this generic message. The real cause is always a few lines above, in the script output: command not found, missing file, access denied by the sandbox, Pods out of sync.
Common causes
- Pods out of sync:
Podfile.lockchanged (pull, branch switch, new dependency) withoutpod install, or you opened the.xcodeprojinstead of the.xcworkspace. nodenot found (React Native, Expo): Xcode does not load your.zshrc, so a Node installed with nvm, fnm or Volta is not in itsPATH.- Script sandboxing (
ENABLE_USER_SCRIPT_SANDBOXING, on by default in projects created with Xcode 15 or later): the script is not allowed to read or write an undeclared file, hence lines likeSandbox: rsync(…) deny(1) file-write-create. - Flutter not prepared:
ios/Flutter/Generated.xcconfigmissing or pointing to an old SDK path, becauseflutter pub getwas not run after a clone or a move. - Your own script fails: file not executable (
Permission denied), CRLF line endings, missing tool (SwiftLint), or a JavaScript error while building the bundle.
Step-by-step fix
-
Read the real error message
In Xcode, open the Report navigator (Cmd+9), select the last build, click the failing line then the details icon to expand the script output. You can also run the build in a terminal and read the last lines.
cd ios xcodebuild -workspace App.xcworkspace -scheme App -configuration Debug -sdk iphonesimulator build 2>&1 | grep -B 20 "PhaseScriptExecution failed" -
Resync CocoaPods
If the log mentions
Podfile.lockor[CP], reinstall the Pods, then always open the.xcworkspacefile. With aGemfile, preferbundle exec pod install.cd ios pod install --repo-update open App.xcworkspace -
React Native: tell Xcode where node is
Since React Native 0.69, the scripts read
NODE_BINARYfromios/.xcode.env, andios/.xcode.env.local(not committed) can override it. Write the path of your Node into it, from a terminal wherenodeworks.cd ios echo "export NODE_BINARY=$(command -v node)" > .xcode.env.local cat .xcode.env.local -
Flutter: regenerate the iOS configuration
The Flutter script needs
Generated.xcconfig, created byflutter pub get. Clean and regenerate everything, then build again.flutter clean flutter pub get cd ios && pod install && cd .. flutter build ios --debug --no-codesign -
"Sandbox: … deny(1)" lines: handle script sandboxing
The proper fix is to declare the files read and written in the Input Files and Output Files of the phase, and to update CocoaPods (
gem install cocoapods). If a third-party script does not allow it, set User Script Sandboxing to No in Build Settings, for the affected target only: your scripts will then be able to access your whole user folder during the build.// Build Settings > Build Options > User Script Sandboxing ENABLE_USER_SCRIPT_SANDBOXING = NO -
Your own script: make it executable and test it
If the log shows
Permission deniedorcommand not found, make the script executable, convert its line endings to LF and use absolute paths for tools (Homebrew lives in/opt/homebrew/binon Apple silicon Macs).chmod +x scripts/build-phase.sh export PATH="/opt/homebrew/bin:$PATH" bash -x scripts/build-phase.sh -
Clear derived data
If the error persists after the fix, run Product > Clean Build Folder (Shift+Cmd+K), or delete the build cache. These folders are regenerated on the next build.
rm -rf ~/Library/Developer/Xcode/DerivedData/*
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Run
pod install(ornpx pod-install) after everygit pullthat changesPodfile.lock, and always open the.xcworkspace. - Commit
ios/.xcode.envwithexport NODE_BINARY=$(command -v node)and let each developer adapt.xcode.env.local. - In your build scripts, start with
set -euo pipefailand print clear messages: the real error will be easier to spot in the log.
Frequently asked questions
Where can I see the details of "PhaseScriptExecution failed"?
In the Report navigator (Cmd+9): select the build, then the failing phase line, and expand its output. The useful line is just before "Command PhaseScriptExecution failed".
Why does it work in the terminal but not in Xcode?
Xcode runs scripts without loading your shell profile: tools added to PATH by nvm, Homebrew or asdf in .zshrc are invisible. Use absolute paths, or NODE_BINARY for React Native.
Should I disable ENABLE_USER_SCRIPT_SANDBOXING?
Only if the Sandbox: … deny(1) lines show it and a third-party script does not declare its files. Keep it on when you can: it stops a compromised script from accessing your files during the build.
Useful tools for this error
More Mobile (Android, iOS) errors
- Fix "SDK location not found" (ANDROID_HOME / sdk.dir) on Android
- Fix "CocoaPods could not find compatible versions for pod" on iOS
- Fix "Unable to load script" (index.android.bundle) in React Native
- Fix "Signing for "App" requires a development team" in Xcode
- Fix "INSTALL_FAILED_UPDATE_INCOMPATIBLE: signatures do not match" on Android
- Fix "Duplicate class ... found in modules" in an Android Gradle build
- Fix "cmdline-tools component is missing" and "Android license status unknown" (flutter doctor)
- Fix "Invariant Violation: "main" has not been registered" (React Native / Expo)