Skip to content

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:

  1. Open your .xcworkspace file in Xcode
  2. Select your project in the left sidebar
  3. Navigate to Build SettingsAllCombined
  4. Search for ENABLE_USER_SCRIPT_SANDBOXING
  5. 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.

Xcode Build Settings showing ENABLE_USER_SCRIPT_SANDBOXING set to NO

After making these changes:

  1. Clean your build: ProductClean Build Folder (⌥⇧⌘K)
  2. Delete DerivedData folder (located at ~/Library/Developer/Xcode/DerivedData)
  3. Rebuild your project

Why This Works

The sandboxing feature restricts file system access during build phases. Disabling it allows essential copy scripts to:

swift
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:

ruby
# Add to your Gemfile
gem 'xcodeproj', '< 1.26.0' # Versions >=1.26.0 may cause sandbox issues

Install dependencies with:

bash
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:

  1. Verify Podfile linkage for your extension target:

    ruby
    target 'XXXShareExtension' do
      # Ensure copy resources script exists
      use_frameworks!
    end
  2. Check runtime permissions in ios/XXXShareExtension/Info.plist:

    xml
    <key>NSDocumentsFolderUsageDescription</key>
    <string>Required to write resources</string>
  3. Reset Xcode toolchain:

    bash
    sudo 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 TypeCompatibility
React Native
Native iOS
Ionic/Cordova
Xcode 15+
Share Extensions