mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 22:03:48 +00:00
fix(examples): use SDK to install agents instead of CLI command
This commit is contained in:
parent
b98c848965
commit
8af152f0b3
7 changed files with 94 additions and 57 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { Sandbox } from "@e2b/code-interpreter";
|
||||
import { SandboxAgent } from "sandbox-agent";
|
||||
import { logInspectorUrl, runPrompt } from "@sandbox-agent/example-shared";
|
||||
|
||||
if (!process.env.E2B_API_KEY || (!process.env.OPENAI_API_KEY && !process.env.ANTHROPIC_API_KEY)) {
|
||||
|
|
@ -11,8 +12,6 @@ const run = (cmd: string) => sandbox.commands.run(cmd);
|
|||
|
||||
console.log("Installing sandbox-agent...");
|
||||
await run("curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh");
|
||||
await run("sandbox-agent install-agent claude");
|
||||
await run("sandbox-agent install-agent codex");
|
||||
|
||||
console.log("Starting server...");
|
||||
await sandbox.commands.run("sandbox-agent server --no-token --host 0.0.0.0 --port 3000", { background: true });
|
||||
|
|
@ -20,6 +19,22 @@ await sandbox.commands.run("sandbox-agent server --no-token --host 0.0.0.0 --por
|
|||
const baseUrl = `https://${sandbox.getHost(3000)}`;
|
||||
logInspectorUrl({ baseUrl });
|
||||
|
||||
// Wait for server to be ready
|
||||
console.log("Waiting for server...");
|
||||
const client = await SandboxAgent.connect({ baseUrl });
|
||||
for (let i = 0; i < 30; i++) {
|
||||
try {
|
||||
await client.getHealth();
|
||||
break;
|
||||
} catch {
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Installing agents...");
|
||||
await client.installAgent("claude");
|
||||
await client.installAgent("codex");
|
||||
|
||||
const cleanup = async () => {
|
||||
console.log("Cleaning up...");
|
||||
await sandbox.kill();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue