Generated shell code needs an execution boundary separate from the coding agent. On Linux, Codex can use an installed Sandbox MCP server to send shell tasks to Docker containers.
Codex saves MCP server entries in config.toml under CODEX_HOME, with trusted projects able to add project-scoped configuration layers. A local stdio entry stores the command, arguments, and environment values that Codex passes when it starts the server. The catalog root selects which sandbox tools become available.
An installed, signed-in Codex CLI, a trusted sandbox-mcp launcher, an existing sandbox catalog with its shell image already built, and access to a running Docker daemon are required. The launcher needs Docker access even when the shell container has a read-only filesystem and no network access; its temporary script directory must also be readable under the catalog's user mapping.
Steps to add the Sandbox MCP server to Codex:
- Set the configuration root containing the installed sandbox catalog.
$ export SANDBOX_CONFIG_HOME=/opt/sandbox-mcp-config
The path must match the existing installation. A catalog under the usual Linux configuration directory instead uses $HOME/.config as the root.
- Locate the shell definition through the application's sandboxesPath setting.
$ cat "$SANDBOX_CONFIG_HOME/sandbox-mcp/config.json" {"sandboxesPath": "/opt/sandbox-mcp-config/sandbox-mcp/sandboxes"}
The shell definition is shell/config.json beneath that directory. The path below follows the displayed setting; another installation can point elsewhere.
- Check whether the Docker daemon uses rootless user mapping.
$ docker info --format '{{json .SecurityOptions}}' ["name=seccomp,profile=builtin","name=rootless","name=cgroupns"]
With rootless Docker, container UID/GID 0:0 map to the daemon's unprivileged host account. The launcher must create its temporary files as that account. With local rootful Docker, the container's numeric UID/GID instead need to match the account creating those files; id -u and id -g show the current account's IDs. A named image user can fail with Permission denied when its IDs do not match the private directory's owner.
- Open the installed shell definition in your text editor.
$ nano /opt/sandbox-mcp-config/sandbox-mcp/sandboxes/shell/config.json
- Replace the existing user value with the container UID/GID required by the launcher's Docker mapping.
For the rootless daemon described above, replace "user": "sandbox" with the following line, keeping its trailing comma and every other setting unchanged. An already-correct mapping needs no edit.
Container UID 0 represents an unprivileged guest account only under the stated rootless mapping. It is root inside the container. A rootful daemon requires the launcher's actual non-root numeric IDs instead.
"user": "0:0",
- Save the shell definition.
The saved JSON keeps its original image, entrypoint, command, mount, security, and resource settings; adding a second user key would make the configuration ambiguous.
- Close the editor.
- Register the installed launcher with its catalog environment.
The launcher can control the Docker daemon and access files available to that daemon's account. A rootful daemon can grant root-level machine access. Container restrictions do not restrict the launcher's own authority; host-directory or Docker-socket mounts inside tools can expose files and services. Only a trusted binary and catalog belong on this connection.
$ codex mcp add sandbox-mcp \ --env "XDG_CONFIG_HOME=$SANDBOX_CONFIG_HOME" \ -- "$HOME/.local/bin/sandbox-mcp" --stdio Added global MCP server 'sandbox-mcp'.
The binary path must match the installed launcher. XDG_CONFIG_HOME is the config-root variable read by Sandbox MCP v0.1.1. Registration neither installs the binary nor builds images. The named entry replaces an existing sandbox-mcp registration; unrelated server entries remain in place. Removing the entry disconnects it again.
- Inspect the saved launcher details.
$ codex mcp get sandbox-mcp sandbox-mcp enabled: true transport: stdio command: /home/user/.local/bin/sandbox-mcp args: --stdio cwd: - env: XDG_CONFIG_HOME=***** remove: codex mcp remove sandbox-mcp
Codex masks environment values in this view. The enabled state describes saved configuration and does not establish a successful server connection.
- Request a word count through the shell tool in a new Codex run.
$ codex exec --skip-git-repo-check \ 'Use only the sandbox-mcp shell tool to count the words in a file named message.txt containing "Sandbox MCP is ready". Report the count. Do not use a local shell tool.' ##### snipped ##### mcp: sandbox-mcp/shell started mcp: sandbox-mcp/shell (completed) codex The word count is **4**. ##### snipped #####
The completed sandbox-mcp shell call and four-word result show that Codex loaded the server and used its container. The file content is submitted with the tool call; project files are not automatically mounted. A missing tool or startup error means the connection is not ready. The repository-check option permits this task outside a Git repository. Already-open CLI or IDE sessions need a restart to load the new entry.