agent-neckbeard 1.1.16 → 1.1.17

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 CHANGED
@@ -8,6 +8,12 @@ The intent is simple: your production process should not run the agent. The sand
8
8
 
9
9
  This is designed to work from short-lived request handlers and long-running workers, including Vercel Functions, Hatchet workers, and Trigger.dev tasks. See `docs/CONSUMER_ENVIRONMENTS.md` before changing lifecycle, timeout, streaming, or cleanup behavior for those environments.
10
10
 
11
+ The three primary usage patterns:
12
+
13
+ - Workflows: a run-output agent runs once per background task and returns one validated output (Run-Output Agents below).
14
+ - Streaming: a persistent sandbox server emits typed progress frames while work runs (Streaming Agents below).
15
+ - Direct sandbox access: `SandboxClient` wraps E2B and Daytona behind one filesystem/command API, no agent required (Direct Sandbox Access below).
16
+
11
17
  ## What This Does
12
18
 
13
19
  You write an agent:
@@ -61,6 +67,8 @@ new Agent({
61
67
  });
62
68
  ```
63
69
 
70
+ When the right path differs between environments (for example a monorepo dev server versus a deployed worker), `resolveAgentSourceFile(candidates, { errorMessage })` returns the first candidate path that exists and falls back to the bundled agent module when running inside the sandbox.
71
+
64
72
  For Next.js/Vercel-style deployments, keep `agent-neckbeard` external to the server bundle and make sure the referenced source file is included in the production artifact:
65
73
 
66
74
  ```typescript
@@ -77,7 +85,7 @@ const nextConfig = withNeckbeardNextConfig({
77
85
  export default nextConfig;
78
86
  ```
79
87
 
80
- The helper traces files imported by those source entries by default, including package entry metadata that `deploy()` needs when it rebundles the agent at runtime. For Next 13 configs that still use `experimental.serverComponentsExternalPackages`, the helper automatically uses the matching experimental tracing fields when it sees that shape. Set `outputFileTracingRoot` when the agent source is outside the app root.
88
+ The helper traces files imported by those source entries by default, including package entry metadata that `deploy()` needs when it rebundles the agent at runtime. Set `outputFileTracingRoot` when the agent source is outside the app root.
81
89
 
82
90
  This repo tests that shape locally with `npm run test:compat:next`, which builds and runs a Dockerized Next App Router fixture without pushing to Vercel. The fixture also checks the runtime env contract, Node major, and traced standalone files so source-level tests do not mask deployment artifact problems.
83
91
 
@@ -141,9 +149,25 @@ run: async (input, ctx) => {
141
149
 
142
150
  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.
143
151
 
152
+ Run-output agents fit background workflows (Hatchet tasks, Trigger.dev jobs, queue workers). The usual shape is one sandbox per task:
153
+
154
+ ```typescript
155
+ const sandboxId = await agent.deploy({ fresh: true });
156
+
157
+ try {
158
+ const result = await agent.run(input, { sandboxId });
159
+ if (!result.ok) throw result.error;
160
+ return result.output;
161
+ } finally {
162
+ await agent.kill(sandboxId);
163
+ }
164
+ ```
165
+
166
+ `deploy({ fresh: true })` keeps concurrent tasks from sharing one cached sandbox; see Reusing Sandboxes for the caching behavior.
167
+
144
168
  ## Streaming Agents
145
169
 
146
- Use `server.handler` when you want progress frames while the sandbox work is still running:
170
+ Use `server.handler` when you want progress frames while the sandbox work is still running, such as relaying tool calls and assistant text to a UI or event log:
147
171
 
148
172
  ```typescript
149
173
  const agent = new Agent({
@@ -172,7 +196,7 @@ for await (const frame of agent.invoke({ prompt: 'hi' }, { sandboxId })) {
172
196
  }
173
197
  ```
174
198
 
175
- 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.
199
+ 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. `invoke()` also accepts an abort signal for host-side cancellation: `agent.invoke(input, { sandboxId, signal })`.
176
200
 
177
201
  ## Reusing Sandboxes
178
202
 
@@ -189,6 +213,8 @@ const result = await agent.run({ topic: 'hello' }, { sandboxId: savedSandboxId }
189
213
 
190
214
  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.
191
215
 
216
+ `deploy()` caches the sandbox on the agent instance and returns the cached ID on later calls. Use `deploy({ fresh: true })` to provision a new sandbox without touching the instance cache, which is useful when one agent instance serves concurrent runs that each need their own sandbox. The caller owns the returned sandbox ID: pass it to `run()`/`invoke()` and `kill()` it explicitly.
217
+
192
218
  ### Environment Changes with Reused Sandboxes
193
219
 
194
220
  `envs` are applied when Neckbeard creates the sandbox and starts the sandbox server. If the host app was missing a required value such as `ANTHROPIC_API_KEY` when the sandbox was created, the sandbox can remain healthy but unauthenticated even after you fix the host environment and redeploy the app.
@@ -197,26 +223,30 @@ Updating Vercel, Render, or 1Password environment variables does not mutate alre
197
223
 
198
224
  ## Direct Sandbox Access
199
225
 
200
- Use `SandboxClient` when host code needs provider-neutral filesystem or command access without running an agent invocation:
226
+ Use `SandboxClient` when host code needs provider-neutral filesystem or command access without running an agent invocation, such as staging documents into a sandbox before an agent runs or pulling artifacts out afterward:
201
227
 
202
228
  ```typescript
203
229
  import { SandboxClient } from 'agent-neckbeard';
204
230
 
205
- const sandbox = await SandboxClient.connect({
206
- provider: 'e2b',
207
- sandboxId,
208
- timeoutMs: 30 * 60 * 1000,
231
+ const sandbox = await SandboxClient.create({
232
+ provider: 'daytona',
233
+ template: 'daytona-small',
234
+ domainAllowList: '*.example.com',
235
+ autoDeleteInterval: 30,
209
236
  });
210
237
 
211
- await sandbox.makeDir('/home/user/documents');
212
- await sandbox.writeFile('/home/user/documents/input.txt', 'hello');
238
+ const documentsDir = `${sandbox.paths.homeDir}/documents`;
239
+ await sandbox.makeDir(documentsDir);
240
+ await sandbox.writeFile(`${documentsDir}/input.txt`, 'hello');
213
241
  const result = await sandbox.runCommand('ls documents', {
214
- cwd: '/home/user',
242
+ cwd: sandbox.paths.homeDir,
215
243
  timeoutMs: 60_000,
216
244
  });
245
+ const bytes = await sandbox.readFileBytes(`${documentsDir}/input.txt`);
246
+ await sandbox.kill();
217
247
  ```
218
248
 
219
- `SandboxClient.create()` and `SandboxClient.connect()` support E2B and Daytona. E2B supports `setTimeout()` for sandbox lifetime extension; providers without that lifecycle primitive throw a `ConfigurationError`.
249
+ Reconnect to an existing sandbox with `SandboxClient.connect({ provider, sandboxId })`. `create()` accepts provider-specific lifetime options: `timeoutMs` on E2B and `autoDeleteInterval` in minutes on Daytona (`-1`, the default, disables auto-delete). `sandbox.paths` exposes the same provider-neutral paths agents receive as `ctx.sandbox`. E2B supports `setTimeout()` for sandbox lifetime extension; providers without that lifecycle primitive throw a `ConfigurationError`.
220
250
 
221
251
  ## Configuration
222
252
 
@@ -239,6 +269,10 @@ new Agent({
239
269
  files?: [{ url, path }],
240
270
  claudeDir?: string,
241
271
  envs?: Record<string, string | undefined>,
272
+ build?: {
273
+ external?: string[],
274
+ autoDetectExternal?: boolean,
275
+ },
242
276
  // Run-output agents require:
243
277
  outputSchema: ZodSchema,
244
278
  run: (input, ctx) => Promise<output>,
@@ -251,7 +285,7 @@ new Agent({
251
285
  });
252
286
  ```
253
287
 
254
- 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.
288
+ 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 the sandbox user's home on Daytona (`/home/daytona` on default snapshots).
255
289
 
256
290
  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.
257
291
 
@@ -271,21 +305,17 @@ const agent = new Agent({
271
305
  });
272
306
  ```
273
307
 
274
- 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.
308
+ 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. The `build` option tunes this: `build.external` adds package globs to mark external, and `build.autoDetectExternal: false` disables the native-module auto-detection.
275
309
 
276
310
  ## Cleanup
277
311
 
278
- ```typescript
279
- const sandboxId = await agent.deploy();
312
+ Neckbeard never kills a sandbox on its own; sandboxes run until you kill them or the provider's lifetime settings expire them. Kill every sandbox you deploy, as in the workflow example above. `kill()` accepts a sandbox ID. If omitted, it kills the sandbox cached on the agent instance.
280
313
 
281
- try {
282
- const result = await agent.run(input, { sandboxId });
283
- } finally {
284
- await agent.kill(sandboxId);
285
- }
286
- ```
314
+ ## Errors
315
+
316
+ All errors extend `NeckbeardError`. `ConfigurationError` covers invalid agent config, missing provider API keys, and provider features a sandbox does not support. `DeploymentError` covers sandbox creation, dependency install, and runtime server startup failures, and includes captured server logs when the health check fails. `ValidationError` wraps input/output schema failures with the parser error as `cause`. `ExecutionError` represents agent handler failures.
287
317
 
288
- `kill()` accepts a sandbox ID. If omitted, it kills the sandbox cached on the agent instance.
318
+ `run()` never throws; it returns `{ ok: false, error }`. `invoke()` throws.
289
319
 
290
320
  ## Testing
291
321
 
package/dist/index.cjs CHANGED
@@ -327,35 +327,6 @@ function withNeckbeardNextConfig(nextConfig, options) {
327
327
  sourceFiles,
328
328
  traceSourceDependencies
329
329
  );
330
- const experimental = asRecord(nextConfig.experimental);
331
- const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
332
- if (useLegacyExperimental) {
333
- const nextExperimental = {
334
- ...experimental,
335
- serverComponentsExternalPackages: mergeStringArray(
336
- experimental.serverComponentsExternalPackages,
337
- [NECKBEARD_PACKAGE_NAME]
338
- ),
339
- outputFileTracingIncludes: mergeTracingIncludes(
340
- experimental.outputFileTracingIncludes,
341
- routeGlobs,
342
- traceIncludeFiles
343
- )
344
- };
345
- if (options.outputFileTracingRoot !== void 0) {
346
- nextExperimental.outputFileTracingRoot = options.outputFileTracingRoot;
347
- }
348
- return {
349
- ...nextConfig,
350
- experimental: nextExperimental,
351
- webpack: withNextTraceIncludeWebpack(
352
- nextConfig.webpack,
353
- sourceFiles,
354
- routeGlobs,
355
- traceSourceDependencies
356
- )
357
- };
358
- }
359
330
  const result = {
360
331
  ...nextConfig,
361
332
  serverExternalPackages: mergeStringArray(nextConfig.serverExternalPackages, [
@@ -1151,8 +1122,8 @@ var E2bSandboxHandle = class {
1151
1122
  trafficToken: this.sandbox.trafficAccessToken
1152
1123
  };
1153
1124
  }
1154
- destroy() {
1155
- return this.sandbox.kill();
1125
+ async destroy() {
1126
+ await this.sandbox.kill();
1156
1127
  }
1157
1128
  };
1158
1129
  var DaytonaSandboxHandle = class _DaytonaSandboxHandle {
package/dist/index.d.cts CHANGED
@@ -114,13 +114,6 @@ interface NeckbeardNextConfigOptions {
114
114
  * live outside the app directory.
115
115
  */
116
116
  outputFileTracingRoot?: string;
117
- /**
118
- * Force the older Next.js experimental config placement used by Next 13.
119
- *
120
- * By default this is inferred when the provided config already uses
121
- * `experimental.serverComponentsExternalPackages` or experimental tracing.
122
- */
123
- legacyExperimental?: boolean;
124
117
  }
125
118
  interface ResolveAgentSourceFileOptions {
126
119
  /** Custom error prefix when no source file candidate exists outside the sandbox runtime. */
@@ -134,7 +127,6 @@ interface ResolveAgentSourceFileOptions {
134
127
  }
135
128
  declare function resolveAgentSourceFile(candidates: string[], options?: ResolveAgentSourceFileOptions): string;
136
129
  type NextConfigObject = {
137
- experimental?: Record<string, unknown>;
138
130
  outputFileTracingIncludes?: Record<string, unknown>;
139
131
  outputFileTracingRoot?: string;
140
132
  serverExternalPackages?: string[];
@@ -182,7 +174,7 @@ interface AgentSharedConfig<TInput> {
182
174
  * Next.js route handler running from `.next/server/chunks/*.js`.
183
175
  */
184
176
  sourceFile?: string;
185
- /** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
177
+ /** OS-level dependencies to install in the sandbox. Defaults to none. */
186
178
  dependencies?: OsDependencies;
187
179
  /**
188
180
  * Files to download and initialize in the sandbox filesystem.
package/dist/index.d.ts CHANGED
@@ -114,13 +114,6 @@ interface NeckbeardNextConfigOptions {
114
114
  * live outside the app directory.
115
115
  */
116
116
  outputFileTracingRoot?: string;
117
- /**
118
- * Force the older Next.js experimental config placement used by Next 13.
119
- *
120
- * By default this is inferred when the provided config already uses
121
- * `experimental.serverComponentsExternalPackages` or experimental tracing.
122
- */
123
- legacyExperimental?: boolean;
124
117
  }
125
118
  interface ResolveAgentSourceFileOptions {
126
119
  /** Custom error prefix when no source file candidate exists outside the sandbox runtime. */
@@ -134,7 +127,6 @@ interface ResolveAgentSourceFileOptions {
134
127
  }
135
128
  declare function resolveAgentSourceFile(candidates: string[], options?: ResolveAgentSourceFileOptions): string;
136
129
  type NextConfigObject = {
137
- experimental?: Record<string, unknown>;
138
130
  outputFileTracingIncludes?: Record<string, unknown>;
139
131
  outputFileTracingRoot?: string;
140
132
  serverExternalPackages?: string[];
@@ -182,7 +174,7 @@ interface AgentSharedConfig<TInput> {
182
174
  * Next.js route handler running from `.next/server/chunks/*.js`.
183
175
  */
184
176
  sourceFile?: string;
185
- /** OS-level dependencies to install in the sandbox. Defaults to Claude Code. Set to {} to skip. */
177
+ /** OS-level dependencies to install in the sandbox. Defaults to none. */
186
178
  dependencies?: OsDependencies;
187
179
  /**
188
180
  * Files to download and initialize in the sandbox filesystem.
package/dist/index.js CHANGED
@@ -93,35 +93,6 @@ function withNeckbeardNextConfig(nextConfig, options) {
93
93
  sourceFiles,
94
94
  traceSourceDependencies
95
95
  );
96
- const experimental = asRecord(nextConfig.experimental);
97
- const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
98
- if (useLegacyExperimental) {
99
- const nextExperimental = {
100
- ...experimental,
101
- serverComponentsExternalPackages: mergeStringArray(
102
- experimental.serverComponentsExternalPackages,
103
- [NECKBEARD_PACKAGE_NAME]
104
- ),
105
- outputFileTracingIncludes: mergeTracingIncludes(
106
- experimental.outputFileTracingIncludes,
107
- routeGlobs,
108
- traceIncludeFiles
109
- )
110
- };
111
- if (options.outputFileTracingRoot !== void 0) {
112
- nextExperimental.outputFileTracingRoot = options.outputFileTracingRoot;
113
- }
114
- return {
115
- ...nextConfig,
116
- experimental: nextExperimental,
117
- webpack: withNextTraceIncludeWebpack(
118
- nextConfig.webpack,
119
- sourceFiles,
120
- routeGlobs,
121
- traceSourceDependencies
122
- )
123
- };
124
- }
125
96
  const result = {
126
97
  ...nextConfig,
127
98
  serverExternalPackages: mergeStringArray(nextConfig.serverExternalPackages, [
@@ -917,8 +888,8 @@ var E2bSandboxHandle = class {
917
888
  trafficToken: this.sandbox.trafficAccessToken
918
889
  };
919
890
  }
920
- destroy() {
921
- return this.sandbox.kill();
891
+ async destroy() {
892
+ await this.sandbox.kill();
922
893
  }
923
894
  };
924
895
  var DaytonaSandboxHandle = class _DaytonaSandboxHandle {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-neckbeard",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "description": "Deploy AI agents to E2B and Daytona sandboxes",
5
5
  "type": "module",
6
6
  "exports": {