OpenAI explains in detail how the Codex sandbox restricts commands' file and network access
Inside the Codex sandbox
OpenAI published a post introducing the design of the Codex sandbox, which lets Codex run commands in the user's existing environment and restricts file system and network access according to permission profiles. The built-in :workspace profile allows writes within the workspace, makes .git and .codex read-only, allows a fairly broad read scope, and disables network by default; OpenAI says this blocks a large class of bad behavior, but harm can still be caused by tampering with packages in node_modules and similar means, so training and alignment are needed as well. Network restrictions are enforced by a shared network proxy according to domain rules; macOS uses Seatbelt's sandbox-exec, Linux combines bubblewrap and seccomp-bpf, and on Windows it is being replaced with an implementation based on Microsoft's MXC library. The codex sandbox command lets developers apply the same set of restrictions to their own tools, and the post gives adding a permission profile to a stdio MCP server as an example.
The original source gives the specific implementation and default permission trade-offs of the Codex sandbox on macOS, Linux and Windows, which can serve as a reference for building one's own agent sandbox.