mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-21 02:04:37 +00:00
Fix docker example codex startup
This commit is contained in:
parent
6fd55fe8a8
commit
51145a7383
2 changed files with 21 additions and 17 deletions
|
|
@ -16,17 +16,11 @@ docker run --rm -p 3000:3000 \
|
||||||
-e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
|
-e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
|
||||||
-e OPENAI_API_KEY="$OPENAI_API_KEY" \
|
-e OPENAI_API_KEY="$OPENAI_API_KEY" \
|
||||||
alpine:latest sh -c "\
|
alpine:latest sh -c "\
|
||||||
apk add --no-cache curl ca-certificates libstdc++ libgcc bash && \
|
apk add --no-cache curl ca-certificates libstdc++ libgcc bash nodejs npm && \
|
||||||
curl -fsSL https://releases.rivet.dev/sandbox-agent/0.2.x/install.sh | sh && \
|
curl -fsSL https://releases.rivet.dev/sandbox-agent/0.2.x/install.sh | sh && \
|
||||||
sandbox-agent install-agent claude && \
|
|
||||||
sandbox-agent install-agent codex && \
|
|
||||||
sandbox-agent server --no-token --host 0.0.0.0 --port 3000"
|
sandbox-agent server --no-token --host 0.0.0.0 --port 3000"
|
||||||
```
|
```
|
||||||
|
|
||||||
<Note>
|
|
||||||
Alpine is required for some agent binaries that target musl libc.
|
|
||||||
</Note>
|
|
||||||
|
|
||||||
## TypeScript with dockerode
|
## TypeScript with dockerode
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
|
@ -37,17 +31,18 @@ const docker = new Docker();
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
|
|
||||||
const container = await docker.createContainer({
|
const container = await docker.createContainer({
|
||||||
Image: "alpine:latest",
|
Image: "node:22-bookworm-slim",
|
||||||
Cmd: ["sh", "-c", [
|
Cmd: ["sh", "-c", [
|
||||||
"apk add --no-cache curl ca-certificates libstdc++ libgcc bash",
|
"apt-get update",
|
||||||
|
"DEBIAN_FRONTEND=noninteractive apt-get install -y curl ca-certificates bash libstdc++6",
|
||||||
|
"rm -rf /var/lib/apt/lists/*",
|
||||||
"curl -fsSL https://releases.rivet.dev/sandbox-agent/0.2.x/install.sh | sh",
|
"curl -fsSL https://releases.rivet.dev/sandbox-agent/0.2.x/install.sh | sh",
|
||||||
"sandbox-agent install-agent claude",
|
|
||||||
"sandbox-agent install-agent codex",
|
|
||||||
`sandbox-agent server --no-token --host 0.0.0.0 --port ${PORT}`,
|
`sandbox-agent server --no-token --host 0.0.0.0 --port ${PORT}`,
|
||||||
].join(" && ")],
|
].join(" && ")],
|
||||||
Env: [
|
Env: [
|
||||||
`ANTHROPIC_API_KEY=${process.env.ANTHROPIC_API_KEY}`,
|
`ANTHROPIC_API_KEY=${process.env.ANTHROPIC_API_KEY}`,
|
||||||
`OPENAI_API_KEY=${process.env.OPENAI_API_KEY}`,
|
`OPENAI_API_KEY=${process.env.OPENAI_API_KEY}`,
|
||||||
|
`CODEX_API_KEY=${process.env.CODEX_API_KEY}`,
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
ExposedPorts: { [`${PORT}/tcp`]: {} },
|
ExposedPorts: { [`${PORT}/tcp`]: {} },
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
|
|
@ -61,7 +56,7 @@ await container.start();
|
||||||
const baseUrl = `http://127.0.0.1:${PORT}`;
|
const baseUrl = `http://127.0.0.1:${PORT}`;
|
||||||
const sdk = await SandboxAgent.connect({ baseUrl });
|
const sdk = await SandboxAgent.connect({ baseUrl });
|
||||||
|
|
||||||
const session = await sdk.createSession({ agent: "claude" });
|
const session = await sdk.createSession({ agent: "codex" });
|
||||||
await session.prompt([{ type: "text", text: "Summarize this repository." }]);
|
await session.prompt([{ type: "text", text: "Summarize this repository." }]);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
import Docker from "dockerode";
|
import Docker from "dockerode";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
import { SandboxAgent } from "sandbox-agent";
|
import { SandboxAgent } from "sandbox-agent";
|
||||||
import { detectAgent, buildInspectorUrl } from "@sandbox-agent/example-shared";
|
import { detectAgent, buildInspectorUrl } from "@sandbox-agent/example-shared";
|
||||||
|
|
||||||
const IMAGE = "alpine:latest";
|
const IMAGE = "node:22-bookworm-slim";
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
|
const agent = detectAgent();
|
||||||
|
const codexAuthPath = process.env.HOME ? path.join(process.env.HOME, ".codex", "auth.json") : null;
|
||||||
|
const bindMounts = codexAuthPath && fs.existsSync(codexAuthPath)
|
||||||
|
? [`${codexAuthPath}:/root/.codex/auth.json:ro`]
|
||||||
|
: [];
|
||||||
|
|
||||||
const docker = new Docker({ socketPath: "/var/run/docker.sock" });
|
const docker = new Docker({ socketPath: "/var/run/docker.sock" });
|
||||||
|
|
||||||
|
|
@ -24,20 +31,22 @@ console.log("Starting container...");
|
||||||
const container = await docker.createContainer({
|
const container = await docker.createContainer({
|
||||||
Image: IMAGE,
|
Image: IMAGE,
|
||||||
Cmd: ["sh", "-c", [
|
Cmd: ["sh", "-c", [
|
||||||
"apk add --no-cache curl ca-certificates libstdc++ libgcc bash",
|
"apt-get update",
|
||||||
|
"DEBIAN_FRONTEND=noninteractive apt-get install -y curl ca-certificates bash libstdc++6",
|
||||||
|
"rm -rf /var/lib/apt/lists/*",
|
||||||
"curl -fsSL https://releases.rivet.dev/sandbox-agent/0.2.x/install.sh | sh",
|
"curl -fsSL https://releases.rivet.dev/sandbox-agent/0.2.x/install.sh | sh",
|
||||||
"sandbox-agent install-agent claude",
|
|
||||||
"sandbox-agent install-agent codex",
|
|
||||||
`sandbox-agent server --no-token --host 0.0.0.0 --port ${PORT}`,
|
`sandbox-agent server --no-token --host 0.0.0.0 --port ${PORT}`,
|
||||||
].join(" && ")],
|
].join(" && ")],
|
||||||
Env: [
|
Env: [
|
||||||
process.env.ANTHROPIC_API_KEY ? `ANTHROPIC_API_KEY=${process.env.ANTHROPIC_API_KEY}` : "",
|
process.env.ANTHROPIC_API_KEY ? `ANTHROPIC_API_KEY=${process.env.ANTHROPIC_API_KEY}` : "",
|
||||||
process.env.OPENAI_API_KEY ? `OPENAI_API_KEY=${process.env.OPENAI_API_KEY}` : "",
|
process.env.OPENAI_API_KEY ? `OPENAI_API_KEY=${process.env.OPENAI_API_KEY}` : "",
|
||||||
|
process.env.CODEX_API_KEY ? `CODEX_API_KEY=${process.env.CODEX_API_KEY}` : "",
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
ExposedPorts: { [`${PORT}/tcp`]: {} },
|
ExposedPorts: { [`${PORT}/tcp`]: {} },
|
||||||
HostConfig: {
|
HostConfig: {
|
||||||
AutoRemove: true,
|
AutoRemove: true,
|
||||||
PortBindings: { [`${PORT}/tcp`]: [{ HostPort: `${PORT}` }] },
|
PortBindings: { [`${PORT}/tcp`]: [{ HostPort: `${PORT}` }] },
|
||||||
|
Binds: bindMounts,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await container.start();
|
await container.start();
|
||||||
|
|
@ -45,7 +54,7 @@ await container.start();
|
||||||
const baseUrl = `http://127.0.0.1:${PORT}`;
|
const baseUrl = `http://127.0.0.1:${PORT}`;
|
||||||
|
|
||||||
const client = await SandboxAgent.connect({ baseUrl });
|
const client = await SandboxAgent.connect({ baseUrl });
|
||||||
const session = await client.createSession({ agent: detectAgent(), sessionInit: { cwd: "/root", mcpServers: [] } });
|
const session = await client.createSession({ agent, sessionInit: { cwd: "/root", mcpServers: [] } });
|
||||||
const sessionId = session.id;
|
const sessionId = session.id;
|
||||||
|
|
||||||
console.log(` UI: ${buildInspectorUrl({ baseUrl, sessionId })}`);
|
console.log(` UI: ${buildInspectorUrl({ baseUrl, sessionId })}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue