Xcode says a script phase failed, but not which one or why
Command PhaseScriptExecution failed with a nonzero exit codeShort answer
This line only reports that one Run Script build phase exited with an error. The phase name after PhaseScriptExecution says which script, and the lines printed just above it say why. In Flutter and CocoaPods projects the usual culprits are an out-of-sync Podfile.lock, user script sandboxing, a stale Flutter SDK path, or a Dart build error.
Fix it fast
1Find out which cause you have
Build from the terminal so the whole script output is kept, and print the lines just before the failure. The name in the PhaseScriptExecution line (for example Run Script, Thin Binary or [CP] Check Pods Manifest.lock) tells you which phase failed; the lines above it are that script's own message.
flutter build ios --no-codesign -v 2>&1 | grep -n -B25 "PhaseScriptExecution failed"2Match what you see, then jump to its fix
- 1
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.[CP] Check Pods Manifest.lock: the Pods folder does not match Podfile.lockFix - 2
Sandbox: … deny(1) file-read-data or file-write-create on a path in your project or DerivedData, printed by a Run Script or [CP] Embed Pods Frameworks phaseUser script sandboxing blocks a script from reading or writing a fileFix - 3
…/packages/flutter_tools/bin/xcode_backend.sh: No such file or directory, often right after moving or reinstalling the Flutter SDKRun Script or Thin Binary cannot find Flutter: FLUTTER_ROOT is staleFix - 4
Failed to package …, or a Dart error, missing asset or Flutter tool message printed just above the PhaseScriptExecution line for the Run Script phaseThe Flutter build inside the Run Script phase failedFix
- 1
What does the error look like?
Command PhaseScriptExecution failed with a nonzero exit codeerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.Sandbox: rsync(…) deny(1) file-read-data …/Pods/Target Support Files/…/bin/sh: …/packages/flutter_tools/bin/xcode_backend.sh: No such file or directory
Cause 1 of 4
[CP] Check Pods Manifest.lock: the Pods folder does not match Podfile.lock
1Check
CocoaPods adds a script phase that compares Podfile.lock with Pods/Manifest.lock and stops the build when they differ. That happens after a pull that changed Podfile.lock, a plugin change, or a Pods folder made by another CocoaPods version. Run the same comparison by hand.
diff ios/Podfile.lock ios/Pods/Manifest.lock && echo same2Fix
Install the pods again from the ios folder so Pods/Manifest.lock is rewritten. For a Flutter app, run pub get first so the plugin list is current.
flutter pub get
cd ios && pod install3Verify
The two files are identical and the build gets past the phase.
diff ios/Podfile.lock ios/Pods/Manifest.lock && echo same
flutter build ios --no-codesignConfirmed by github.com
Cause 2 of 4
User script sandboxing blocks a script from reading or writing a file
1Check
Since Xcode 14 the ENABLE_USER_SCRIPT_SANDBOXING build setting can be turned on for shell script phases. When it is on, a script may not touch files inside the project folder or Derived Data unless they are listed as inputs or outputs, and the build fails with a sandbox violation. Flutter's own project template sets it to NO. Look at the value your target resolves to.
xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner -showBuildSettings \
| grep ENABLE_USER_SCRIPT_SANDBOXING2Fix
For a Flutter app, set User Script Sandboxing to No on the Runner target (Build Settings > Build Options), as the Flutter template does, and do the same on any extra app targets. For scripts you own, the stricter fix is to list every file they read as an input file and every file they write as an output file in the phase.
# in ios/Runner.xcodeproj/project.pbxproj the setting reads
ENABLE_USER_SCRIPT_SANDBOXING = NO;3Verify
The resolved setting prints NO and the same build passes.
xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner -showBuildSettings \
| grep ENABLE_USER_SCRIPT_SANDBOXINGConfirmed by developer.apple.com
Cause 3 of 4
Run Script or Thin Binary cannot find Flutter: FLUTTER_ROOT is stale
1Check
Flutter's Run Script and Thin Binary phases run xcode_backend.sh from the folder named by FLUTTER_ROOT. Flutter writes that value into ios/Flutter/Generated.xcconfig when it prepares the iOS project, so the file keeps the old path until Flutter regenerates it.
grep FLUTTER_ROOT ios/Flutter/Generated.xcconfig
flutter --version --machine | grep flutterRoot2Fix
Run pub get from the project root so Flutter rewrites Generated.xcconfig with the current SDK folder, then build again.
flutter clean
flutter pub get3Verify
FLUTTER_ROOT now matches the SDK you run, and the script file exists.
grep FLUTTER_ROOT ios/Flutter/Generated.xcconfig
ls "$(flutter --version --machine | python3 -c 'import json,sys;print(json.load(sys.stdin)["flutterRoot"])')/packages/flutter_tools/bin/xcode_backend.sh"Confirmed by github.com
Cause 4 of 4
The Flutter build inside the Run Script phase failed
1Check
The Run Script phase calls flutter assemble through xcode_backend.sh. If that command exits with an error the script prints Failed to package and exits, and Xcode reduces all of it to the PhaseScriptExecution line. The real message is the Flutter tool output above.
flutter analyze
flutter build ios --no-codesign -v 2>&1 | grep -n -B15 "Failed to package"2Fix
Fix the first Dart, asset or dependency error shown, then build again. The same error appears in plain flutter build, so you can debug there instead of inside Xcode.
flutter pub get
flutter build ios --no-codesign3Verify
flutter build ios finishes and Xcode builds the same project.
flutter build ios --no-codesignConfirmed by github.com
How do I stop it coming back?
- Commit Podfile.lock and run pod install after every pull that changes it.
- After moving or upgrading the Flutter SDK, run flutter clean and flutter pub get before opening Xcode.
- Keep User Script Sandboxing at the value Flutter's template uses, and declare input and output files for scripts you add.
- Build with flutter build ios in CI so the full script output is in the log, not only the Xcode summary line.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
Related fixes
Mobile apps
Simulator build fails because a library was built for real iPhones
building for iOS Simulator, but linking in object file built for iOS, for architecture arm64
The linker was building for the Simulator and met a library compiled only for physical iPhones.
4 causes, each with a fixMobile apps
pod install cannot pick a version of a pod that satisfies every requirement
Specs satisfying the `FirebaseAuth (~> 11.0)` dependency were found, but they required a higher minimum deployment target.
CocoaPods tried every version of the named pod and none fit all requirements.
4 causes, each with a fixMobile apps
Apple rejected the app under Guideline 4.3, Design: Spam
Guideline 4.3(b) - Design - Spam
Guideline 4.3 is Apple's duplicate rule.
5 causes, each with a fixMobile apps
flutter run says: Could not run Runner.app, try Xcode Product > Run
Try launching Xcode and selecting "Product > Run" to fix the problem:
Flutter prints this when installing or launching the built app on the iPhone fails, and it hides the real reason.
4 causes, each with a fixMobile apps
flutter doctor says CocoaPods is installed but not working
You appear to have CocoaPods installed but it is not working.
Flutter runs pod --version and treats a failed or unreadable result as a broken install.
3 causes, each with a fixMobile apps
flutter run on iOS or macOS stops with Error running pod install
Warning: CocoaPods not installed. Skipping pod install.
Flutter only reports that pod install failed; the reason is in the lines just above it.
5 causes, each with a fix