All posts
Guide

“Command PhaseScriptExecution failed with a nonzero exit code”: how to fix it

How to find the real error behind Xcode’s PhaseScriptExecution failure, then fix it by cause: script sandboxing, CocoaPods, Node for React Native, Flutter, Crashlytics.

By the Renameproof team · · 7 min read

Your build or archive stops with “Command PhaseScriptExecution failed with a nonzero exit code”. That line is only a summary. It means one of the target’s Run Script build phases ended with an error, and the script printed the real reason a few lines above it in the build log. Every fix depends on which script failed and what it said, so read that first instead of trying fixes at random.

Why it happens

Xcode runs each Run Script phase as a shell script. If the script exits with any code other than 0, Xcode reports this generic error. Projects made with CocoaPods, React Native, Expo, Flutter or Firebase all add their own scripts, so the usual culprits are:

  • Script sandboxing. With User Script Sandboxing on, a script can only touch files it declares as inputs and outputs. CocoaPods’ framework-embedding script and other tools that copy files with rsync get blocked.
  • CocoaPods is out of sync. The “[CP] Check Pods Manifest.lock” phase fails when Podfile.lock and the installed Pods don’t match.
  • React Native can’t find Node. The “Bundle React Native code and images” phase runs Node, and Xcode doesn’t load your terminal’s PATH or version manager.
  • The JavaScript bundle fails. A syntax error or missing import in your JS code fails the same React Native phase, even though nothing is wrong with Xcode.
  • Flutter’s build script fails. The “Run Script” and “Thin Binary” phases call Flutter’s xcode_backend.sh, which fails if Flutter’s generated files are stale or missing.
  • A crash-reporting upload script fails. The Crashlytics dSYM script needs its input files declared when sandboxing is on.
  • A custom script fails, for example because the file isn’t executable or a tool it calls isn’t installed on this Mac or CI runner.

Step 1: find the real error

  1. In the Issue navigator, click the PhaseScriptExecution error. Xcode usually opens the Report navigator (View → Navigators → Reports) with the right build and step selected.
  2. If it doesn’t, open the Report navigator yourself, pick the latest build, and use the All Messages filter so script output isn’t hidden.
  3. Find the failed step. It’s named after the build phase, such as “[CP] Embed Pods Frameworks”, “Bundle React Native code and images”, “Run Script” or “Thin Binary”.
  4. Select it and choose Editor → Expand Selected Transcripts. The last lines before the exit are the real error.
  5. To share or search the whole log, click Export at the top of the report. That saves the transcript of every step as a text file.
  6. On the command line or CI, scroll up from the error in the xcodebuild output to the PhaseScriptExecution block. For Flutter, flutter build ios --verbose prints more detail.

Match the error to the cause

What the transcript showsCauseFix
Sandbox: rsync(<pid>) deny(1) file-write-create <path> (or rsync.samba)User Script Sandboxing blocks a copy scriptSet User Script Sandboxing to No, or declare the script’s inputs and outputs
The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.Pods not installed or out of dateRun pod install in the ios folder and open the .xcworkspace
A warning that you need to configure your node path in .xcode.env, or node not foundXcode can’t find Node (React Native, Expo)Set NODE_BINARY in ios/.xcode.env or ios/.xcode.env.local
A Metro or JavaScript error (SyntaxError, Unable to resolve module)Your JS code doesn’t bundleFix the JS error it names; Xcode is fine
An error from xcode_backend.sh, or a missing Generated.xcconfigFlutter’s generated files are staleflutter clean, flutter pub get, pod install, then build again
Output from the Crashlytics run script, often with a sandbox denydSYM upload script can’t read its filesAdd the Input Files Firebase lists, keep it the last phase
Permission denied on a .sh fileThe script isn’t executablechmod +x on that script, then commit the change

How to fix each cause

Sandbox: rsync deny (User Script Sandboxing)

Xcode 14 added the ENABLE_USER_SCRIPT_SANDBOXING build setting. When it’s on, a Run Script phase that reads or writes a file it hasn’t declared fails with a sandbox violation. Projects created with Xcode 15 or later turn it on, and accepting Xcode’s “Update to recommended settings” can turn it on in older projects. Scripts that copy frameworks with rsync, like CocoaPods’ embed phase, then fail.

  1. Select the app target, open Build Settings → All, and search for User Script Sandboxing.
  2. Set it to No for the app target. Check the project level too, so nothing sets it back to Yes.
  3. Clean the build folder (Product → Clean Build Folder) and build again.
  4. Still failing? Tick Show environment variables in build log on the failing script phase, build, and check the value of ENABLE_USER_SCRIPT_SANDBOXING in the transcript. If it still says YES, it’s being set somewhere else.
  5. If you’d rather keep sandboxing on, list every file the script reads under Input Files and every file it writes under Output Files. That’s the approach Apple recommends, but it only works for scripts you control.

New Flutter projects already ship with User Script Sandboxing set to No in the Runner target, and Flutter’s add-to-app guide asks you to set it to No when Xcode rebuilds your Flutter code.

CocoaPods out of sync

  1. In a terminal, go to the folder with your Podfile (ios/ for React Native and Flutter) and run pod install.
  2. Always open the .xcworkspace, not the .xcodeproj. Building the project file alone skips the Pods.
  3. If pod install itself fails, update CocoaPods first. If the error persists, delete the Pods folder and Podfile.lock only as a last resort, since that can change pod versions.

React Native or Expo can’t find Node

Since React Native 0.69, the build phases read the Node path from the NODE_BINARY variable in ios/.xcode.env. The build script also reads ios/.xcode.env.local if it exists, which is the place for paths that differ per machine. Run command -v node in your terminal and put the result in one of those files, for example export NODE_BINARY=/opt/homebrew/bin/node. If you use nvm, React Native’s docs suggest moving the nvm setup from ~/.zshrc to ~/.zshenv so Xcode picks it up.

Flutter’s build script fails

  1. Run flutter clean, then flutter pub get. That regenerates ios/Flutter/Generated.xcconfig, which holds the Flutter SDK path the scripts use.
  2. In ios/, run pod install.
  3. Build once from the terminal with flutter build ios (or flutter build ipa). If that fails, its message is clearer than Xcode’s.
  4. If the transcript shows a rsync sandbox deny, check User Script Sandboxing on the Runner target as above.

Crashlytics upload script

Firebase’s setup puts the Crashlytics run script last in Build Phases. With User Script Sandboxing on, the script can only read what’s in its Input Files list, so copy the full list from Firebase’s Crashlytics guide: the dSYM folder, its DWARF binary and Info.plist, the app’s GoogleService-Info.plist and the executable. If you also use ENABLE_DEBUG_DYLIB, Firebase lists one more path for the debug dylib.

Project typePhase that usually failsFirst thing to check
Native Xcode with CocoaPods[CP] Check Pods Manifest.lock, [CP] Embed Pods Frameworkspod install, then User Script Sandboxing
React Native (bare)Bundle React Native code and imagesNODE_BINARY in ios/.xcode.env, then any JS error
Expo (prebuild or EAS Build)Bundle React Native code and imagesSame as React Native; on EAS, open the Xcode logs in the build page
FlutterRun Script, Thin Binaryflutter clean and flutter pub get, then pod install
Any app with CrashlyticsThe Crashlytics run scriptInput Files list and phase order

Questions people ask

Is it safe to turn off User Script Sandboxing?

It removes a build-time safety check, not anything in your shipped app. Apple recommends keeping it on and declaring inputs and outputs, but for third-party scripts you can’t change, turning it off on the app target is the usual fix.

Why does it build in Debug but fail when I archive?

Some scripts only run for Release builds. React Native, for example, bundles the JavaScript into the app for Release, so a JS error or Node path problem only shows up when you archive.

Does deleting DerivedData fix it?

Sometimes, when a stale file confuses a script. But it doesn’t fix sandboxing, Node path or Pods errors, so read the transcript first.

What is “error 65” in React Native?

It’s xcodebuild’s exit code for a failed build, which the React Native CLI passes on. The real cause is in the Xcode log, often this same PhaseScriptExecution failure.

Sources

  1. Apple: Build settings reference (User Script Sandboxing)
  2. Apple: Xcode 14 release notes (script sandboxing)
  3. Apple Developer Forums: Command failed with a nonzero exit code (finding the build transcript)
  4. Apple Developer Forums: Sandbox rsync.samba deny (checking the setting in the build log)
  5. Xcode Help: View and filter logs and reports
  6. React Native: Set up your environment (.xcode.env)
  7. Flutter: Add Flutter to an existing iOS app
  8. Firebase: Get started with Crashlytics (Apple platforms)

Check your own name

Domains, both app stores, bundle IDs and every live site using the name, in under a minute.

Check a name

Keep reading

“Multiple commands produce ‘<path>’” in Xcode: how to fix it

Read the two numbered lines under Xcode’s “Multiple commands produce” error to find the cause: Info.plist, duplicate resources, privacy manifests or Pods.

November 27, 2026 · 5 min read

“No profiles for ‘<bundle-id>’ were found”: how to fix it

Why Xcode or xcodebuild can’t find a provisioning profile for your bundle ID, and how to fix it with automatic signing, -allowProvisioningUpdates or a manual profile.

November 27, 2026 · 5 min read
“Command PhaseScriptExecution failed with a nonzero exit code”: how to fix it