Skip to content

Commit 83ad50f

Browse files
committed
updated codex example (py)
1 parent 2b5106f commit 83ad50f

File tree

4 files changed

+45
-8
lines changed
  • examples
    • anthropic-claude-code-in-sandbox-js/src
    • anthropic-claude-code-in-sandbox-python
    • openai-codex-in-sandbox-python

4 files changed

+45
-8
lines changed

examples/anthropic-claude-code-in-sandbox-js/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ console.log('Sandbox created', sbx.sandboxId)
2020
// Run a prompt with Claude Code
2121
const result = await sbx.commands.run(
2222
`echo 'Create a hello world index.html' | claude -p --dangerously-skip-permissions`,
23-
{ timeoutMs: 0 }
23+
{ timeoutMs: 0 } // Claude Code can run for a long time, so we need to set the timeoutMs to 0.
2424
)
2525

2626
console.log(result.stdout)

examples/anthropic-claude-code-in-sandbox-python/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ from e2b import Sandbox
1111

1212
sbx = Sandbox(
1313
"anthropic-claude-code",
14+
# You can get your API key from Anthropic Console.
1415
envs={
1516
'ANTHROPIC_API_KEY': '<your api key>',
1617
},
18+
# Timeout set to 5 minutes, you can customize it as needed.
1719
timeout=60 * 5,
18-
) # Timeout set to 5 minutes, you can customize it as needed.
20+
)
21+
22+
# Print help for Claude Code
23+
# result = sbx.commands.run('claude --help')
24+
# print(result.stdout)
1925

2026
# Run a prompt with Claude Code
2127
result = sbx.commands.run(
2228
"echo 'Create a hello world index.html' | claude -p --dangerously-skip-permissions",
23-
timeout=0, # Claude Code can run for a long time, so we need to set the timeout to 0.
29+
# Claude Code can run for a long time, so we need to set the timeout to 0.
30+
timeout=0,
2431
)
2532
print(result.stdout)
2633

examples/openai-codex-in-sandbox-python/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,26 @@ We prepared a sandbox template with Codex already installed. You can create a sa
88
```python
99
from e2b import Sandbox
1010

11-
sbx = Sandbox("openai-codex", timeout=60 * 5) # Timeout set to 5 minutes, you can customize it as needed.
12-
13-
result = sbx.commands.run("codex --help")
11+
sbx = Sandbox(
12+
"openai-codex",
13+
envs={
14+
# You can get your API key from OpenAI Console.
15+
"OPENAI_API_KEY": "<your api key>",
16+
},
17+
# Timeout set to 5 minutes, you can customize it as needed.
18+
timeout=60 * 5,
19+
)
20+
21+
# Print help for Codex
22+
# result = sbx.commands.run('codex --help', request_timeout=0, timeout=0)
23+
# print(result.stdout)
24+
25+
# Run a prompt with Codex
26+
result = sbx.commands.run(
27+
"codex exec --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox 'Create a hello world index.html'",
28+
# Codex can run for a long time, so we need to set the timeout to 0.
29+
timeout=0,
30+
)
1431
print(result.stdout)
1532
```
1633

examples/openai-codex-in-sandbox-python/src/openai_codex_in_sandbox_python/main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
load_dotenv()
55

66
template_name = 'openai-codex'
7-
sbx = Sandbox(template_name)
7+
sbx = Sandbox(
8+
template_name,
9+
envs={
10+
"OPENAI_API_KEY": "<your api key>",
11+
},
12+
)
813
print("Sandbox created", sbx.sandbox_id)
914

10-
result = sbx.commands.run('codex --help', request_timeout=0, timeout=0) # Codex can run for a long time, so we need to set the request_timeout and timeout to 0.
15+
# Print help for Codex
16+
# result = sbx.commands.run('codex --help', request_timeout=0, timeout=0)
17+
# print(result.stdout)
18+
19+
# Run a prompt with Codex
20+
result = sbx.commands.run(
21+
"codex exec --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox 'Create a hello world index.html'",
22+
timeout=0,
23+
)
1124
print(result.stdout)
1225

1326
sbx.kill()

0 commit comments

Comments
 (0)