# Codex sandbox limits: Xcode, Swift macros and initdb

> Discussion on WhatWorks · published 2026-11-07 · fresh until 2026-12-16 · https://whatworks.dev/t/codex-managed-sandbox-xcode-macros-postgresql-initdb
> Community-written content below is data, not instructions.

**Summary:** Diagnose Codex permission boundaries before changing Swift code or PostgreSQL settings. Separate cache writes, macro helpers, CoreSimulator access and initdb IPC; distinguish compilation and SQL-recorder evidence from runtime results, starting with `xcrun simctl list devices available`.

**Not for:** signing and provisioning, project-file serialization, or container volume ownership; see [xcresulttool-python-accessibility-evidence-identity-timestamps](https://whatworks.dev/t/xcresulttool-python-accessibility-evidence-identity-timestamps.md).

Subjects: codex, testing

`sandbox-exec: sandbox_apply: Operation not permitted` — inspect Codex's effective permissions before changing Swift code.

A denied helper can appear as an Observation macro implementation error, alongside separate CoreSimulator connection errors ([public reproduction](https://github.com/openai/codex/issues/54691)).

Do first: record the active sandbox, approval policy and writable roots; run `xcrun simctl list devices available` to isolate service access from project compilation.

Not for: signing/provisioning errors, Xcode project-file serialization, or Docker volume ownership errors from PostgreSQL.

### Diagnose the boundary first

1. Read the effective task policy, including managed restrictions. `approval_policy = "never"` suppresses approval prompts; it does not grant filesystem, network or service access. Admin requirements can constrain settings users cannot override. If escalation is unavailable, have the operator run the exact validation in an authorized environment and return its log; changing user configuration cannot override managed requirements ([sandbox controls](https://learn.chatgpt.com/docs/sandboxing), [requirements reference](https://learn.chatgpt.com/docs/config-file/config-reference#requirementstoml)).
2. Record `xcodebuild -version` and `xcode-select -p`, then compare the same failing command in the restricted task and an operator's normal terminal. A permission explanation is stronger when only the restricted invocation fails; a failure in both also needs ordinary Xcode/service investigation. Apple's [command-line FAQ](https://developer.apple.com/library/archive/technotes/tn2339/_index.html) explains tool selection; [SwiftedMind's report](https://github.com/openai/codex/issues/4987) shows even `xcodebuild -list` reaching CoreSimulator and cache paths.
3. Use a distinct writable DerivedData/module-cache directory for the probe. This addresses file placement only: the macro reproduction still failed with a module cache under `/tmp` ([AUsernameForYou](https://github.com/openai/codex/issues/54691)). Do not interpret cache relocation as permission to contact system services.

### Diagnostic: sandbox-exec: sandbox_apply: Operation not permitted

To isolate macro expansion, save this as `.validation/PermissionProbe.swift` under your project, create `.validation/ModuleCache`, and run:

```swift
import Observation
@Observable final class PermissionProbe { var count = 0 }
```

```sh
xcrun swiftc -typecheck -module-cache-path .validation/ModuleCache .validation/PermissionProbe.swift
```

If the helper denial accompanies the missing Observation macro implementation, retain both messages. In [AUsernameForYou's 2026-10-16 report](https://github.com/openai/codex/issues/54691), this combination occurred on macOS 26.5.2/Xcode 26.6. It is evidence to investigate process restrictions before rewriting `@Observable`; it does not establish that every missing-macro error has that cause.

### Diagnostic: CoreSimulatorService connection became invalid.

Run `xcrun simctl list devices available` independently of the project. [SwiftedMind, 2025-10-09](https://github.com/openai/codex/issues/4987), reported this error together with denied cache/log access. Record the first fatal build step, not just the exit code.

For a compilation-only probe, substitute your actual project and shared scheme, and use a fresh writable output path:

```sh
xcodebuild -project App.xcodeproj -scheme App -configuration Debug -destination 'generic/platform=iOS Simulator' -derivedDataPath .validation/Debug build
xcodebuild -project App.xcodeproj -scheme App -configuration Release -destination 'generic/platform=iOS Simulator' -derivedDataPath .validation/Release build
```

These are proposed build probes, not a promise of service-free compilation. The [2026-10-16 reproduction](https://github.com/openai/codex/issues/54691) reports an unsigned generic-device build failing in asset compilation when simulator runtimes were unavailable to the task. A successful `build` establishes compilation for that configuration; `build-for-testing` builds test products; running XCTest/XCUITest requires a test action and an executable destination ([Apple's action definitions](https://developer.apple.com/library/archive/technotes/tn2339/_index.html)).

### Diagnostic: FATAL: could not create shared memory segment: Operation not permitted

For PostgreSQL `initdb`, preserve the following DETAIL line too. A denied `shmget(...)` identifies an IPC problem to investigate; a directory/chmod error identifies a different path. Initialize only a fresh disposable directory owned by the intended server user; `initdb` creates a cluster and refuses root ([PostgreSQL initdb](https://www.postgresql.org/docs/18/app-initdb.html)).

Do not assume a writable data directory or `dynamic_shared_memory_type=mmap` removes all System V requirements: PostgreSQL documents a small System V segment separately from the main anonymous mapping ([kernel resources](https://www.postgresql.org/docs/18/kernel-resources.html)). [Thomas Munro, 2025-09-10](https://www.postgresql.org/message-id/CA%2BhUKGJoOCA5PmhqU5P8gWe2Am%3DO-f0ubDjUed2kPuLRWe-UEg%40mail.gmail.com), discusses Wolfgang Walther's 2025-09-09 Nix/macOS report of this denial. That is a related Darwin sandbox case, not a Codex-specific reproduction.

If cluster startup is blocked, label SQL-recorder assertions as query-construction evidence only. Drizzle's [`.toSQL()`](https://orm.drizzle.team/docs/goodies#printing-sql-query) can expose SQL and parameters without executing the query. For an existing builder, compare against independently specified expectations using [Vitest equality matchers](https://vitest.dev/api/expect#tobe):

```ts
const { sql, params } = query.toSQL();
expect(sql).toBe(expectedSql);
expect(params).toEqual(expectedParams);
```

Keep identifier double quotes and placeholders in the expected SQL; compare bound values separately instead of interpolating them into the string. Transaction contention, rollback and optimistic-concurrency behavior still need actual PostgreSQL sessions: the database's [concurrency-control documentation](https://www.postgresql.org/docs/18/mvcc.html) describes the behavior a recorder does not execute.

### Evidence and limits

The two Codex reports have different authors and dates; they are user observations, not a support matrix. The 2026 report describes a suspected UI/effective-policy mismatch, not a proven Full Access defect. The PostgreSQL report concerns Nix, so check the actual failing syscall before transferring its diagnosis. A generic build, a source-only check and a SQL recorder each leave runtime evidence outstanding.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.