agent-neckbeard 1.1.17 → 1.1.18

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/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 1.1.18 - 2026-08-05
4
+
5
+ - Add harness-neutral `localDirectories` uploads beneath the sandbox agent directory, with recursive byte-preserving copies and deployment preflight validation.
6
+ - Deprecate `claudeDir` in favor of an explicit `localDirectories` mapping while keeping its `.claude` upload behavior backward compatible.
package/README.md CHANGED
@@ -77,6 +77,10 @@ import { withNeckbeardNextConfig } from 'agent-neckbeard';
77
77
 
78
78
  const nextConfig = withNeckbeardNextConfig({
79
79
  // your existing Next config
80
+ outputFileTracingIncludes: {
81
+ // Include every localDirectories source tree used by deploy().
82
+ '/api/my-agent': ['./packages/my-agent/.agents/**/*'],
83
+ },
80
84
  }, {
81
85
  routeGlob: '/api/my-agent',
82
86
  sourceFiles: ['./packages/my-agent/src/agent.ts'],
@@ -85,7 +89,7 @@ const nextConfig = withNeckbeardNextConfig({
85
89
  export default nextConfig;
86
90
  ```
87
91
 
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.
92
+ 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. It preserves and merges existing `outputFileTracingIncludes`, such as the `.agents/**/*` entry above. A `localDirectories.source` is read by the deployed process, so its complete tree must be included in the production function artifact. Set `outputFileTracingRoot` when the agent source or local directory is outside the app root.
89
93
 
90
94
  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.
91
95
 
@@ -251,6 +255,8 @@ Reconnect to an existing sandbox with `SandboxClient.connect({ provider, sandbox
251
255
  ## Configuration
252
256
 
253
257
  ```typescript
258
+ import type { LocalDirectoryUpload } from 'agent-neckbeard';
259
+
254
260
  new Agent({
255
261
  sandbox: {
256
262
  provider: 'e2b' | 'daytona',
@@ -267,7 +273,8 @@ new Agent({
267
273
  commands?: string[],
268
274
  },
269
275
  files?: [{ url, path }],
270
- claudeDir?: string,
276
+ localDirectories?: LocalDirectoryUpload[],
277
+ claudeDir?: string, // deprecated; use localDirectories
271
278
  envs?: Record<string, string | undefined>,
272
279
  build?: {
273
280
  external?: string[],
@@ -287,7 +294,50 @@ new Agent({
287
294
 
288
295
  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).
289
296
 
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.
297
+ `LocalDirectoryUpload` is exported by the package and has this shape:
298
+
299
+ ```typescript
300
+ interface LocalDirectoryUpload {
301
+ source: string;
302
+ destination: string;
303
+ }
304
+ ```
305
+
306
+ `localDirectories` recursively copies consumer-selected local directories beneath `ctx.sandbox.agentDir` during `deploy()`. Relative sources resolve from the deploying process's current working directory; absolute sources are also supported. Nested paths and dotfiles are included, text and binary files retain their exact bytes, and parent directories are created as needed. Empty directories are not preserved.
307
+
308
+ Each `destination` is relative to the sandbox agent directory. For example, this Pi-oriented configuration produces `<sandbox agentDir>/.agents/skills/...` on both E2B and Daytona:
309
+
310
+ ```typescript
311
+ const agent = new Agent({
312
+ localDirectories: [
313
+ {
314
+ source: './packages/my-agent/.agents',
315
+ destination: '.agents',
316
+ },
317
+ ],
318
+ // ...run-output or streaming agent configuration
319
+ });
320
+ ```
321
+
322
+ Copying skills to `.agents/skills` does not guarantee that Pi or another harness will discover them automatically. If the harness working directory is elsewhere, pass `${ctx.sandbox.agentDir}/.agents/skills` to it as an explicit skill path. Neckbeard does not detect harnesses or change their discovery and trust settings.
323
+
324
+ Before creating a sandbox, Neckbeard validates and enumerates every local upload. A source must exist and be a directory. `localDirectories` rejects symbolic links anywhere in a source tree, with the local path in the error. Empty destinations, `.`, absolute destinations, traversal outside the agent directory, and duplicate sandbox targets are rejected with `ConfigurationError`; this includes collisions with another entry or with `claudeDir`.
325
+
326
+ For Next.js/Vercel and other bundled deployment environments, ensure each source tree is present in the runtime artifact. Include it with `withNeckbeardNextConfig` as shown above, with raw `outputFileTracingIncludes`, or with the equivalent artifact-inclusion setting for the host framework.
327
+
328
+ `claudeDir` is deprecated but remains functional for backward compatibility. It uploads the contents of a local `.claude` directory to `<sandbox agentDir>/.claude`, preserving existing Claude Agent SDK behavior. Replace it with an explicit `localDirectories` mapping:
329
+
330
+ ```typescript
331
+ const agent = new Agent({
332
+ localDirectories: [
333
+ {
334
+ source: './my-project/.claude',
335
+ destination: '.claude',
336
+ },
337
+ ],
338
+ // ...agent configuration
339
+ });
340
+ ```
291
341
 
292
342
  The `envs` option passes environment variables to the sandbox. Undefined values are filtered out:
293
343
 
package/dist/index.cjs CHANGED
@@ -744,6 +744,53 @@ function requireSchemaLike(name, value) {
744
744
  }
745
745
  return value;
746
746
  }
747
+ function normalizeLocalDirectoryDestination(destination, name) {
748
+ if (destination.trim() === "") {
749
+ throw new ConfigurationError(`${name}.destination must be a non-empty relative path.`);
750
+ }
751
+ if (destination.includes("\0")) {
752
+ throw new ConfigurationError(`${name}.destination must not contain null bytes.`);
753
+ }
754
+ const sandboxPath = destination.replace(/\\/g, "/");
755
+ if ((0, import_node_path.isAbsolute)(destination) || import_node_path.posix.isAbsolute(sandboxPath) || import_node_path.win32.isAbsolute(destination)) {
756
+ throw new ConfigurationError(
757
+ `${name}.destination must be relative to the sandbox agent directory.`
758
+ );
759
+ }
760
+ if (sandboxPath.split("/").includes("..")) {
761
+ throw new ConfigurationError(
762
+ `${name}.destination must not traverse outside the sandbox agent directory.`
763
+ );
764
+ }
765
+ const normalized = import_node_path.posix.normalize(sandboxPath);
766
+ if (normalized === ".") {
767
+ throw new ConfigurationError(`${name}.destination must not be ".".`);
768
+ }
769
+ return normalized;
770
+ }
771
+ function validateLocalDirectoriesConfig(value) {
772
+ if (value === void 0) return;
773
+ if (!Array.isArray(value)) {
774
+ throw new ConfigurationError("localDirectories must be an array when provided.");
775
+ }
776
+ for (const [index, entry] of value.entries()) {
777
+ const name = `localDirectories[${index}]`;
778
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
779
+ throw new ConfigurationError(`${name} must be an object.`);
780
+ }
781
+ const candidate = entry;
782
+ if (typeof candidate.source !== "string" || candidate.source.trim() === "") {
783
+ throw new ConfigurationError(`${name}.source must be a non-empty string.`);
784
+ }
785
+ if (candidate.source.includes("\0")) {
786
+ throw new ConfigurationError(`${name}.source must not contain null bytes.`);
787
+ }
788
+ if (typeof candidate.destination !== "string") {
789
+ throw new ConfigurationError(`${name}.destination must be a string.`);
790
+ }
791
+ normalizeLocalDirectoryDestination(candidate.destination, name);
792
+ }
793
+ }
747
794
  function validateAgentConfig(config) {
748
795
  if (!config || typeof config !== "object") {
749
796
  throw new ConfigurationError("Agent config must be an object.");
@@ -764,6 +811,7 @@ function validateAgentConfig(config) {
764
811
  if (config.sourceFile !== void 0 && (typeof config.sourceFile !== "string" || config.sourceFile.trim() === "")) {
765
812
  throw new ConfigurationError("sourceFile must be a non-empty string when provided.");
766
813
  }
814
+ validateLocalDirectoriesConfig(config.localDirectories);
767
815
  if (isServerAgentConfig(config)) {
768
816
  if ("run" in config && typeof config.run === "function") {
769
817
  throw new ConfigurationError("Agent config must use either run or server.handler, not both.");
@@ -1382,30 +1430,131 @@ function resolveSourceFile(sourceFile) {
1382
1430
  }
1383
1431
  return resolved;
1384
1432
  }
1385
- function readDirectoryRecursively(dirPath) {
1433
+ function localPathStats(localPath, upload, isSourceRoot = false) {
1434
+ let stats;
1435
+ try {
1436
+ stats = (0, import_node_fs.lstatSync)(localPath);
1437
+ } catch (error) {
1438
+ const code = error.code;
1439
+ const detail = isSourceRoot && code === "ENOENT" ? "source does not exist" : "could not read local path";
1440
+ throw new ConfigurationError(
1441
+ `${upload.name} ${detail}: ${localPath} (${errorMessage(error)})`
1442
+ );
1443
+ }
1444
+ if (!stats.isSymbolicLink()) return stats;
1445
+ if (upload.rejectSymlinks) {
1446
+ throw new ConfigurationError(
1447
+ `${upload.name} source tree contains a symbolic link: ${localPath}`
1448
+ );
1449
+ }
1450
+ try {
1451
+ return (0, import_node_fs.statSync)(localPath);
1452
+ } catch (error) {
1453
+ throw new ConfigurationError(
1454
+ `${upload.name} could not follow legacy symbolic link: ${localPath} (${errorMessage(error)})`
1455
+ );
1456
+ }
1457
+ }
1458
+ function readConfiguredLocalDirectory(upload) {
1459
+ const rootPath = (0, import_node_path.resolve)(process.cwd(), upload.source);
1460
+ const rootStats = localPathStats(rootPath, upload, true);
1461
+ if (!rootStats.isDirectory()) {
1462
+ throw new ConfigurationError(`${upload.name}.source must be a directory: ${rootPath}`);
1463
+ }
1464
+ const destination = normalizeLocalDirectoryDestination(upload.destination, upload.name);
1386
1465
  const files = [];
1387
- function walkDir(currentPath) {
1388
- const entries = (0, import_node_fs.readdirSync)(currentPath);
1466
+ function walk(currentPath) {
1467
+ let entries;
1468
+ try {
1469
+ entries = (0, import_node_fs.readdirSync)(currentPath).sort((left, right) => left.localeCompare(right));
1470
+ } catch (error) {
1471
+ throw new ConfigurationError(
1472
+ `${upload.name} could not read local directory: ${currentPath} (${errorMessage(error)})`
1473
+ );
1474
+ }
1389
1475
  for (const entry of entries) {
1390
- const fullPath = (0, import_node_path.join)(currentPath, entry);
1391
- const stat = (0, import_node_fs.statSync)(fullPath);
1392
- if (stat.isDirectory()) {
1393
- walkDir(fullPath);
1394
- } else if (stat.isFile()) {
1395
- const relPath = (0, import_node_path.relative)(dirPath, fullPath);
1396
- const isBinary = /\.(png|jpg|jpeg|gif|ico|pdf|zip|tar|gz|bin|exe|dll|so|dylib|wasm)$/i.test(entry);
1397
- if (isBinary) {
1398
- const buffer = (0, import_node_fs.readFileSync)(fullPath);
1399
- const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
1400
- files.push({ relativePath: relPath, content: arrayBuffer });
1401
- } else {
1402
- files.push({ relativePath: relPath, content: (0, import_node_fs.readFileSync)(fullPath, "utf-8") });
1403
- }
1476
+ const localPath = (0, import_node_path.join)(currentPath, entry);
1477
+ const stats = localPathStats(localPath, upload);
1478
+ if (stats.isDirectory()) {
1479
+ walk(localPath);
1480
+ continue;
1481
+ }
1482
+ if (!stats.isFile()) {
1483
+ throw new ConfigurationError(
1484
+ `${upload.name} source tree contains an unsupported filesystem entry: ${localPath}`
1485
+ );
1404
1486
  }
1487
+ const relativePath = (0, import_node_path.relative)(rootPath, localPath).split(import_node_path.sep).join("/");
1488
+ const targetPath = import_node_path.posix.join(destination, relativePath);
1489
+ let content;
1490
+ try {
1491
+ content = (0, import_node_fs.readFileSync)(localPath);
1492
+ } catch (error) {
1493
+ throw new ConfigurationError(
1494
+ `${upload.name} could not read local file: ${localPath} (${errorMessage(error)})`
1495
+ );
1496
+ }
1497
+ files.push({ localPath, targetPath, content });
1498
+ }
1499
+ }
1500
+ walk(rootPath);
1501
+ return { rootPath, files };
1502
+ }
1503
+ function prepareLocalDirectoryUploads(localDirectories, claudeDir) {
1504
+ const uploads = localDirectories.map((entry, index) => ({
1505
+ ...entry,
1506
+ name: `localDirectories[${index}]`,
1507
+ rejectSymlinks: true,
1508
+ preserveRootDirectory: false
1509
+ }));
1510
+ if (claudeDir) {
1511
+ uploads.push({
1512
+ source: claudeDir,
1513
+ destination: ".claude",
1514
+ name: "claudeDir",
1515
+ rejectSymlinks: false,
1516
+ preserveRootDirectory: true
1517
+ });
1518
+ }
1519
+ const filesByTarget = /* @__PURE__ */ new Map();
1520
+ const requiredDirectories = /* @__PURE__ */ new Set();
1521
+ for (const upload of uploads) {
1522
+ const prepared = readConfiguredLocalDirectory(upload);
1523
+ const destination = normalizeLocalDirectoryDestination(upload.destination, upload.name);
1524
+ if (upload.preserveRootDirectory) {
1525
+ requiredDirectories.add(destination);
1526
+ }
1527
+ for (const file of prepared.files) {
1528
+ const existing = filesByTarget.get(file.targetPath);
1529
+ if (existing) {
1530
+ throw new ConfigurationError(
1531
+ `Duplicate sandbox target "${file.targetPath}" from local files "${existing.localPath}" and "${file.localPath}".`
1532
+ );
1533
+ }
1534
+ filesByTarget.set(file.targetPath, file);
1405
1535
  }
1406
1536
  }
1407
- walkDir(dirPath);
1408
- return files;
1537
+ for (const file of filesByTarget.values()) {
1538
+ let parent = import_node_path.posix.dirname(file.targetPath);
1539
+ while (parent !== ".") {
1540
+ const parentFile = filesByTarget.get(parent);
1541
+ if (parentFile) {
1542
+ throw new ConfigurationError(
1543
+ `Sandbox target collision: local file "${parentFile.localPath}" maps to "${parent}", which must be a directory for "${file.localPath}".`
1544
+ );
1545
+ }
1546
+ requiredDirectories.add(parent);
1547
+ parent = import_node_path.posix.dirname(parent);
1548
+ }
1549
+ }
1550
+ const directories = [...requiredDirectories].sort((left, right) => {
1551
+ const depthDifference = left.split("/").length - right.split("/").length;
1552
+ return depthDifference || left.localeCompare(right);
1553
+ });
1554
+ const files = [...filesByTarget.values()].sort(
1555
+ (left, right) => left.targetPath.localeCompare(right.targetPath)
1556
+ );
1557
+ return { directories, files };
1409
1558
  }
1410
1559
  var Agent = class {
1411
1560
  sandbox;
@@ -1420,6 +1569,8 @@ var Agent = class {
1420
1569
  maxDuration;
1421
1570
  dependencies;
1422
1571
  files;
1572
+ localDirectories;
1573
+ /** @deprecated Use `localDirectories` with destination `.claude` instead. */
1423
1574
  claudeDir;
1424
1575
  envs;
1425
1576
  build;
@@ -1441,6 +1592,7 @@ var Agent = class {
1441
1592
  this._sourceFile = resolveSourceFile(config.sourceFile);
1442
1593
  this.dependencies = config.dependencies ?? DEFAULT_DEPENDENCIES;
1443
1594
  this.files = config.files ?? [];
1595
+ this.localDirectories = (config.localDirectories ?? []).map((entry) => ({ ...entry }));
1444
1596
  this.claudeDir = config.claudeDir;
1445
1597
  this.envs = config.envs ?? {};
1446
1598
  this.build = config.build ?? {};
@@ -1643,6 +1795,10 @@ ${parts.join("\n\n")}`;
1643
1795
  }
1644
1796
  async _deploy(options) {
1645
1797
  if (!options?.fresh && this._serverRuntime) return this._serverRuntime.connection.sandboxId;
1798
+ const localDirectoryUploads = prepareLocalDirectoryUploads(
1799
+ this.localDirectories,
1800
+ this.claudeDir
1801
+ );
1646
1802
  const esbuild = await getEsbuild();
1647
1803
  const externalPatterns = Array.from(
1648
1804
  /* @__PURE__ */ new Set([...DEFAULT_EXTERNALS, ...this.build.external ?? []])
@@ -1776,21 +1932,14 @@ var require = __neckbeard_createRequire(import.meta.url);
1776
1932
  }
1777
1933
  }
1778
1934
  }
1779
- if (this.claudeDir) {
1780
- const claudeFiles = readDirectoryRecursively(this.claudeDir);
1781
- await sandbox.runCommand(`mkdir -p ${shellEscape(paths.claudeDir)}`, {
1782
- timeoutMs: QUICK_COMMAND_TIMEOUT_MS
1783
- });
1784
- for (const file of claudeFiles) {
1785
- const destPath = `${paths.claudeDir}/${file.relativePath}`;
1786
- const parentDir = destPath.substring(0, destPath.lastIndexOf("/"));
1787
- if (parentDir && parentDir !== paths.claudeDir) {
1788
- await sandbox.runCommand(`mkdir -p ${shellEscape(parentDir)}`, {
1789
- timeoutMs: QUICK_COMMAND_TIMEOUT_MS
1790
- });
1791
- }
1792
- await sandbox.writeFile(destPath, file.content);
1793
- }
1935
+ for (const directory of localDirectoryUploads.directories) {
1936
+ await sandbox.makeDir(import_node_path.posix.join(paths.agentDir, directory));
1937
+ }
1938
+ for (const file of localDirectoryUploads.files) {
1939
+ await sandbox.writeFile(
1940
+ import_node_path.posix.join(paths.agentDir, file.targetPath),
1941
+ file.content
1942
+ );
1794
1943
  }
1795
1944
  await sandbox.writeFile(paths.agentModule, result.outputFiles[0].text);
1796
1945
  await sandbox.writeFile(paths.serverModule, RUNTIME_SERVER_SOURCE);
package/dist/index.d.cts CHANGED
@@ -159,6 +159,23 @@ interface FileDownload {
159
159
  */
160
160
  path: string;
161
161
  }
162
+ /**
163
+ * Configuration for recursively copying a local directory into the sandbox
164
+ * agent directory during deploy().
165
+ */
166
+ interface LocalDirectoryUpload {
167
+ /**
168
+ * Local source directory. Relative paths resolve from the deploying
169
+ * process's current working directory.
170
+ */
171
+ source: string;
172
+ /**
173
+ * Destination directory relative to `ctx.sandbox.agentDir`.
174
+ * Absolute paths and paths that traverse outside the agent directory are
175
+ * rejected.
176
+ */
177
+ destination: string;
178
+ }
162
179
  /** Default dependencies - empty by default, specify what you need */
163
180
  declare const DEFAULT_DEPENDENCIES: OsDependencies;
164
181
  interface AgentSharedConfig<TInput> {
@@ -183,7 +200,19 @@ interface AgentSharedConfig<TInput> {
183
200
  */
184
201
  files?: FileDownload[];
185
202
  /**
186
- * Local path to a .claude directory containing skills and settings.
203
+ * Local directories to recursively upload beneath the sandbox agent
204
+ * directory. Dotfiles and exact file bytes are preserved. Symbolic links
205
+ * are rejected.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * localDirectories: [{ source: './.agents', destination: '.agents' }]
210
+ * ```
211
+ */
212
+ localDirectories?: LocalDirectoryUpload[];
213
+ /**
214
+ * Legacy Claude-specific convenience option. Local path to a .claude
215
+ * directory containing skills and settings.
187
216
  * The directory will be uploaded to {homeDir}/agent/.claude/ in the sandbox.
188
217
  * This enables Claude Agent SDK to access skills defined in SKILL.md files
189
218
  * within .claude/skills/ subdirectories.
@@ -194,6 +223,8 @@ interface AgentSharedConfig<TInput> {
194
223
  * - cwd is set to {homeDir}/agent/ (containing .claude/)
195
224
  * - settingSources includes 'project'
196
225
  * - allowedTools includes 'Skill'
226
+ *
227
+ * @deprecated Use `localDirectories` with destination `.claude` instead.
197
228
  */
198
229
  claudeDir?: string;
199
230
  /**
@@ -378,6 +409,8 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
378
409
  readonly maxDuration: number;
379
410
  readonly dependencies: OsDependencies;
380
411
  readonly files: FileDownload[];
412
+ readonly localDirectories: LocalDirectoryUpload[];
413
+ /** @deprecated Use `localDirectories` with destination `.claude` instead. */
381
414
  readonly claudeDir?: string;
382
415
  readonly envs: Record<string, string | undefined>;
383
416
  readonly build: BuildOptions;
@@ -477,4 +510,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
477
510
  }): AsyncGenerator<TFrame>;
478
511
  }
479
512
 
480
- export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, type SandboxCommandOptions, type SandboxCommandResult, type SandboxConfig, type SandboxFileContent, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
513
+ export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, type LocalDirectoryUpload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, type SandboxCommandOptions, type SandboxCommandResult, type SandboxConfig, type SandboxFileContent, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
package/dist/index.d.ts CHANGED
@@ -159,6 +159,23 @@ interface FileDownload {
159
159
  */
160
160
  path: string;
161
161
  }
162
+ /**
163
+ * Configuration for recursively copying a local directory into the sandbox
164
+ * agent directory during deploy().
165
+ */
166
+ interface LocalDirectoryUpload {
167
+ /**
168
+ * Local source directory. Relative paths resolve from the deploying
169
+ * process's current working directory.
170
+ */
171
+ source: string;
172
+ /**
173
+ * Destination directory relative to `ctx.sandbox.agentDir`.
174
+ * Absolute paths and paths that traverse outside the agent directory are
175
+ * rejected.
176
+ */
177
+ destination: string;
178
+ }
162
179
  /** Default dependencies - empty by default, specify what you need */
163
180
  declare const DEFAULT_DEPENDENCIES: OsDependencies;
164
181
  interface AgentSharedConfig<TInput> {
@@ -183,7 +200,19 @@ interface AgentSharedConfig<TInput> {
183
200
  */
184
201
  files?: FileDownload[];
185
202
  /**
186
- * Local path to a .claude directory containing skills and settings.
203
+ * Local directories to recursively upload beneath the sandbox agent
204
+ * directory. Dotfiles and exact file bytes are preserved. Symbolic links
205
+ * are rejected.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * localDirectories: [{ source: './.agents', destination: '.agents' }]
210
+ * ```
211
+ */
212
+ localDirectories?: LocalDirectoryUpload[];
213
+ /**
214
+ * Legacy Claude-specific convenience option. Local path to a .claude
215
+ * directory containing skills and settings.
187
216
  * The directory will be uploaded to {homeDir}/agent/.claude/ in the sandbox.
188
217
  * This enables Claude Agent SDK to access skills defined in SKILL.md files
189
218
  * within .claude/skills/ subdirectories.
@@ -194,6 +223,8 @@ interface AgentSharedConfig<TInput> {
194
223
  * - cwd is set to {homeDir}/agent/ (containing .claude/)
195
224
  * - settingSources includes 'project'
196
225
  * - allowedTools includes 'Skill'
226
+ *
227
+ * @deprecated Use `localDirectories` with destination `.claude` instead.
197
228
  */
198
229
  claudeDir?: string;
199
230
  /**
@@ -378,6 +409,8 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
378
409
  readonly maxDuration: number;
379
410
  readonly dependencies: OsDependencies;
380
411
  readonly files: FileDownload[];
412
+ readonly localDirectories: LocalDirectoryUpload[];
413
+ /** @deprecated Use `localDirectories` with destination `.claude` instead. */
381
414
  readonly claudeDir?: string;
382
415
  readonly envs: Record<string, string | undefined>;
383
416
  readonly build: BuildOptions;
@@ -477,4 +510,4 @@ declare class Agent<TInput, TOutput = unknown, TFrame = unknown> {
477
510
  }): AsyncGenerator<TFrame>;
478
511
  }
479
512
 
480
- export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, type SandboxCommandOptions, type SandboxCommandResult, type SandboxConfig, type SandboxFileContent, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
513
+ export { Agent, type AgentConfig, type AgentMode, type AgentRunContext, type AgentRunResult, type AgentSandboxContext, type BuildOptions, ConfigurationError, DEFAULT_DEPENDENCIES, type DaytonaSandboxConfig, DeploymentError, type E2BSandboxConfig, ExecutionError, type FileDownload, type LocalDirectoryUpload, NeckbeardError, type NeckbeardNextConfigOptions, type OsDependencies, type ResolveAgentSourceFileOptions, type RunAgentConfig, SandboxClient, type SandboxClientConnectOptions, type SandboxClientCreateOptions, type SandboxCommandOptions, type SandboxCommandResult, type SandboxConfig, type SandboxFileContent, type SandboxProvider, type ServerAgentConfig, ValidationError, resolveAgentSourceFile, withNeckbeardNextConfig };
package/dist/index.js CHANGED
@@ -4,8 +4,25 @@ import {
4
4
 
5
5
  // src/index.ts
6
6
  import { fileURLToPath } from "url";
7
- import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "fs";
8
- import { basename, dirname, join, relative, resolve } from "path";
7
+ import {
8
+ existsSync,
9
+ lstatSync,
10
+ readdirSync,
11
+ readFileSync,
12
+ statSync,
13
+ writeFileSync
14
+ } from "fs";
15
+ import {
16
+ basename,
17
+ dirname,
18
+ isAbsolute,
19
+ join,
20
+ posix,
21
+ relative,
22
+ resolve,
23
+ sep,
24
+ win32
25
+ } from "path";
9
26
  import { builtinModules, createRequire } from "module";
10
27
 
11
28
  // src/runtime/server-source.generated.ts
@@ -510,6 +527,53 @@ function requireSchemaLike(name, value) {
510
527
  }
511
528
  return value;
512
529
  }
530
+ function normalizeLocalDirectoryDestination(destination, name) {
531
+ if (destination.trim() === "") {
532
+ throw new ConfigurationError(`${name}.destination must be a non-empty relative path.`);
533
+ }
534
+ if (destination.includes("\0")) {
535
+ throw new ConfigurationError(`${name}.destination must not contain null bytes.`);
536
+ }
537
+ const sandboxPath = destination.replace(/\\/g, "/");
538
+ if (isAbsolute(destination) || posix.isAbsolute(sandboxPath) || win32.isAbsolute(destination)) {
539
+ throw new ConfigurationError(
540
+ `${name}.destination must be relative to the sandbox agent directory.`
541
+ );
542
+ }
543
+ if (sandboxPath.split("/").includes("..")) {
544
+ throw new ConfigurationError(
545
+ `${name}.destination must not traverse outside the sandbox agent directory.`
546
+ );
547
+ }
548
+ const normalized = posix.normalize(sandboxPath);
549
+ if (normalized === ".") {
550
+ throw new ConfigurationError(`${name}.destination must not be ".".`);
551
+ }
552
+ return normalized;
553
+ }
554
+ function validateLocalDirectoriesConfig(value) {
555
+ if (value === void 0) return;
556
+ if (!Array.isArray(value)) {
557
+ throw new ConfigurationError("localDirectories must be an array when provided.");
558
+ }
559
+ for (const [index, entry] of value.entries()) {
560
+ const name = `localDirectories[${index}]`;
561
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
562
+ throw new ConfigurationError(`${name} must be an object.`);
563
+ }
564
+ const candidate = entry;
565
+ if (typeof candidate.source !== "string" || candidate.source.trim() === "") {
566
+ throw new ConfigurationError(`${name}.source must be a non-empty string.`);
567
+ }
568
+ if (candidate.source.includes("\0")) {
569
+ throw new ConfigurationError(`${name}.source must not contain null bytes.`);
570
+ }
571
+ if (typeof candidate.destination !== "string") {
572
+ throw new ConfigurationError(`${name}.destination must be a string.`);
573
+ }
574
+ normalizeLocalDirectoryDestination(candidate.destination, name);
575
+ }
576
+ }
513
577
  function validateAgentConfig(config) {
514
578
  if (!config || typeof config !== "object") {
515
579
  throw new ConfigurationError("Agent config must be an object.");
@@ -530,6 +594,7 @@ function validateAgentConfig(config) {
530
594
  if (config.sourceFile !== void 0 && (typeof config.sourceFile !== "string" || config.sourceFile.trim() === "")) {
531
595
  throw new ConfigurationError("sourceFile must be a non-empty string when provided.");
532
596
  }
597
+ validateLocalDirectoriesConfig(config.localDirectories);
533
598
  if (isServerAgentConfig(config)) {
534
599
  if ("run" in config && typeof config.run === "function") {
535
600
  throw new ConfigurationError("Agent config must use either run or server.handler, not both.");
@@ -1148,30 +1213,131 @@ function resolveSourceFile(sourceFile) {
1148
1213
  }
1149
1214
  return resolved;
1150
1215
  }
1151
- function readDirectoryRecursively(dirPath) {
1216
+ function localPathStats(localPath, upload, isSourceRoot = false) {
1217
+ let stats;
1218
+ try {
1219
+ stats = lstatSync(localPath);
1220
+ } catch (error) {
1221
+ const code = error.code;
1222
+ const detail = isSourceRoot && code === "ENOENT" ? "source does not exist" : "could not read local path";
1223
+ throw new ConfigurationError(
1224
+ `${upload.name} ${detail}: ${localPath} (${errorMessage(error)})`
1225
+ );
1226
+ }
1227
+ if (!stats.isSymbolicLink()) return stats;
1228
+ if (upload.rejectSymlinks) {
1229
+ throw new ConfigurationError(
1230
+ `${upload.name} source tree contains a symbolic link: ${localPath}`
1231
+ );
1232
+ }
1233
+ try {
1234
+ return statSync(localPath);
1235
+ } catch (error) {
1236
+ throw new ConfigurationError(
1237
+ `${upload.name} could not follow legacy symbolic link: ${localPath} (${errorMessage(error)})`
1238
+ );
1239
+ }
1240
+ }
1241
+ function readConfiguredLocalDirectory(upload) {
1242
+ const rootPath = resolve(process.cwd(), upload.source);
1243
+ const rootStats = localPathStats(rootPath, upload, true);
1244
+ if (!rootStats.isDirectory()) {
1245
+ throw new ConfigurationError(`${upload.name}.source must be a directory: ${rootPath}`);
1246
+ }
1247
+ const destination = normalizeLocalDirectoryDestination(upload.destination, upload.name);
1152
1248
  const files = [];
1153
- function walkDir(currentPath) {
1154
- const entries = readdirSync(currentPath);
1249
+ function walk(currentPath) {
1250
+ let entries;
1251
+ try {
1252
+ entries = readdirSync(currentPath).sort((left, right) => left.localeCompare(right));
1253
+ } catch (error) {
1254
+ throw new ConfigurationError(
1255
+ `${upload.name} could not read local directory: ${currentPath} (${errorMessage(error)})`
1256
+ );
1257
+ }
1155
1258
  for (const entry of entries) {
1156
- const fullPath = join(currentPath, entry);
1157
- const stat = statSync(fullPath);
1158
- if (stat.isDirectory()) {
1159
- walkDir(fullPath);
1160
- } else if (stat.isFile()) {
1161
- const relPath = relative(dirPath, fullPath);
1162
- const isBinary = /\.(png|jpg|jpeg|gif|ico|pdf|zip|tar|gz|bin|exe|dll|so|dylib|wasm)$/i.test(entry);
1163
- if (isBinary) {
1164
- const buffer = readFileSync(fullPath);
1165
- const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
1166
- files.push({ relativePath: relPath, content: arrayBuffer });
1167
- } else {
1168
- files.push({ relativePath: relPath, content: readFileSync(fullPath, "utf-8") });
1169
- }
1259
+ const localPath = join(currentPath, entry);
1260
+ const stats = localPathStats(localPath, upload);
1261
+ if (stats.isDirectory()) {
1262
+ walk(localPath);
1263
+ continue;
1170
1264
  }
1265
+ if (!stats.isFile()) {
1266
+ throw new ConfigurationError(
1267
+ `${upload.name} source tree contains an unsupported filesystem entry: ${localPath}`
1268
+ );
1269
+ }
1270
+ const relativePath = relative(rootPath, localPath).split(sep).join("/");
1271
+ const targetPath = posix.join(destination, relativePath);
1272
+ let content;
1273
+ try {
1274
+ content = readFileSync(localPath);
1275
+ } catch (error) {
1276
+ throw new ConfigurationError(
1277
+ `${upload.name} could not read local file: ${localPath} (${errorMessage(error)})`
1278
+ );
1279
+ }
1280
+ files.push({ localPath, targetPath, content });
1171
1281
  }
1172
1282
  }
1173
- walkDir(dirPath);
1174
- return files;
1283
+ walk(rootPath);
1284
+ return { rootPath, files };
1285
+ }
1286
+ function prepareLocalDirectoryUploads(localDirectories, claudeDir) {
1287
+ const uploads = localDirectories.map((entry, index) => ({
1288
+ ...entry,
1289
+ name: `localDirectories[${index}]`,
1290
+ rejectSymlinks: true,
1291
+ preserveRootDirectory: false
1292
+ }));
1293
+ if (claudeDir) {
1294
+ uploads.push({
1295
+ source: claudeDir,
1296
+ destination: ".claude",
1297
+ name: "claudeDir",
1298
+ rejectSymlinks: false,
1299
+ preserveRootDirectory: true
1300
+ });
1301
+ }
1302
+ const filesByTarget = /* @__PURE__ */ new Map();
1303
+ const requiredDirectories = /* @__PURE__ */ new Set();
1304
+ for (const upload of uploads) {
1305
+ const prepared = readConfiguredLocalDirectory(upload);
1306
+ const destination = normalizeLocalDirectoryDestination(upload.destination, upload.name);
1307
+ if (upload.preserveRootDirectory) {
1308
+ requiredDirectories.add(destination);
1309
+ }
1310
+ for (const file of prepared.files) {
1311
+ const existing = filesByTarget.get(file.targetPath);
1312
+ if (existing) {
1313
+ throw new ConfigurationError(
1314
+ `Duplicate sandbox target "${file.targetPath}" from local files "${existing.localPath}" and "${file.localPath}".`
1315
+ );
1316
+ }
1317
+ filesByTarget.set(file.targetPath, file);
1318
+ }
1319
+ }
1320
+ for (const file of filesByTarget.values()) {
1321
+ let parent = posix.dirname(file.targetPath);
1322
+ while (parent !== ".") {
1323
+ const parentFile = filesByTarget.get(parent);
1324
+ if (parentFile) {
1325
+ throw new ConfigurationError(
1326
+ `Sandbox target collision: local file "${parentFile.localPath}" maps to "${parent}", which must be a directory for "${file.localPath}".`
1327
+ );
1328
+ }
1329
+ requiredDirectories.add(parent);
1330
+ parent = posix.dirname(parent);
1331
+ }
1332
+ }
1333
+ const directories = [...requiredDirectories].sort((left, right) => {
1334
+ const depthDifference = left.split("/").length - right.split("/").length;
1335
+ return depthDifference || left.localeCompare(right);
1336
+ });
1337
+ const files = [...filesByTarget.values()].sort(
1338
+ (left, right) => left.targetPath.localeCompare(right.targetPath)
1339
+ );
1340
+ return { directories, files };
1175
1341
  }
1176
1342
  var Agent = class {
1177
1343
  sandbox;
@@ -1186,6 +1352,8 @@ var Agent = class {
1186
1352
  maxDuration;
1187
1353
  dependencies;
1188
1354
  files;
1355
+ localDirectories;
1356
+ /** @deprecated Use `localDirectories` with destination `.claude` instead. */
1189
1357
  claudeDir;
1190
1358
  envs;
1191
1359
  build;
@@ -1207,6 +1375,7 @@ var Agent = class {
1207
1375
  this._sourceFile = resolveSourceFile(config.sourceFile);
1208
1376
  this.dependencies = config.dependencies ?? DEFAULT_DEPENDENCIES;
1209
1377
  this.files = config.files ?? [];
1378
+ this.localDirectories = (config.localDirectories ?? []).map((entry) => ({ ...entry }));
1210
1379
  this.claudeDir = config.claudeDir;
1211
1380
  this.envs = config.envs ?? {};
1212
1381
  this.build = config.build ?? {};
@@ -1409,6 +1578,10 @@ ${parts.join("\n\n")}`;
1409
1578
  }
1410
1579
  async _deploy(options) {
1411
1580
  if (!options?.fresh && this._serverRuntime) return this._serverRuntime.connection.sandboxId;
1581
+ const localDirectoryUploads = prepareLocalDirectoryUploads(
1582
+ this.localDirectories,
1583
+ this.claudeDir
1584
+ );
1412
1585
  const esbuild = await getEsbuild();
1413
1586
  const externalPatterns = Array.from(
1414
1587
  /* @__PURE__ */ new Set([...DEFAULT_EXTERNALS, ...this.build.external ?? []])
@@ -1542,21 +1715,14 @@ var require = __neckbeard_createRequire(import.meta.url);
1542
1715
  }
1543
1716
  }
1544
1717
  }
1545
- if (this.claudeDir) {
1546
- const claudeFiles = readDirectoryRecursively(this.claudeDir);
1547
- await sandbox.runCommand(`mkdir -p ${shellEscape(paths.claudeDir)}`, {
1548
- timeoutMs: QUICK_COMMAND_TIMEOUT_MS
1549
- });
1550
- for (const file of claudeFiles) {
1551
- const destPath = `${paths.claudeDir}/${file.relativePath}`;
1552
- const parentDir = destPath.substring(0, destPath.lastIndexOf("/"));
1553
- if (parentDir && parentDir !== paths.claudeDir) {
1554
- await sandbox.runCommand(`mkdir -p ${shellEscape(parentDir)}`, {
1555
- timeoutMs: QUICK_COMMAND_TIMEOUT_MS
1556
- });
1557
- }
1558
- await sandbox.writeFile(destPath, file.content);
1559
- }
1718
+ for (const directory of localDirectoryUploads.directories) {
1719
+ await sandbox.makeDir(posix.join(paths.agentDir, directory));
1720
+ }
1721
+ for (const file of localDirectoryUploads.files) {
1722
+ await sandbox.writeFile(
1723
+ posix.join(paths.agentDir, file.targetPath),
1724
+ file.content
1725
+ );
1560
1726
  }
1561
1727
  await sandbox.writeFile(paths.agentModule, result.outputFiles[0].text);
1562
1728
  await sandbox.writeFile(paths.serverModule, RUNTIME_SERVER_SOURCE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-neckbeard",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "Deploy AI agents to E2B and Daytona sandboxes",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,7 +20,8 @@
20
20
  "types": "./dist/index.d.cts",
21
21
  "sideEffects": false,
22
22
  "files": [
23
- "dist"
23
+ "dist",
24
+ "CHANGELOG.md"
24
25
  ],
25
26
  "engines": {
26
27
  "node": ">=20.0.0"