agent-neckbeard 1.1.7 → 1.1.9
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 +114 -53
- package/dist/index.cjs +360 -475
- package/dist/index.d.cts +49 -75
- package/dist/index.d.ts +49 -75
- package/dist/index.js +310 -465
- package/dist/{invoke-client-Y3NPRFEE.js → invoke-client-WYMFPR3F.js} +45 -11
- package/dist/runtime/server.js +163 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,31 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
# neckbeard
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Neckbeard deploys your agent code into an E2B or Daytona sandbox and runs it behind a small persistent HTTP server inside that sandbox.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
This creates an obvious problem: do you really want that process running on your production server?
|
|
10
|
-
|
|
11
|
-
Anthropic's answer is no. Their [hosting docs](https://docs.claude.com/en/docs/agent-sdk/hosting) say you should run the entire agent inside a sandbox. Not just intercept the dangerous tool calls—put the whole thing in a container where it can't escape.
|
|
12
|
-
|
|
13
|
-
That sounds simple. It's not.
|
|
14
|
-
|
|
15
|
-
## The Plumbing Problem
|
|
16
|
-
|
|
17
|
-
Sandboxes like E2B give you a fresh Linux container. Your agent code lives in your repo. Bridging these two worlds is surprisingly annoying.
|
|
18
|
-
|
|
19
|
-
First, you have to get your code into the sandbox. You could bake it into a custom template, but then you're rebuilding templates every time you change a line. You could git clone on boot, but that's slow and requires auth. You could bundle and upload at runtime, which works, but now you're writing bundler configs.
|
|
20
|
-
|
|
21
|
-
Then you have to pass input. How do you get the user's prompt into a process running inside a sandbox? CLI arguments require escaping and have length limits. Environment variables have size limits. Writing to a file works, but adds boilerplate.
|
|
22
|
-
|
|
23
|
-
The worst part is output. When you run `sandbox.exec("node agent.js")`, you get back everything the process printed. SDK logs, debug output, streaming tokens, and somewhere in there, your actual result. Good luck parsing that reliably.
|
|
24
|
-
|
|
25
|
-
So you end up writing results to a file, reading it back, parsing JSON, validating the shape, handling errors. Every team building sandboxed agents writes some version of this plumbing. It's tedious.
|
|
7
|
+
The intent is simple: your production process should not run the agent. The sandbox runs the agent, keeps its filesystem/process state, and exposes a private `/invoke` endpoint that neckbeard calls for each turn.
|
|
26
8
|
|
|
27
9
|
## What This Does
|
|
28
10
|
|
|
29
|
-
|
|
11
|
+
You write an agent:
|
|
30
12
|
|
|
31
13
|
```typescript
|
|
32
14
|
import { Agent } from 'agent-neckbeard';
|
|
@@ -56,14 +38,17 @@ const agent = new Agent({
|
|
|
56
38
|
return JSON.parse(message.result ?? '{}');
|
|
57
39
|
}
|
|
58
40
|
}
|
|
41
|
+
throw new Error('Claude did not return a result');
|
|
59
42
|
},
|
|
60
43
|
});
|
|
61
44
|
|
|
62
|
-
const sandboxId = await agent.deploy();
|
|
63
|
-
const result = await agent.run({ topic: 'TypeScript generics' });
|
|
45
|
+
const sandboxId = await agent.deploy();
|
|
46
|
+
const result = await agent.run({ topic: 'TypeScript generics' }, { sandboxId });
|
|
64
47
|
```
|
|
65
48
|
|
|
66
|
-
`deploy()` bundles your
|
|
49
|
+
`deploy()` bundles your agent, uploads `agent.mjs` and a TypeScript runtime server to the sandbox, starts `node server.mjs`, waits for `/health`, and returns the sandbox ID.
|
|
50
|
+
|
|
51
|
+
`run()` validates input locally, POSTs it to the sandbox server, reads SSE harness events, validates the final output, and returns the existing `{ ok, executionId, output | error }` result shape.
|
|
67
52
|
|
|
68
53
|
## Setup
|
|
69
54
|
|
|
@@ -74,48 +59,122 @@ npm install agent-neckbeard
|
|
|
74
59
|
```bash
|
|
75
60
|
export E2B_API_KEY=your-key
|
|
76
61
|
export DAYTONA_API_KEY=your-key
|
|
77
|
-
export ANTHROPIC_API_KEY=your-key
|
|
62
|
+
export ANTHROPIC_API_KEY=your-key
|
|
78
63
|
```
|
|
79
64
|
|
|
80
|
-
Pick the sandbox backend explicitly with `sandbox.provider`.
|
|
65
|
+
Pick the sandbox backend explicitly with `sandbox.provider`. The public `sandbox.template` field maps to an E2B template or a Daytona snapshot.
|
|
81
66
|
|
|
82
|
-
##
|
|
67
|
+
## Run-Output Agents
|
|
83
68
|
|
|
84
|
-
|
|
69
|
+
Use `run` when each invocation should produce one validated output:
|
|
85
70
|
|
|
86
71
|
```typescript
|
|
87
72
|
new Agent({
|
|
88
73
|
sandbox: {
|
|
89
|
-
provider: 'e2b'
|
|
90
|
-
template:
|
|
74
|
+
provider: 'e2b',
|
|
75
|
+
template: 'code-interpreter-v1',
|
|
91
76
|
},
|
|
92
|
-
inputSchema:
|
|
93
|
-
outputSchema:
|
|
94
|
-
run: (input, ctx) =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
77
|
+
inputSchema: z.object({ prompt: z.string() }),
|
|
78
|
+
outputSchema: z.object({ answer: z.string() }),
|
|
79
|
+
run: async (input, ctx) => {
|
|
80
|
+
ctx.logger.info(`Handling ${ctx.executionId}`);
|
|
81
|
+
return { answer: input.prompt.toUpperCase() };
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The `run` handler receives a context object with `executionId`, `AbortSignal`, environment variables, sandbox paths, and a logger:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
run: async (input, ctx) => {
|
|
90
|
+
const notesPath = `${ctx.sandbox.homeDir}/data/notes.txt`;
|
|
91
|
+
const cwd = ctx.sandbox.agentDir;
|
|
92
|
+
// ...
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Use `ctx.sandbox.homeDir` and `ctx.sandbox.agentDir` instead of hardcoding `/home/user` if you want the same agent code to work on both providers.
|
|
97
|
+
|
|
98
|
+
## Streaming Agents
|
|
99
|
+
|
|
100
|
+
Use `server.handler` when you want progress frames while the sandbox work is still running:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const agent = new Agent({
|
|
104
|
+
sandbox: {
|
|
105
|
+
provider: 'daytona',
|
|
106
|
+
template: 'daytona-small',
|
|
99
107
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
inputSchema: z.object({ prompt: z.string() }),
|
|
109
|
+
server: {
|
|
110
|
+
frameSchema: z.object({
|
|
111
|
+
type: z.enum(['status', 'token', 'done']),
|
|
112
|
+
text: z.string().optional(),
|
|
113
|
+
}),
|
|
114
|
+
handler: async ({ input, emit }) => {
|
|
115
|
+
await emit({ type: 'status', text: `Starting ${input.prompt}` });
|
|
116
|
+
await emit({ type: 'token', text: 'hello' });
|
|
117
|
+
await emit({ type: 'done' });
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const sandboxId = await agent.deploy();
|
|
123
|
+
|
|
124
|
+
for await (const frame of agent.invoke({ prompt: 'hi' }, { sandboxId })) {
|
|
125
|
+
console.log(frame);
|
|
126
|
+
}
|
|
104
127
|
```
|
|
105
128
|
|
|
106
|
-
|
|
129
|
+
Internally, streaming uses Server-Sent Events from the sandbox `/invoke` endpoint. Neckbeard wraps user frames in harness events so errors, completion, and run-output results are handled consistently.
|
|
130
|
+
|
|
131
|
+
## Reusing Sandboxes
|
|
132
|
+
|
|
133
|
+
Persist the sandbox ID if another process needs to call the same running sandbox server:
|
|
107
134
|
|
|
108
135
|
```typescript
|
|
109
136
|
const sandboxId = await agent.deploy();
|
|
110
|
-
|
|
111
|
-
|
|
137
|
+
await saveSandboxId(sandboxId);
|
|
138
|
+
|
|
139
|
+
// Later:
|
|
140
|
+
const savedSandboxId = await loadSandboxId();
|
|
141
|
+
const result = await agent.run({ topic: 'hello' }, { sandboxId: savedSandboxId });
|
|
112
142
|
```
|
|
113
143
|
|
|
114
|
-
|
|
144
|
+
Neckbeard rehydrates the sandbox endpoint and provider traffic token from the sandbox ID using the configured provider SDK. E2B traffic tokens are sent as the `e2b-traffic-access-token` header. Daytona preview tokens are sent as the `DAYTONA_SANDBOX_AUTH_KEY` query parameter. Consumers only need to store the sandbox ID and configure the same provider/API key in the process that reconnects.
|
|
145
|
+
|
|
146
|
+
## Configuration
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
new Agent({
|
|
150
|
+
sandbox: {
|
|
151
|
+
provider: 'e2b' | 'daytona',
|
|
152
|
+
template: string,
|
|
153
|
+
},
|
|
154
|
+
inputSchema: ZodSchema,
|
|
155
|
+
outputSchema?: ZodSchema,
|
|
156
|
+
run?: (input, ctx) => Promise<output>,
|
|
157
|
+
server?: {
|
|
158
|
+
port?: number,
|
|
159
|
+
frameSchema: ZodSchema,
|
|
160
|
+
handler: ({ input, ctx, signal, emit }) => Promise<void>,
|
|
161
|
+
},
|
|
162
|
+
maxDuration?: number,
|
|
163
|
+
dependencies?: {
|
|
164
|
+
apt?: string[],
|
|
165
|
+
commands?: string[],
|
|
166
|
+
},
|
|
167
|
+
files?: [{ url, path }],
|
|
168
|
+
claudeDir?: string,
|
|
169
|
+
envs?: Record<string, string | undefined>,
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The `files` option downloads files into the sandbox before the server starts. Relative paths resolve from the sandbox home directory: `/home/user` on E2B and `/home/daytona` on Daytona.
|
|
115
174
|
|
|
116
175
|
The `claudeDir` option uploads a local `.claude/` directory to the sandbox, enabling Claude Agent SDK skills. Point it at a directory containing `.claude/skills/*/SKILL.md` files.
|
|
117
176
|
|
|
118
|
-
The `envs` option passes environment variables to the sandbox.
|
|
177
|
+
The `envs` option passes environment variables to the sandbox. Undefined values are filtered out:
|
|
119
178
|
|
|
120
179
|
```typescript
|
|
121
180
|
const agent = new Agent({
|
|
@@ -131,19 +190,21 @@ const agent = new Agent({
|
|
|
131
190
|
});
|
|
132
191
|
```
|
|
133
192
|
|
|
134
|
-
Some packages
|
|
193
|
+
Some packages cannot be bundled because they spawn child processes or have native modules. The Claude Agent SDK is like this. These packages are automatically marked external and installed with npm in the sandbox.
|
|
135
194
|
|
|
136
|
-
|
|
195
|
+
## Cleanup
|
|
137
196
|
|
|
138
197
|
```typescript
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
198
|
+
const sandboxId = await agent.deploy();
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const result = await agent.run(input, { sandboxId });
|
|
202
|
+
} finally {
|
|
203
|
+
await agent.kill(sandboxId);
|
|
143
204
|
}
|
|
144
205
|
```
|
|
145
206
|
|
|
146
|
-
|
|
207
|
+
`kill()` accepts a sandbox ID. If omitted, it kills the sandbox cached on the agent instance.
|
|
147
208
|
|
|
148
209
|
## Testing
|
|
149
210
|
|