@papercraneai/sandbox-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # Sandbox Agent
2
+
3
+ An Express server that runs the Claude Agent SDK inside Daytona sandboxes, providing AI-assisted development capabilities.
4
+
5
+ ## Overview
6
+
7
+ This agent runs inside a Daytona sandbox and exposes HTTP endpoints for chat interactions. It uses the Claude Agent SDK with built-in tools (Read, Write, Edit, Glob, Grep, Bash) to help users build applications.
8
+
9
+ ## Building the Daytona Snapshot
10
+
11
+ ### Prerequisites
12
+
13
+ 1. Install the Daytona CLI:
14
+ ```bash
15
+ curl -sf https://download.daytona.io/daytona/install.sh | bash
16
+ ```
17
+
18
+ 2. Authenticate:
19
+ ```bash
20
+ daytona login
21
+ ```
22
+
23
+ ### Creating the Snapshot
24
+
25
+ From this directory (`papercrane/apps/sandbox-agent`):
26
+
27
+ ```bash
28
+ daytona snapshot create <snapshot-name> --dockerfile ./Dockerfile --context .
29
+ ```
30
+
31
+ **Important:** The `--context .` flag is required. Without it, Daytona only includes files explicitly referenced in COPY commands and may miss the `src/` directory.
32
+
33
+ ### Monorepo Considerations
34
+
35
+ This project lives in a monorepo with npm workspaces. The `package-lock.json` must be generated standalone (outside the workspace) for the Docker build to work:
36
+
37
+ ```bash
38
+ # Copy to temp directory
39
+ cp -r . /tmp/sandbox-agent-standalone
40
+ cd /tmp/sandbox-agent-standalone
41
+
42
+ # Generate lock file
43
+ npm install
44
+
45
+ # Copy back
46
+ cp package-lock.json /path/to/papercrane/apps/sandbox-agent/
47
+ ```
48
+
49
+ ## Claude Agent SDK Usage
50
+
51
+ ### Key Options
52
+
53
+ ```typescript
54
+ import { query } from "@anthropic-ai/claude-agent-sdk"
55
+
56
+ for await (const msg of query({
57
+ prompt: message,
58
+ options: {
59
+ systemPrompt: "Your system prompt",
60
+ maxTurns: 15,
61
+ cwd: "/path/to/project", // NOT workingDirectory
62
+ permissionMode: "bypassPermissions",
63
+ allowDangerouslySkipPermissions: true, // Required when bypassing
64
+ allowedTools: ["Read", "Write", "Edit", "Glob", "Grep", "Bash"]
65
+ }
66
+ })) {
67
+ // Handle streaming messages
68
+ }
69
+ ```
70
+
71
+ ### Common Pitfalls
72
+
73
+ 1. **`workingDirectory` vs `cwd`**: The SDK uses `cwd` (not `workingDirectory`) to set the working directory.
74
+
75
+ 2. **`allowDangerouslySkipPermissions`**: When using `permissionMode: "bypassPermissions"`, you must also set `allowDangerouslySkipPermissions: true`. This is a safety measure to ensure intentional bypassing.
76
+
77
+ 3. **Built-in Tools**: The SDK provides these built-in tools - no need to implement them yourself:
78
+ - `Read` - Read files
79
+ - `Write` - Write files
80
+ - `Edit` - Edit files with find/replace
81
+ - `Glob` - Find files by pattern
82
+ - `Grep` - Search file contents
83
+ - `Bash` - Execute shell commands
84
+
85
+ ## API Endpoints
86
+
87
+ ### `GET /health`
88
+ Health check endpoint.
89
+
90
+ ### `POST /chat`
91
+ Streaming chat endpoint (SSE). Send a message and receive streaming responses.
92
+
93
+ ```json
94
+ { "message": "Create a hello world component" }
95
+ ```
96
+
97
+ ### `POST /chat/sync`
98
+ Synchronous chat endpoint. Waits for completion and returns all messages.
99
+
100
+ ## Environment Variables
101
+
102
+ - `PORT` - Server port (default: 3001)
103
+ - `PROJECT_DIR` - Working directory for the agent (default: /home/user/project)
104
+ - `ANTHROPIC_API_KEY` - Required for Claude API access (injected at sandbox creation time, not in the snapshot)
105
+
106
+ ## Architecture
107
+
108
+ ```
109
+ ┌─────────────────────────────────────────────────────────┐
110
+ │ Daytona Sandbox │
111
+ │ ┌─────────────────┐ ┌─────────────────────────┐ │
112
+ │ │ sandbox-agent │ │ Vite Dev Server │ │
113
+ │ │ (port 3001) │ │ (port 3000) │ │
114
+ │ │ │ │ │ │
115
+ │ │ Claude Agent │────▶│ /tmp/project │ │
116
+ │ │ SDK + Tools │ │ (React app) │ │
117
+ │ └─────────────────┘ └─────────────────────────┘ │
118
+ └─────────────────────────────────────────────────────────┘
119
+ │ │
120
+ │ Preview Token │ Preview Token
121
+ ▼ ▼
122
+ ┌─────────────────────────────────────────────────────────┐
123
+ │ AuthLLM Server │
124
+ │ - Proxies chat requests to sandbox-agent │
125
+ │ - Manages sandbox lifecycle │
126
+ │ - Handles authentication │
127
+ └─────────────────────────────────────────────────────────┘
128
+ ```
129
+
130
+ ## Security
131
+
132
+ - Sandboxes are created with `public: false`
133
+ - All requests to the sandbox require a Daytona preview token (`X-Daytona-Preview-Token` header)
134
+ - The `ANTHROPIC_API_KEY` is injected at runtime, not baked into the snapshot
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};