Resolving Xcode Sandbox File-Write-Data Errors
Problem Statement
When building React Native iOS projects (particularly Share extensions) in Xcode, you may encounter a sandbox permission error:
Sandbox: bash(72986) deny(1) file-write-data /Users/XXX/ios/Pods/resources-to-copy-XXXShareExtension.txt
This error indicates the Xcode build sandbox is preventing scripts from writing to required files. The issue manifests as a build failure despite repeated rebuild attempts, especially in projects with extensions.
Primary Solution: Disable User Script Sandboxing
The most reliable fix involves disabling the ENABLE_USER_SCRIPT_SANDBOXING setting in Xcode:
- Open your
.xcworkspace
file in Xcode - Select your project in the left sidebar
- Navigate to Build Settings › All › Combined
- Search for
ENABLE_USER_SCRIPT_SANDBOXING
- Change the value to NO for:
- Your main application target
- Your Share Extension target (XXXShareExtension)
Important
Both targets must have this setting disabled. Failure to modify both is a common oversight.
After making these changes:
- Clean your build: Product › Clean Build Folder (⌥⇧⌘K)
- Delete
DerivedData
folder (located at ~/Library/Developer/Xcode/DerivedData) - Rebuild your project
Why This Works
The sandboxing feature restricts file system access during build phases. Disabling it allows essential copy scripts to:
1. Read resources from source directories
2. Write required files to the build folder
3. Access shared Pod resources between targets
Alternative Solution: Fix Gem Dependencies in CI Environments
If the error occurs in a CI/CD pipeline using Ruby-based tools, pin your xcodeproj
gem version:
# Add to your Gemfile
gem 'xcodeproj', '< 1.26.0' # Versions >=1.26.0 may cause sandbox issues
Install dependencies with:
bundle install
bundle exec pod install
Framework Limitation
This Gemfile fix only applies to builds using:
- Fastlane
- CocoaPods dependency management
- Ruby-based build toolchains
Additional Troubleshooting Steps
If the issue persists:
Verify Podfile linkage for your extension target:
rubytarget 'XXXShareExtension' do # Ensure copy resources script exists use_frameworks! end
Check runtime permissions in
ios/XXXShareExtension/Info.plist
:xml<key>NSDocumentsFolderUsageDescription</key> <string>Required to write resources</string>
Reset Xcode toolchain:
bashsudo rm -rf ~/Library/Developer/Xcode/DerivedData sudo rm -rf ~/Library/Caches/CocoaPods pod deintegrate pod install --repo-update
Conclusion
The deny(1) file-write-data
error occurs when Xcode's sandbox restricts build script operations. Disabling ENABLE_USER_SCRIPT_SANDBOXING for all targets resolves most cases, while gem version management addresses CI-specific pipeline failures. These solutions apply to:
Project Type | Compatibility |
---|---|
React Native | ✅ |
Native iOS | ✅ |
Ionic/Cordova | ✅ |
Xcode 15+ | ✅ |
Share Extensions | ✅ |