Skip to content
  1. LuzineDebug
  2. Mobile (Android, iOS)
  3. Command PhaseScriptExecution failed with a nonze…
Mobile (Android, iOS) Intermediate ≈ 15 min to fix

Fix "Command PhaseScriptExecution failed with a nonzero exit code" in Xcode

Error message
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
In short

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).

Be the first to confirm this fix

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

  1. Pods out of sync: Podfile.lock changed (pull, branch switch, new dependency) without pod install, or you opened the .xcodeproj instead of the .xcworkspace.
  2. node not found (React Native, Expo): Xcode does not load your .zshrc, so a Node installed with nvm, fnm or Volta is not in its PATH.
  3. 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 like Sandbox: rsync(…) deny(1) file-write-create.
  4. Flutter not prepared: ios/Flutter/Generated.xcconfig missing or pointing to an old SDK path, because flutter pub get was not run after a clone or a move.
  5. 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

  1. 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.

    bash
    cd ios
    xcodebuild -workspace App.xcworkspace -scheme App -configuration Debug -sdk iphonesimulator build 2>&1 | grep -B 20 "PhaseScriptExecution failed"
  2. Resync CocoaPods

    If the log mentions Podfile.lock or [CP], reinstall the Pods, then always open the .xcworkspace file. With a Gemfile, prefer bundle exec pod install.

    bash
    cd ios
    pod install --repo-update
    open App.xcworkspace
  3. React Native: tell Xcode where node is

    Since React Native 0.69, the scripts read NODE_BINARY from ios/.xcode.env, and ios/.xcode.env.local (not committed) can override it. Write the path of your Node into it, from a terminal where node works.

    bash
    cd ios
    echo "export NODE_BINARY=$(command -v node)" > .xcode.env.local
    cat .xcode.env.local
  4. Flutter: regenerate the iOS configuration

    The Flutter script needs Generated.xcconfig, created by flutter pub get. Clean and regenerate everything, then build again.

    bash
    flutter clean
    flutter pub get
    cd ios && pod install && cd ..
    flutter build ios --debug --no-codesign
  5. "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.

    plaintext
    // Build Settings > Build Options > User Script Sandboxing
    ENABLE_USER_SCRIPT_SANDBOXING = NO
  6. Your own script: make it executable and test it

    If the log shows Permission denied or command not found, make the script executable, convert its line endings to LF and use absolute paths for tools (Homebrew lives in /opt/homebrew/bin on Apple silicon Macs).

    bash
    chmod +x scripts/build-phase.sh
    export PATH="/opt/homebrew/bin:$PATH"
    bash -x scripts/build-phase.sh
  7. 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.

    bash
    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 (or npx pod-install) after every git pull that changes Podfile.lock, and always open the .xcworkspace.
  • Commit ios/.xcode.env with export NODE_BINARY=$(command -v node) and let each developer adapt .xcode.env.local.
  • In your build scripts, start with set -euo pipefail and 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

All Mobile (Android, iOS) errors →