Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/agents/codex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

const sandbox = await Sandbox.create('codex', {
envs: { CODEX_API_KEY: process.env.CODEX_API_KEY },
timeoutMs: 600_000,

Check warning on line 69 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L69

Did you really mean 'timeoutMs'?
})

await sandbox.git.clone('https://github.com/your-org/your-repo.git', {
Expand Down Expand Up @@ -244,21 +244,85 @@
```
</CodeGroup>

## Resume a session

Codex persists sessions (rollout files under `~/.codex/sessions` in the sandbox) that can be resumed with follow-up tasks using `codex exec resume`. Run the first task with `--json` and capture the `thread_id` from the `thread.started` event.

Check warning on line 249 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L249

Did you really mean 'rollout'?

<CodeGroup>
```typescript JavaScript & TypeScript
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('codex', {
envs: { CODEX_API_KEY: process.env.CODEX_API_KEY },
timeoutMs: 600_000,

Check warning on line 257 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L257

Did you really mean 'timeoutMs'?
})

// Start a new session
const initial = await sandbox.commands.run(
`codex exec --full-auto --skip-git-repo-check --json "Create plan.md with a 3-step plan for a TODO CLI app"`
)

// The first --json event is thread.started
const threadId = JSON.parse(initial.stdout.trim().split('\n')[0]).thread_id

Check warning on line 266 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L266

Did you really mean 'threadId'?

// Continue in the same session
await sandbox.commands.run(
`codex exec resume ${threadId} --full-auto --skip-git-repo-check "Now implement step 1 of the plan"`,
{ onStdout: (data) => process.stdout.write(data) }
)

const plan = await sandbox.commands.run('cat /home/user/plan.md')
console.log(plan.stdout)

await sandbox.kill()
```
```python Python
import os
import json
from e2b import Sandbox

sandbox = Sandbox.create("codex", envs={
"CODEX_API_KEY": os.environ["CODEX_API_KEY"],
}, timeout=600)

# Start a new session
initial = sandbox.commands.run(
'codex exec --full-auto --skip-git-repo-check --json "Create plan.md with a 3-step plan for a TODO CLI app"',
)

# The first --json event is thread.started
thread_id = json.loads(initial.stdout.strip().splitlines()[0])["thread_id"]

# Continue in the same session
sandbox.commands.run(
f'codex exec resume {thread_id} --full-auto --skip-git-repo-check "Now implement step 1 of the plan"',
on_stdout=lambda data: print(data, end=""),
)

plan = sandbox.commands.run("cat /home/user/plan.md")
print(plan.stdout)

sandbox.kill()
```
</CodeGroup>

To simply continue the most recent session in the working directory, use `codex exec resume --last "follow-up task"` — no thread ID needed. When working in a cloned repo, pass `-C` before the `resume` subcommand (`codex exec -C /home/user/repo resume <thread_id> "..."`); it is not accepted after it.

Check warning on line 309 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L309

Did you really mean 'subcommand'?

## Image input

Pass screenshots or design mockups with `--image` to give Codex visual context alongside the prompt.

Check warning on line 313 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L313

Did you really mean 'mockups'?

<CodeGroup>
```typescript JavaScript & TypeScript
import fs from 'fs'

Check warning on line 317 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L317

Did you really mean 'fs'?
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('codex', {
envs: { CODEX_API_KEY: process.env.CODEX_API_KEY },
timeoutMs: 600_000,

Check warning on line 322 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L322

Did you really mean 'timeoutMs'?
})

// Upload a design mockup to the sandbox

Check warning on line 325 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L325

Did you really mean 'mockup'?
await sandbox.files.write(
'/home/user/mockup.png',
fs.readFileSync('./mockup.png')
Expand Down Expand Up @@ -344,7 +408,7 @@

<CodeGroup>
```bash JavaScript & TypeScript
npx tsx build.ts

Check warning on line 411 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L411

Did you really mean 'npx'?
```
```bash Python
python build.py
Expand All @@ -358,7 +422,7 @@
Auto-pause, resume, and manage sandbox lifecycle
</Card>
<Card title="Git integration" icon="code-branch" href="/docs/sandbox/git-integration">
Clone repos, manage branches, and push changes

Check warning on line 425 in docs/agents/codex.mdx

View check run for this annotation

Mintlify / Mintlify Validation (e2b) - vale-spellcheck

docs/agents/codex.mdx#L425

Did you really mean 'repos'?
</Card>
<Card title="SSH access" icon="terminal" href="/docs/sandbox/ssh-access">
Connect to the sandbox via SSH for interactive sessions
Expand Down