> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superserve.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex

> Run the OpenAI Codex CLI in a Superserve sandbox.

Codex is OpenAI's terminal coding agent. Run it in a Superserve sandbox so its shell commands and file edits stay isolated from your machine.

## Via the console

1. On the [Secrets page](https://console.superserve.ai/secrets?utm_source=docs\&utm_medium=link), create a secret with the **OpenAI** provider and paste your API key — you only do this once, and the key never enters the sandbox.
2. Go to [console.superserve.ai](https://console.superserve.ai?utm_source=docs\&utm_medium=link) and click **Create sandbox**.
3. Pick the **`superserve/node-22`** template.
4. Under **Advanced Options → Secrets**, bind that secret to `OPENAI_API_KEY`.
5. Create the sandbox, open its **Terminal**, and run:

   ```bash theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
   npm install -g @openai/codex && codex
   ```

## Via the SDK

```bash theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
npm install @superserve/sdk
export SUPERSERVE_API_KEY=ss_live_...
```

<CodeGroup>
  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  import { Sandbox, Secret } from "@superserve/sdk"

  // One-time: store your key as a secret. It never enters the sandbox.
  await Secret.create({ name: "openai-key", value: "sk-...", provider: "openai" })

  const sandbox = await Sandbox.create({
    name: "codex",
    fromTemplate: "superserve/node-22",
    secrets: { OPENAI_API_KEY: "openai-key" },
  })

  await sandbox.commands.run("npm install -g @openai/codex")
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
  from superserve import Sandbox, Secret

  # One-time: store your key as a secret. It never enters the sandbox.
  Secret.create(name="openai-key", value="sk-...", provider="openai")

  sandbox = Sandbox.create(
      name="codex",
      from_template="superserve/node-22",
      secrets={"OPENAI_API_KEY": "openai-key"},
  )

  sandbox.commands.run("npm install -g @openai/codex")
  ```
</CodeGroup>

Codex reads `OPENAI_API_KEY` as usual, but its value is a [stand-in token](/secrets/overview) — the real key is attached only on requests to OpenAI, never exposed to the agent.

Open the sandbox in the [console](https://console.superserve.ai?utm_source=docs\&utm_medium=link), launch the terminal, and run `codex`.

## Persist sessions

```typescript theme={"theme":{"light":"github-light","dark":"vitesse-dark"}}
await sandbox.pause()
await sandbox.resume()
```
