mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 07:04:48 +00:00
refactor: split daytona example into two variants
- daytona.ts (default): Installs sandbox-agent at runtime. Faster to start but installs on each run. Use for quick testing. - daytona-with-snapshot.ts: Builds custom image with sandbox-agent pre-installed. Slow first run (~2-3 min) but fast subsequent runs. Use for repeated development. Run with: pnpm start (default) or pnpm start:snapshot
This commit is contained in:
parent
387ab0840d
commit
136926b445
3 changed files with 51 additions and 7 deletions
|
|
@ -4,6 +4,7 @@
|
|||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "tsx src/daytona.ts",
|
||||
"start:snapshot": "tsx src/daytona-with-snapshot.ts",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
41
examples/daytona/src/daytona-with-snapshot.ts
Normal file
41
examples/daytona/src/daytona-with-snapshot.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Daytona, Image } from "@daytonaio/sdk";
|
||||
import { logInspectorUrl, runPrompt } from "@sandbox-agent/example-shared";
|
||||
|
||||
const daytona = new Daytona();
|
||||
|
||||
const envVars: Record<string, string> = {};
|
||||
if (process.env.ANTHROPIC_API_KEY)
|
||||
envVars.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
||||
if (process.env.OPENAI_API_KEY)
|
||||
envVars.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
||||
|
||||
// Build a custom image with sandbox-agent pre-installed (slower first run, faster subsequent runs)
|
||||
const image = Image.base("ubuntu:22.04").runCommands(
|
||||
"apt-get update && apt-get install -y curl ca-certificates",
|
||||
"curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh",
|
||||
);
|
||||
|
||||
console.log("Creating Daytona sandbox (first run builds the base image and may take a few minutes, subsequent runs are fast)...");
|
||||
const sandbox = await daytona.create({ envVars, image, autoStopInterval: 0 }, { timeout: 180 });
|
||||
|
||||
await sandbox.process.executeCommand(
|
||||
"nohup sandbox-agent server --no-token --host 0.0.0.0 --port 3000 >/tmp/sandbox-agent.log 2>&1 &",
|
||||
);
|
||||
|
||||
const baseUrl = (await sandbox.getSignedPreviewUrl(3000, 4 * 60 * 60)).url;
|
||||
logInspectorUrl({ baseUrl });
|
||||
|
||||
const cleanup = async () => {
|
||||
await sandbox.delete(60);
|
||||
process.exit(0);
|
||||
};
|
||||
process.once("SIGINT", cleanup);
|
||||
process.once("SIGTERM", cleanup);
|
||||
|
||||
// When running as root in a container, Claude requires interactive permission prompts (bypass mode is not supported). Set autoApprovePermissions: true to auto-approve,
|
||||
// or leave false for interactive prompts.
|
||||
await runPrompt({
|
||||
baseUrl,
|
||||
autoApprovePermissions: process.env.AUTO_APPROVE_PERMISSIONS === "true",
|
||||
});
|
||||
await cleanup();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Daytona, Image } from "@daytonaio/sdk";
|
||||
import { Daytona } from "@daytonaio/sdk";
|
||||
import { logInspectorUrl, runPrompt } from "@sandbox-agent/example-shared";
|
||||
|
||||
const daytona = new Daytona();
|
||||
|
|
@ -9,13 +9,15 @@ if (process.env.ANTHROPIC_API_KEY)
|
|||
if (process.env.OPENAI_API_KEY)
|
||||
envVars.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
||||
|
||||
const image = Image.base("ubuntu:22.04").runCommands(
|
||||
"apt-get update && apt-get install -y curl ca-certificates",
|
||||
"curl -fsSL https://releases.rivet.dev/sandbox-agent/0.1.3/install.sh | sh",
|
||||
);
|
||||
// Use default image and install sandbox-agent at runtime (faster startup, no snapshot build)
|
||||
console.log("Creating Daytona sandbox...");
|
||||
const sandbox = await daytona.create({ envVars, autoStopInterval: 0 });
|
||||
|
||||
console.log("Creating Daytona sandbox (first run builds the base image and may take a few minutes, subsequent runs are fast)...");
|
||||
const sandbox = await daytona.create({ envVars, image, autoStopInterval: 0 }, { timeout: 180 });
|
||||
// Install sandbox-agent and start server
|
||||
console.log("Installing sandbox-agent...");
|
||||
await sandbox.process.executeCommand(
|
||||
"curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh",
|
||||
);
|
||||
|
||||
await sandbox.process.executeCommand(
|
||||
"nohup sandbox-agent server --no-token --host 0.0.0.0 --port 3000 >/tmp/sandbox-agent.log 2>&1 &",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue