# A sandbox for Codex: running codex exec in a cloud workspace

> Run OpenAI Codex non-interactively with codex exec inside a Sandscale workspace, a persistent Firecracker microVM, and drive it from your laptop over SSH. Sandbox modes, JSON output and schedules.

Run OpenAI Codex non-interactively with codex exec inside a Sandscale workspace, a persistent Firecracker microVM, and drive it from your laptop over SSH. Sandbox modes, JSON output and schedules.

November 27, 2026 · 5 min read · The Sandscale team

**Short answer:** Codex has its own sandbox modes, but they still run on the machine Codex runs on. To keep the whole run off your laptop, run Codex on a cloud computer and call `codex exec` there. A Sandscale [workspace](https://sandscale.dev/workspaces) is a Firecracker microVM with its own kernel and a disk that persists, and `sandscale workspace ssh NAME -- COMMAND` lets you start the run from your own terminal.

Sources, read in November 2026: OpenAI’s [Codex non-interactive mode](https://developers.openai.com/codex/noninteractive) page, and Sandscale’s [workspaces guide](https://sandscale.dev/docs/guides/workspaces) and [workspace CLI reference](https://sandscale.dev/docs/reference/cli/workspace).

## Codex’s sandbox and a workspace are different layers

Per OpenAI’s docs, `codex exec` runs in a read-only sandbox by default. `--sandbox workspace-write` allows edits, and `--sandbox danger-full-access` allows broader access, which the docs say to use only in a controlled environment such as an isolated CI runner or container.

Those modes limit what Codex may do on its host. A workspace changes what the host is. Combining them gives you two independent checks: Codex’s mode inside, and a separate microVM with its own kernel outside, so even a run with broad access lands on the workspace’s disk.

## 1. Create a workspace for Codex

```sh
sandscale login
sandscale workspace templates list
sandscale workspace create codex-box --template TEMPLATE
sandscale workspace open codex-box
```

`TEMPLATE` is a name from `templates list`. Inside the workspace, install Codex as OpenAI’s docs describe, sign in, and clone your repository. The disk persists, so you do this once. Codex calls OpenAI’s API, so the workspace needs network access; network follows your plan and your organization’s policy, so check that yours lets the workspace reach that API.

## 2. Run codex exec on the workspace

From inside the workspace:

```sh
cd ~/src/my-service
codex exec --sandbox workspace-write "run the tests, fix the first failure, and explain the fix"
```

While it runs, Codex streams progress to standard error and prints only the final agent message to standard output, so you can redirect it:

```sh
codex exec --sandbox workspace-write "update the changelog for the last 10 commits" | tee changelog-notes.md
```

For machine-readable output, `--json` turns standard output into a JSON Lines stream of events such as `thread.started`, `turn.completed`, `turn.failed` and `item.*`. `--ephemeral` skips writing session rollout files to disk.

## 3. Start it from your laptop

`sandscale workspace ssh` runs everything after `--` on the workspace, with a short-lived certificate and a checked host key:

```sh
sandscale workspace ssh codex-box -- 'cd ~/src/my-service && codex exec --sandbox workspace-write "fix the lint errors"'
```

Per the CLI reference, ssh joins the words after `--` with spaces, as ssh does, so quote the remote command as one string. If the workspace is stopped, `sandscale workspace open codex-box` starts it first.

For long tasks, start Codex inside `tmux` on the workspace instead and detach, so the run does not depend on your SSH session.

## 4. Feed it logs without copying them around

OpenAI’s docs show piping input into `codex exec`, with the prompt as the instruction and standard input as context. On a workspace that is handy for test output that never leaves the machine:

```sh
npm test 2>&1 | codex exec "summarize the failing tests and propose the smallest likely fix" > test-summary.md
```

## 5. Stop it when the run is done

```sh
sandscale workspace schedule stop codex-box 8h
sandscale workspace stop codex-box
```

The first stops the workspace 8 hours after each start; the second stops it now. Stopping keeps the disk. A workspace also stops when idle, and it uses your plan’s vCPU-hours only while it runs.

## Project trust and MCP servers

OpenAI’s docs say local `codex exec` runs load project configuration and project-defined MCP servers only for trusted projects, and that project-defined MCP servers can run commands outside Codex’s sandbox. On a workspace, “outside the sandbox” still means inside the microVM, which is one more reason to give Codex its own workspace rather than your laptop. If you want Codex on your laptop instead, with only commands going to Sandscale, see [adding the Sandscale MCP server to Codex](https://sandscale.dev/blog/sandscale-mcp-server-in-codex).

## FAQ

### What sandbox does Codex use by default?

Per OpenAI’s docs, `codex exec` runs in a read-only sandbox by default. `--sandbox workspace-write` allows edits and `--sandbox danger-full-access` allows broader access.

### How do I run Codex outside my own machine?

Install Codex on a cloud workspace and run `codex exec` there, either in a shell on the workspace or from your laptop with `sandscale workspace ssh NAME -- COMMAND`. The workspace is its own Firecracker microVM.

### Can I get Codex output as JSON?

Yes. `codex exec --json` makes standard output a JSON Lines stream of events. Without it, only the final agent message goes to standard output.

### Does the workspace keep Codex’s sign-in and my clone?

Yes. A workspace keeps its disk when it stops. Deleting it with `sandscale workspace delete` deletes its disks.

## Related

- [Adding the Sandscale MCP server to Codex](https://sandscale.dev/blog/sandscale-mcp-server-in-codex)
- [Running Claude Code headless in a cloud workspace](https://sandscale.dev/blog/claude-code-headless-in-a-cloud-workspace)
- [Running Gemini CLI headless in a cloud workspace](https://sandscale.dev/blog/gemini-cli-headless-in-a-cloud-workspace)
- [Use case: a coding agent that keeps working after you close the laptop](https://sandscale.dev/blog/use-case-long-running-agent-in-a-workspace)

**On this page**

1. Codex’s sandbox and a workspace are different layers
2. 1. Create a workspace for Codex
3. 2. Run codex exec on the workspace
4. 3. Start it from your laptop
5. 4. Feed it logs without copying them around
6. 5. Stop it when the run is done
7. Project trust and MCP servers
8. FAQ
9. Related

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [November 27, 2026 · **A LlamaIndex.TS data agent that runs its Python in a Sandscale sandbox** · Use LlamaIndex.TS's agent workflow with tools that write and run Python in a Firecracker sandbox, built per sandbox so a run can only reach its own box. Upload data files, answer with the numbers, clean up. Type-checked.](https://sandscale.dev/blog/llamaindex-ts-agent-with-sandscale)
- [November 27, 2026 · **A sandbox for Claude Code: running it headless in a cloud workspace** · Run Claude Code with claude -p inside a Sandscale workspace, a persistent Firecracker microVM, so its Bash tool works on a cloud disk instead of your laptop. Setup, permission flags and what stays where.](https://sandscale.dev/blog/claude-code-headless-in-a-cloud-workspace)

---
Source: https://sandscale.dev/blog/codex-exec-in-a-cloud-workspace
