Codex can't build your iOS app? Error messages, causes and fixes
When Codex fails to build an iOS app, the cause is often its macOS sandbox rather than your project: in the default workspace-write mode, xcodebuild and simctl can lose CoreSimulatorService and the network. Allow Xcode commands outside the sandbox with a Codex rule, check network access, and raise tool_timeout_sec for MCP builds.
Last updated:
Codex runs model-generated commands in an OS-enforced sandbox. On macOS that means Seatbelt policies via sandbox-exec. In the Codex CLI, IDE extension and ChatGPT desktop app, the defaults are no network access and writes limited to the workspace (the current directory plus temporary directories such as /tmp) (OpenAI: agent approvals & security). Xcode's tools reach well beyond that: they talk to simulator services, write caches under ~/Library, and download packages. The errors that result often look like project problems, and Codex itself may not realize the sandbox is the cause (openai/codex#8433).
Setting up Codex for iOS from scratch? Start with Codex for iOS development.
Error → cause → fix
| Error text (excerpt) | Cause | Fix | Source |
|---|---|---|---|
CoreSimulatorService connection became invalid. Simulator services will no longer be available. | The sandbox blocks the XPC connection to the simulator services | Run Xcode commands outside the sandbox: approve them, or permanently with a prefix_rule (see below) | codex#4987, codex#54691; rules: OpenAI |
Error opening log file (…/Library/Logs/CoreSimulator/…): Operation not permitted | Write outside the workspace | as above | codex#4987 |
couldn't create cache file '/tmp/xcrun_db-…' (errno=Operation not permitted) | xcrun/xcodebuild in the sandbox | as above | codex#4987 |
xcodebuild -list exits with 66 and not a workspace file | Misleading: the user report traces it to the CoreSimulator block, not a broken workspace | as above | codex#10390 (comment) |
sandbox-exec: sandbox_apply: Operation not permitted / external macro implementation type 'ObservationMacros.ObservableMacro' could not be found | Nested sandbox: the Swift macro plugin server (or SwiftPM's own sandbox) can't start inside the Codex sandbox | Run the build outside the sandbox. For swift package resolve, a user report names SwiftPM's --disable-sandbox flag | codex#54691, codex#10390 (comment) |
Package resolution or tuist generate hangs or times out | No network in workspace-write | Set network_access = true under [sandbox_workspace_write]; on macOS there's an open report that the setting is ignored | OpenAI, codex#10390 |
Codex asks for approval again for every xcodebuild | Approvals and rules match the command prefix. With redirects (> log 2>&1), env variables or &&, Codex treats the whole line as bash -lc "<script>" | Have Codex run plain xcodebuild … without redirects, or allow a stable wrapper script by rule | OpenAI rules, codex#10321, codex#12095 |
timed out awaiting tools/call after 60s (or 120s) | MCP tool timeout, Codex default 60 s | Set tool_timeout_sec inside the server block: see the setup guide | Codex config reference, MobileBuildMCP |
MCP server doesn't start in Xcode's Codex agent / npx not found | Xcode's agent starts with a minimal PATH | zsh -lc wrapper with an explicit PATH in the project's .codex/config.toml | MobileBuildMCP |
| MCP server times out on startup | Startup timeout, Codex default 10 s | startup_timeout_sec in the server block | Codex config reference |
No signing certificate found (device build) | Signing setup, not an agent problem | In Xcode: enable automatic signing and select a team; the DEVELOPMENT_TEAM build setting holds the team ID | MobileBuildMCP, Apple build settings |
Unable to find a destination matching the provided destination specifier | Simulator name/OS in -destination doesn't match | List the available devices with xcrun simctl list devices available, then use platform=iOS Simulator,name=…[,OS=…] | Apple TN2339 |
| Simulator "booted", but nothing launches | Stale simulator | xcrun simctl shutdown all, wait about 5 s, retry; otherwise xcrun simctl erase <UDID> | MobileBuildMCP |
| Build hangs at "Planning" via MCP | Report: pipe deadlock, amplified by several old MCP server processes (the maintainer couldn't reproduce it) | Check for stale server processes; mobilebuildmcp daemon list / daemon restart | MobileBuildMCP#492, docs |
| Mac gets slow, disk fills up after long simulator sessions | Report: simulators and build artifacts pile up | Shut simulators down between sessions (xcrun simctl shutdown all) and watch DerivedData | codex#34606 |
Rows marked "report" come from public GitHub issues, not official documentation.
1. Is the sandbox the cause? Find out in 30 seconds
Codex has a command for exactly this check (OpenAI):
bash
codex sandbox macos --log-denials xcodebuild -listIf the command works in a normal terminal but fails here (and reports denials), it's the sandbox. In the Codex TUI, /status shows which directories count as the workspace (OpenAI).
2. Allow Xcode commands outside the sandbox permanently
Codex rules are Starlark files in ~/.codex/rules/ (for example default.rules). With decision = "allow", a matching command runs outside the sandbox without a prompt. prompt asks every time, and forbidden blocks it. When several rules match, the strictest decision wins. Codex reads rules at startup, so restart it after a change (OpenAI rules).
python
# ~/.codex/rules/default.rules
prefix_rule(
pattern = ["xcodebuild"],
decision = "allow",
justification = "Xcode builds need CoreSimulator and ~/Library access",
)
prefix_rule(
pattern = ["xcrun", "simctl"],
decision = "allow",
justification = "Simulator control",
)Test it before relying on it (OpenAI rules):
bash
codex execpolicy check --pretty --rules ~/.codex/rules/default.rules -- xcodebuild -listTwo details from the docs and issues:
Redirects break the match. For
>,>>,<,$(…),FOO=bar, wildcards or control flow, Codex doesn't split the line and checks it as["bash", "-lc", "<script>"]. A rule for["xcodebuild"]then no longer applies. A line inAGENTS.mdsuch as "Run xcodebuild without redirects or env prefixes" helps (OpenAI rules). OpenAI closed codex#10321 in June 2026 as fixed by PR #11951, which extends matching to redirects in simple commands. codex#12095 (/bin/zsh -lcvs. direct execution) was still open on 20 Oct 2026.A broken
.rulesfile can stop other rules from working, according to a user report in codex#10321. Check every file withexecpolicy check.
Security: allow means everything starting with xcodebuild runs unsandboxed. That's narrower than --sandbox danger-full-access (which turns off the sandbox and approvals entirely), but it's still an exception. Keep the list short.
3. Network for Swift packages, Tuist and CocoaPods
toml
# ~/.codex/config.toml (OpenAI docs)
[sandbox_workspace_write]
network_access = trueOpenAI warns that network access raises the prompt-injection risk; the docs also describe a network_proxy feature with domain rules (OpenAI). On macOS, codex#10390 reports that the setting had no effect. The issue is open, and a later comment suggests newer versions might have fixed it. If package resolution still hangs, resolve once outside Codex or run the command outside the sandbox via rule or approval.
4. Builds outside the workspace
The workspace-write sandbox allows writes to the workspace and to temporary directories. Use sandbox_workspace_write.writable_roots to add more paths (Codex config reference). In reports, though, extra writable_roots didn't solve the CoreSimulator block (codex#10390), because that's an IPC block, not a write block. For simulator work, step 2 is the reliable route.
5. Use MCP instead of raw shell commands
OpenAI's iOS page recommends staying CLI-first with xcodebuild and adding XcodeBuildMCP (today MobileBuildMCP) once schemes, simulator control, screenshots and logs matter (OpenAI: Build for iOS). Setup and the timeout setting are in the Codex setup guide. For MobileBuildMCP problems, the doctor helps: npx --package mobilebuildmcp@latest mobilebuildmcp-doctor. More simulator tools: iOS simulator MCP servers compared.
AGENTS.md block to copy
markdown
## Building (Codex)
- Build: `xcodebuild -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 17' build`
- Run xcodebuild and simctl as plain commands: no `> log`, no `2>&1`, no `FOO=bar` prefix, no `&&` chains.
- If a command fails with CoreSimulatorService / "Operation not permitted", it is the sandbox: ask for approval instead of changing the project.(The device name is an example. Use one from xcrun simctl list devices available.)
FAQ
- Why does xcodebuild fail in Codex but work in Terminal?
- Codex runs commands in a macOS sandbox with no network and writes limited to the workspace. xcodebuild also needs CoreSimulatorService and folders under ~/Library. Check with codex sandbox macos --log-denials <command>, and allow the command outside the sandbox with a prefix_rule.
- How do I stop Codex asking for approval on every xcodebuild?
- Add prefix_rule(pattern = ["xcodebuild"], decision = "allow") to ~/.codex/rules/default.rules and restart Codex. Have it run xcodebuild without redirects or env prefixes, because Codex checks those lines as a whole bash -lc script.
- How do I fix "timed out awaiting tools/call after 60s" in Codex?
- Codex's default MCP tool timeout is 60 seconds. Set tool_timeout_sec inside the server's [mcp_servers.<name>] block, because MobileBuildMCP's docs say Codex ignores a top-level value. Details are in our Codex for iOS development guide.
- Does Codex have network access when building?
- Not by default. In workspace-write mode, network access is off until you set network_access = true under [sandbox_workspace_write]. There's an open report that this setting has no effect on macOS.
- What does "CoreSimulatorService connection became invalid" mean in Codex?
- The sandbox blocks xcodebuild's or simctl's connection to the simulator services. Your project isn't the problem. Run those commands outside the sandbox, either approved each time or permanently through a Codex rule.