agent-neckbeard 1.1.26 → 1.1.27

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.27 - 2026-11-09
4
+
5
+ - Upload `localDirectories` (and `claudeDir`) as one gzipped tar archive extracted with the sandbox's `tar`, instead of one provider call per file and directory. A 138-file skills directory took about two minutes to upload to a distant Modal sandbox. Images now need `tar` and `gzip`, and uploaded files have mode 0644.
6
+ - Accept `regions` in Modal sandbox config and pass it to sandbox creation. Modal otherwise places a sandbox in any region worldwide.
7
+ - Accept Daytona's `networkBlockAll`, `networkAllowList`, and `domainAllowList` in Modal sandbox config, in the same shape, mapped to Modal's outbound network policy. Modal's domain allow list only passes HTTPS, so with one set the image's apt sources are switched to HTTPS. See `docs/MODAL.md#network-policy`.
8
+ - Link a Modal image's `node`, `npm`, and `npx` into `/usr/local/bin` when they resolve elsewhere, such as an nvm install, so the runtime's fixed `PATH` finds them. Images like `daytonaio/sandbox:*-slim` failed their health check before.
9
+
3
10
  ## 1.1.26 - 2026-11-03
4
11
 
5
12
  - Make the runtime wait up to 10 seconds for an aborted handler to stop before emitting the terminal `error` event, so the event marks the end of the handler's work. The host's `run()` timeout allows for that grace period.
package/README.md CHANGED
@@ -136,6 +136,8 @@ new Agent({
136
136
 
137
137
  Set `networkBlockAll: true` only when you want to block all outbound network access. Daytona rejects `networkBlockAll: true` combined with non-empty allow lists.
138
138
 
139
+ Modal sandboxes accept the same three options in the same shape. Modal's domain allow list only passes HTTPS, so see [Modal network policy](docs/MODAL.md#network-policy).
140
+
139
141
  `autoStopInterval` and `autoDeleteInterval` set the sandbox's Daytona lifecycle, in whole minutes, when the sandbox is created; reconnecting to an existing sandbox does not change them. Daytona stops a sandbox after `autoStopInterval` minutes without activity (`0` disables auto-stop; omitting it keeps Daytona's default, 15 minutes for standard sandbox classes) and deletes it `autoDeleteInterval` minutes after it stops (`0` deletes it immediately; `-1`, the default, never auto-deletes it).
140
142
 
141
143
  ## Structured Tasks
@@ -419,7 +421,7 @@ interface LocalDirectoryUpload {
419
421
  }
420
422
  ```
421
423
 
422
- `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.
424
+ `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. The files go up as one gzipped tar archive that the sandbox extracts with `tar`, so the image needs `tar` and `gzip`; files land with mode 0644.
423
425
 
424
426
  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:
425
427
 
package/dist/index.cjs CHANGED
@@ -260,6 +260,7 @@ module.exports = __toCommonJS(src_exports);
260
260
  var import_node_url = require("url");
261
261
  var import_node_fs = require("fs");
262
262
  var import_node_path = require("path");
263
+ var import_node_crypto3 = require("crypto");
263
264
  var import_node_module2 = require("module");
264
265
  init_protocol();
265
266
 
@@ -541,8 +542,91 @@ function shellQuote(value) {
541
542
  return `'${value.replace(/'/g, `'\\''`)}'`;
542
543
  }
543
544
 
544
- // src/providers/detached-process.ts
545
+ // src/tar.ts
545
546
  var import_node_buffer = require("buffer");
547
+ var import_node_util = require("util");
548
+ var import_node_zlib = require("zlib");
549
+ var gzipAsync = (0, import_node_util.promisify)(import_node_zlib.gzip);
550
+ var BLOCK_SIZE = 512;
551
+ var MAX_OCTAL_SIZE = 8589934591;
552
+ function writeString(header2, value, offset, length) {
553
+ header2.write(value, offset, length, "utf8");
554
+ }
555
+ function writeOctal(header2, value, offset, length) {
556
+ header2.write(`${value.toString(8).padStart(length - 1, "0")}\0`, offset, length, "ascii");
557
+ }
558
+ function splitUstarPath(path) {
559
+ if (import_node_buffer.Buffer.byteLength(path) <= 100) return { name: path, prefix: "" };
560
+ for (let index = path.indexOf("/"); index !== -1; index = path.indexOf("/", index + 1)) {
561
+ const prefix = path.slice(0, index);
562
+ const name = path.slice(index + 1);
563
+ if (import_node_buffer.Buffer.byteLength(prefix) <= 155 && import_node_buffer.Buffer.byteLength(name) <= 100 && name) {
564
+ return { name, prefix };
565
+ }
566
+ }
567
+ return void 0;
568
+ }
569
+ function header(options) {
570
+ if (options.size > MAX_OCTAL_SIZE) {
571
+ throw new Error(`Archive entry ${options.name} is too large.`);
572
+ }
573
+ const block = import_node_buffer.Buffer.alloc(BLOCK_SIZE);
574
+ writeString(block, options.name, 0, 100);
575
+ writeOctal(block, options.mode, 100, 8);
576
+ writeOctal(block, 0, 108, 8);
577
+ writeOctal(block, 0, 116, 8);
578
+ writeOctal(block, options.size, 124, 12);
579
+ writeOctal(block, options.mtime, 136, 12);
580
+ block.fill(" ", 148, 156);
581
+ writeString(block, options.type, 156, 1);
582
+ writeString(block, "ustar\0", 257, 6);
583
+ writeString(block, "00", 263, 2);
584
+ writeString(block, options.prefix ?? "", 345, 155);
585
+ let checksum = 0;
586
+ for (const byte of block) checksum += byte;
587
+ block.write(`${checksum.toString(8).padStart(6, "0")}\0 `, 148, 8, "ascii");
588
+ return block;
589
+ }
590
+ function padding(size) {
591
+ return import_node_buffer.Buffer.alloc((BLOCK_SIZE - size % BLOCK_SIZE) % BLOCK_SIZE);
592
+ }
593
+ function paxPathRecord(path) {
594
+ const body = ` path=${path}
595
+ `;
596
+ let length = import_node_buffer.Buffer.byteLength(body);
597
+ while (String(length).length + import_node_buffer.Buffer.byteLength(body) !== length) {
598
+ length = String(length).length + import_node_buffer.Buffer.byteLength(body);
599
+ }
600
+ return import_node_buffer.Buffer.from(`${length}${body}`);
601
+ }
602
+ async function createTarGz(entries, mtime = Math.floor(Date.now() / 1e3)) {
603
+ const chunks = [];
604
+ for (const entry of entries) {
605
+ const isDirectory = entry.content === void 0;
606
+ const path = isDirectory ? `${entry.path.replace(/\/+$/u, "")}/` : entry.path;
607
+ const size = entry.content?.byteLength ?? 0;
608
+ const type = isDirectory ? "5" : "0";
609
+ const mode = isDirectory ? 493 : 420;
610
+ const split = splitUstarPath(path);
611
+ if (split) {
612
+ chunks.push(header({ ...split, mode, size, mtime, type }));
613
+ } else {
614
+ const record = paxPathRecord(path);
615
+ chunks.push(header({ name: "PaxHeader", mode: 420, size: record.byteLength, mtime, type: "x" }));
616
+ chunks.push(record, padding(record.byteLength));
617
+ chunks.push(header({ name: path.slice(-100).replace(/^\/+/u, ""), mode, size, mtime, type }));
618
+ }
619
+ if (entry.content) {
620
+ chunks.push(import_node_buffer.Buffer.from(entry.content.buffer, entry.content.byteOffset, entry.content.byteLength));
621
+ chunks.push(padding(size));
622
+ }
623
+ }
624
+ chunks.push(import_node_buffer.Buffer.alloc(BLOCK_SIZE * 2));
625
+ return gzipAsync(import_node_buffer.Buffer.concat(chunks));
626
+ }
627
+
628
+ // src/providers/detached-process.ts
629
+ var import_node_buffer2 = require("buffer");
546
630
  var import_node_crypto = require("crypto");
547
631
  var DETACHED_PROCESS_ROOT = "/tmp/agent-neckbeard-detached";
548
632
  var DETACHED_PROCESS_CONTROL_TIMEOUT_MS = 3e4;
@@ -2764,9 +2848,9 @@ function readLogFiles(stdout, stderr, previous, beforePrint = []) {
2764
2848
  function parseDetachedProcessLogs(output) {
2765
2849
  const lineEnd = output.indexOf("\n");
2766
2850
  if (lineEnd < 0) return null;
2767
- const header = output.slice(0, lineEnd);
2851
+ const header2 = output.slice(0, lineEnd);
2768
2852
  const match = new RegExp(`^${LOGS_PREFIX} (0|[1-9][0-9]*) (0|[1-9][0-9]*)$`, "u").exec(
2769
- header
2853
+ header2
2770
2854
  );
2771
2855
  if (!match?.[1] || !match[2]) return null;
2772
2856
  const stdoutBytes = Number(match[1]);
@@ -2787,7 +2871,7 @@ function parseDetachedProcessLogs(output) {
2787
2871
  };
2788
2872
  const stdout = decodeCanonicalBase64(stdoutBase64);
2789
2873
  const stderr = decodeCanonicalBase64(stderrBase64);
2790
- if (!stdout || !stderr || stdout.byteLength !== stdoutBytes || stderr.byteLength !== stderrBytes || !(0, import_node_buffer.isUtf8)(stdout) || !(0, import_node_buffer.isUtf8)(stderr)) {
2874
+ if (!stdout || !stderr || stdout.byteLength !== stdoutBytes || stderr.byteLength !== stderrBytes || !(0, import_node_buffer2.isUtf8)(stdout) || !(0, import_node_buffer2.isUtf8)(stderr)) {
2791
2875
  return null;
2792
2876
  }
2793
2877
  return {
@@ -2800,7 +2884,7 @@ function isStopConfirmation(output) {
2800
2884
  }
2801
2885
 
2802
2886
  // src/providers/daytona-transport.ts
2803
- var import_node_buffer2 = require("buffer");
2887
+ var import_node_buffer3 = require("buffer");
2804
2888
  function daytonaTimeoutSeconds(timeoutMs) {
2805
2889
  return Math.max(1, Math.ceil(timeoutMs / 1e3));
2806
2890
  }
@@ -2846,10 +2930,10 @@ async function makeDaytonaDirectory(sandbox, path, options) {
2846
2930
  );
2847
2931
  }
2848
2932
  function daytonaUploadContent(content) {
2849
- if (import_node_buffer2.Buffer.isBuffer(content)) return content;
2850
- if (typeof content === "string") return import_node_buffer2.Buffer.from(content);
2851
- if (content instanceof Uint8Array) return import_node_buffer2.Buffer.from(content);
2852
- return import_node_buffer2.Buffer.from(content);
2933
+ if (import_node_buffer3.Buffer.isBuffer(content)) return content;
2934
+ if (typeof content === "string") return import_node_buffer3.Buffer.from(content);
2935
+ if (content instanceof Uint8Array) return import_node_buffer3.Buffer.from(content);
2936
+ return import_node_buffer3.Buffer.from(content);
2853
2937
  }
2854
2938
  async function uploadDaytonaFile(sandbox, path, content, options) {
2855
2939
  await options.beforeIo?.();
@@ -3363,8 +3447,21 @@ function getModalSdk() {
3363
3447
  // src/providers/modal.ts
3364
3448
  var MODAL_DEFAULT_TEMPLATE = "node:22-bookworm";
3365
3449
  var MODAL_DEFAULT_TIMEOUT_MS = 60 * 60 * 1e3;
3450
+ function parseModalAllowList(value) {
3451
+ return (value ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
3452
+ }
3453
+ function modalNetworkOptions(options) {
3454
+ if (options.networkBlockAll) return { blockNetwork: true };
3455
+ const cidrs = parseModalAllowList(options.networkAllowList);
3456
+ const domains = parseModalAllowList(options.domainAllowList);
3457
+ return {
3458
+ ...cidrs.length > 0 ? { outboundCidrAllowlist: cidrs } : {},
3459
+ ...domains.length > 0 ? { outboundDomainAllowlist: domains } : {}
3460
+ };
3461
+ }
3366
3462
  function validateModalOptions(options, mode, failure) {
3367
- validateProviderOptions("Modal", options, ["environment", ...mode === "connect" ? ["sandboxId", "tokenId", "tokenSecret"] : [
3463
+ const { networkBlockAll, networkAllowList, domainAllowList, regions, ...rest } = options;
3464
+ validateProviderOptions("Modal", mode === "connect" ? options : rest, ["environment", ...mode === "connect" ? ["sandboxId", "tokenId", "tokenSecret"] : [
3368
3465
  "template",
3369
3466
  "appName",
3370
3467
  "timeoutMs",
@@ -3372,6 +3469,20 @@ function validateModalOptions(options, mode, failure) {
3372
3469
  "memoryMiB",
3373
3470
  ...mode === "create" ? ["tokenId", "tokenSecret", "envs"] : []
3374
3471
  ]], failure);
3472
+ if (regions !== void 0 && (!Array.isArray(regions) || regions.length === 0 || regions.some((region) => typeof region !== "string" || !/^[a-z0-9-]+$/u.test(region)))) {
3473
+ throw failure('Modal regions must be a non-empty array of region names such as "us" or "us-east".');
3474
+ }
3475
+ if (networkBlockAll !== void 0 && typeof networkBlockAll !== "boolean") {
3476
+ throw failure("Modal networkBlockAll must be a boolean.");
3477
+ }
3478
+ for (const [key, value] of [["networkAllowList", networkAllowList], ["domainAllowList", domainAllowList]]) {
3479
+ if (value !== void 0 && (typeof value !== "string" || parseModalAllowList(value).some((entry) => /[\s\0]/u.test(entry)))) {
3480
+ throw failure(`Modal ${key} must be a comma-separated string without whitespace or null bytes in entries.`);
3481
+ }
3482
+ }
3483
+ if (networkBlockAll && (parseModalAllowList(networkAllowList).length > 0 || parseModalAllowList(domainAllowList).length > 0)) {
3484
+ throw failure("Modal networkBlockAll cannot be combined with non-empty allow lists.");
3485
+ }
3375
3486
  if (mode === "connect" && !("sandboxId" in options && options.sandboxId)) {
3376
3487
  throw failure("Modal sandboxId is required.");
3377
3488
  }
@@ -3450,12 +3561,19 @@ var ModalSandboxHandle = class _ModalSandboxHandle {
3450
3561
  let sandbox;
3451
3562
  try {
3452
3563
  const app = await client.apps.fromName(options.appName ?? "agent-neckbeard", { createIfMissing: true });
3564
+ const network = modalNetworkOptions(options);
3453
3565
  const image = client.images.fromRegistry(options.template ?? MODAL_DEFAULT_TEMPLATE).dockerfileCommands([
3454
3566
  "USER root",
3455
3567
  "RUN apt-get update && apt-get install -y --no-install-recommends bash python3 util-linux coreutils sudo curl ca-certificates && rm -rf /var/lib/apt/lists/*",
3568
+ // The runtime starts with a fixed PATH, so images with Node elsewhere (say nvm) need links.
3569
+ 'RUN for bin in node npm npx; do target="$(command -v "$bin" || true)"; if [ -n "$target" ] && [ ! -e "/usr/local/bin/$bin" ]; then ln -s "$target" "/usr/local/bin/$bin"; fi; done',
3570
+ // The domain allow list only passes TLS, so apt installs in the sandbox need HTTPS sources.
3571
+ ...network.outboundDomainAllowlist ? ["RUN find /etc/apt -name '*.list' -o -name '*.sources' | xargs -r sed -i 's|http://|https://|g'"] : [],
3456
3572
  "WORKDIR /root"
3457
3573
  ]);
3458
3574
  sandbox = await client.sandboxes.create(app, image, {
3575
+ ...network,
3576
+ ...options.regions ? { regions: options.regions } : {},
3459
3577
  timeoutMs: options.timeoutMs ?? MODAL_DEFAULT_TIMEOUT_MS,
3460
3578
  cpu: options.cpu,
3461
3579
  memoryMiB: options.memoryMiB,
@@ -5666,14 +5784,21 @@ var require = __neckbeard_createRequire(import.meta.url);
5666
5784
  }
5667
5785
  }
5668
5786
  }
5669
- for (const directory of localDirectoryUploads.directories) {
5670
- await sandbox.makeDir(import_node_path.posix.join(paths.agentDir, directory));
5671
- }
5672
- for (const file of localDirectoryUploads.files) {
5673
- await sandbox.writeFile(
5674
- import_node_path.posix.join(paths.agentDir, file.targetPath),
5675
- file.content
5787
+ if (localDirectoryUploads.directories.length > 0 || localDirectoryUploads.files.length > 0) {
5788
+ const archivePath = import_node_path.posix.join(paths.agentDir, `.neckbeard-local-directories-${(0, import_node_crypto3.randomUUID)()}.tar.gz`);
5789
+ await sandbox.writeFile(archivePath, await createTarGz([
5790
+ ...localDirectoryUploads.directories.map((directory) => ({ path: directory })),
5791
+ ...localDirectoryUploads.files.map((file) => ({ path: file.targetPath, content: file.content }))
5792
+ ]));
5793
+ const extractResult = await sandbox.runCommand(
5794
+ `tar -xzf ${shellQuote(archivePath)} --no-same-owner -C ${shellQuote(paths.agentDir)} && rm -f ${shellQuote(archivePath)}`,
5795
+ { timeoutMs: SANDBOX_COMMAND_TIMEOUT_MS2 }
5676
5796
  );
5797
+ if (extractResult.exitCode !== 0) {
5798
+ throw new DeploymentError(
5799
+ `Failed to extract local directories: ${extractResult.stderr || extractResult.stdout}`
5800
+ );
5801
+ }
5677
5802
  }
5678
5803
  await sandbox.writeFile(paths.agentModule, result.outputFiles[0].text);
5679
5804
  await sandbox.writeFile(paths.serverModule, RUNTIME_SERVER_SOURCE);
package/dist/index.d.cts CHANGED
@@ -55,6 +55,32 @@ interface ModalSandboxConfig {
55
55
  timeoutMs?: number;
56
56
  cpu?: number;
57
57
  memoryMiB?: number;
58
+ /**
59
+ * Regions the sandbox may run in, such as `['us']` or `['us-east']`. Modal
60
+ * otherwise places it in any region worldwide, and every file and command
61
+ * call pays the round trip. Pinned regions cost more; see docs/MODAL.md.
62
+ */
63
+ regions?: string[];
64
+ /**
65
+ * Whether to block all sandbox network egress. Cannot be combined with
66
+ * non-empty allow lists.
67
+ */
68
+ networkBlockAll?: boolean;
69
+ /**
70
+ * Comma-separated CIDR allow list for sandbox egress, any protocol.
71
+ *
72
+ * Example: '203.0.113.0/24,198.51.100.10/32'
73
+ */
74
+ networkAllowList?: string;
75
+ /**
76
+ * Comma-separated domain allow list for sandbox egress. Modal matches the
77
+ * TLS SNI, so it only allows HTTPS (port 443) to these domains; when set, the
78
+ * image's apt sources are switched to HTTPS. Wildcards are supported with a
79
+ * leading `*.`. Traffic matching either allow list is allowed.
80
+ *
81
+ * Example: '*.example.com,api.openai.com'
82
+ */
83
+ domainAllowList?: string;
58
84
  }
59
85
  interface ModalClientCredentials {
60
86
  tokenId?: string;
package/dist/index.d.ts CHANGED
@@ -55,6 +55,32 @@ interface ModalSandboxConfig {
55
55
  timeoutMs?: number;
56
56
  cpu?: number;
57
57
  memoryMiB?: number;
58
+ /**
59
+ * Regions the sandbox may run in, such as `['us']` or `['us-east']`. Modal
60
+ * otherwise places it in any region worldwide, and every file and command
61
+ * call pays the round trip. Pinned regions cost more; see docs/MODAL.md.
62
+ */
63
+ regions?: string[];
64
+ /**
65
+ * Whether to block all sandbox network egress. Cannot be combined with
66
+ * non-empty allow lists.
67
+ */
68
+ networkBlockAll?: boolean;
69
+ /**
70
+ * Comma-separated CIDR allow list for sandbox egress, any protocol.
71
+ *
72
+ * Example: '203.0.113.0/24,198.51.100.10/32'
73
+ */
74
+ networkAllowList?: string;
75
+ /**
76
+ * Comma-separated domain allow list for sandbox egress. Modal matches the
77
+ * TLS SNI, so it only allows HTTPS (port 443) to these domains; when set, the
78
+ * image's apt sources are switched to HTTPS. Wildcards are supported with a
79
+ * leading `*.`. Traffic matching either allow list is allowed.
80
+ *
81
+ * Example: '*.example.com,api.openai.com'
82
+ */
83
+ domainAllowList?: string;
58
84
  }
59
85
  interface ModalClientCredentials {
60
86
  tokenId?: string;
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ import {
43
43
  sep,
44
44
  win32
45
45
  } from "path";
46
+ import { randomUUID } from "crypto";
46
47
  import { builtinModules, createRequire as createRequire2 } from "module";
47
48
 
48
49
  // src/runtime/server-source.generated.ts
@@ -175,6 +176,89 @@ function createAttachedAgentSession(options) {
175
176
  return new AttachedAgentSessionImpl(options);
176
177
  }
177
178
 
179
+ // src/tar.ts
180
+ import { Buffer as Buffer2 } from "buffer";
181
+ import { promisify } from "util";
182
+ import { gzip } from "zlib";
183
+ var gzipAsync = promisify(gzip);
184
+ var BLOCK_SIZE = 512;
185
+ var MAX_OCTAL_SIZE = 8589934591;
186
+ function writeString(header2, value, offset, length) {
187
+ header2.write(value, offset, length, "utf8");
188
+ }
189
+ function writeOctal(header2, value, offset, length) {
190
+ header2.write(`${value.toString(8).padStart(length - 1, "0")}\0`, offset, length, "ascii");
191
+ }
192
+ function splitUstarPath(path) {
193
+ if (Buffer2.byteLength(path) <= 100) return { name: path, prefix: "" };
194
+ for (let index = path.indexOf("/"); index !== -1; index = path.indexOf("/", index + 1)) {
195
+ const prefix = path.slice(0, index);
196
+ const name = path.slice(index + 1);
197
+ if (Buffer2.byteLength(prefix) <= 155 && Buffer2.byteLength(name) <= 100 && name) {
198
+ return { name, prefix };
199
+ }
200
+ }
201
+ return void 0;
202
+ }
203
+ function header(options) {
204
+ if (options.size > MAX_OCTAL_SIZE) {
205
+ throw new Error(`Archive entry ${options.name} is too large.`);
206
+ }
207
+ const block = Buffer2.alloc(BLOCK_SIZE);
208
+ writeString(block, options.name, 0, 100);
209
+ writeOctal(block, options.mode, 100, 8);
210
+ writeOctal(block, 0, 108, 8);
211
+ writeOctal(block, 0, 116, 8);
212
+ writeOctal(block, options.size, 124, 12);
213
+ writeOctal(block, options.mtime, 136, 12);
214
+ block.fill(" ", 148, 156);
215
+ writeString(block, options.type, 156, 1);
216
+ writeString(block, "ustar\0", 257, 6);
217
+ writeString(block, "00", 263, 2);
218
+ writeString(block, options.prefix ?? "", 345, 155);
219
+ let checksum = 0;
220
+ for (const byte of block) checksum += byte;
221
+ block.write(`${checksum.toString(8).padStart(6, "0")}\0 `, 148, 8, "ascii");
222
+ return block;
223
+ }
224
+ function padding(size) {
225
+ return Buffer2.alloc((BLOCK_SIZE - size % BLOCK_SIZE) % BLOCK_SIZE);
226
+ }
227
+ function paxPathRecord(path) {
228
+ const body = ` path=${path}
229
+ `;
230
+ let length = Buffer2.byteLength(body);
231
+ while (String(length).length + Buffer2.byteLength(body) !== length) {
232
+ length = String(length).length + Buffer2.byteLength(body);
233
+ }
234
+ return Buffer2.from(`${length}${body}`);
235
+ }
236
+ async function createTarGz(entries, mtime = Math.floor(Date.now() / 1e3)) {
237
+ const chunks = [];
238
+ for (const entry of entries) {
239
+ const isDirectory = entry.content === void 0;
240
+ const path = isDirectory ? `${entry.path.replace(/\/+$/u, "")}/` : entry.path;
241
+ const size = entry.content?.byteLength ?? 0;
242
+ const type = isDirectory ? "5" : "0";
243
+ const mode = isDirectory ? 493 : 420;
244
+ const split = splitUstarPath(path);
245
+ if (split) {
246
+ chunks.push(header({ ...split, mode, size, mtime, type }));
247
+ } else {
248
+ const record = paxPathRecord(path);
249
+ chunks.push(header({ name: "PaxHeader", mode: 420, size: record.byteLength, mtime, type: "x" }));
250
+ chunks.push(record, padding(record.byteLength));
251
+ chunks.push(header({ name: path.slice(-100).replace(/^\/+/u, ""), mode, size, mtime, type }));
252
+ }
253
+ if (entry.content) {
254
+ chunks.push(Buffer2.from(entry.content.buffer, entry.content.byteOffset, entry.content.byteLength));
255
+ chunks.push(padding(size));
256
+ }
257
+ }
258
+ chunks.push(Buffer2.alloc(BLOCK_SIZE * 2));
259
+ return gzipAsync(Buffer2.concat(chunks));
260
+ }
261
+
178
262
  // src/providers/types.ts
179
263
  function createProviderSandboxPaths(provider, homeDir, workDir) {
180
264
  const agentDir = `${homeDir}/agent`;
@@ -643,8 +727,21 @@ function getModalSdk() {
643
727
  // src/providers/modal.ts
644
728
  var MODAL_DEFAULT_TEMPLATE = "node:22-bookworm";
645
729
  var MODAL_DEFAULT_TIMEOUT_MS = 60 * 60 * 1e3;
730
+ function parseModalAllowList(value) {
731
+ return (value ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
732
+ }
733
+ function modalNetworkOptions(options) {
734
+ if (options.networkBlockAll) return { blockNetwork: true };
735
+ const cidrs = parseModalAllowList(options.networkAllowList);
736
+ const domains = parseModalAllowList(options.domainAllowList);
737
+ return {
738
+ ...cidrs.length > 0 ? { outboundCidrAllowlist: cidrs } : {},
739
+ ...domains.length > 0 ? { outboundDomainAllowlist: domains } : {}
740
+ };
741
+ }
646
742
  function validateModalOptions(options, mode, failure) {
647
- validateProviderOptions("Modal", options, ["environment", ...mode === "connect" ? ["sandboxId", "tokenId", "tokenSecret"] : [
743
+ const { networkBlockAll, networkAllowList, domainAllowList, regions, ...rest } = options;
744
+ validateProviderOptions("Modal", mode === "connect" ? options : rest, ["environment", ...mode === "connect" ? ["sandboxId", "tokenId", "tokenSecret"] : [
648
745
  "template",
649
746
  "appName",
650
747
  "timeoutMs",
@@ -652,6 +749,20 @@ function validateModalOptions(options, mode, failure) {
652
749
  "memoryMiB",
653
750
  ...mode === "create" ? ["tokenId", "tokenSecret", "envs"] : []
654
751
  ]], failure);
752
+ if (regions !== void 0 && (!Array.isArray(regions) || regions.length === 0 || regions.some((region) => typeof region !== "string" || !/^[a-z0-9-]+$/u.test(region)))) {
753
+ throw failure('Modal regions must be a non-empty array of region names such as "us" or "us-east".');
754
+ }
755
+ if (networkBlockAll !== void 0 && typeof networkBlockAll !== "boolean") {
756
+ throw failure("Modal networkBlockAll must be a boolean.");
757
+ }
758
+ for (const [key, value] of [["networkAllowList", networkAllowList], ["domainAllowList", domainAllowList]]) {
759
+ if (value !== void 0 && (typeof value !== "string" || parseModalAllowList(value).some((entry) => /[\s\0]/u.test(entry)))) {
760
+ throw failure(`Modal ${key} must be a comma-separated string without whitespace or null bytes in entries.`);
761
+ }
762
+ }
763
+ if (networkBlockAll && (parseModalAllowList(networkAllowList).length > 0 || parseModalAllowList(domainAllowList).length > 0)) {
764
+ throw failure("Modal networkBlockAll cannot be combined with non-empty allow lists.");
765
+ }
655
766
  if (mode === "connect" && !("sandboxId" in options && options.sandboxId)) {
656
767
  throw failure("Modal sandboxId is required.");
657
768
  }
@@ -730,12 +841,19 @@ var ModalSandboxHandle = class _ModalSandboxHandle {
730
841
  let sandbox;
731
842
  try {
732
843
  const app = await client.apps.fromName(options.appName ?? "agent-neckbeard", { createIfMissing: true });
844
+ const network = modalNetworkOptions(options);
733
845
  const image = client.images.fromRegistry(options.template ?? MODAL_DEFAULT_TEMPLATE).dockerfileCommands([
734
846
  "USER root",
735
847
  "RUN apt-get update && apt-get install -y --no-install-recommends bash python3 util-linux coreutils sudo curl ca-certificates && rm -rf /var/lib/apt/lists/*",
848
+ // The runtime starts with a fixed PATH, so images with Node elsewhere (say nvm) need links.
849
+ 'RUN for bin in node npm npx; do target="$(command -v "$bin" || true)"; if [ -n "$target" ] && [ ! -e "/usr/local/bin/$bin" ]; then ln -s "$target" "/usr/local/bin/$bin"; fi; done',
850
+ // The domain allow list only passes TLS, so apt installs in the sandbox need HTTPS sources.
851
+ ...network.outboundDomainAllowlist ? ["RUN find /etc/apt -name '*.list' -o -name '*.sources' | xargs -r sed -i 's|http://|https://|g'"] : [],
736
852
  "WORKDIR /root"
737
853
  ]);
738
854
  sandbox = await client.sandboxes.create(app, image, {
855
+ ...network,
856
+ ...options.regions ? { regions: options.regions } : {},
739
857
  timeoutMs: options.timeoutMs ?? MODAL_DEFAULT_TIMEOUT_MS,
740
858
  cpu: options.cpu,
741
859
  memoryMiB: options.memoryMiB,
@@ -2946,14 +3064,21 @@ var require = __neckbeard_createRequire(import.meta.url);
2946
3064
  }
2947
3065
  }
2948
3066
  }
2949
- for (const directory of localDirectoryUploads.directories) {
2950
- await sandbox.makeDir(posix.join(paths.agentDir, directory));
2951
- }
2952
- for (const file of localDirectoryUploads.files) {
2953
- await sandbox.writeFile(
2954
- posix.join(paths.agentDir, file.targetPath),
2955
- file.content
3067
+ if (localDirectoryUploads.directories.length > 0 || localDirectoryUploads.files.length > 0) {
3068
+ const archivePath = posix.join(paths.agentDir, `.neckbeard-local-directories-${randomUUID()}.tar.gz`);
3069
+ await sandbox.writeFile(archivePath, await createTarGz([
3070
+ ...localDirectoryUploads.directories.map((directory) => ({ path: directory })),
3071
+ ...localDirectoryUploads.files.map((file) => ({ path: file.targetPath, content: file.content }))
3072
+ ]));
3073
+ const extractResult = await sandbox.runCommand(
3074
+ `tar -xzf ${shellQuote(archivePath)} --no-same-owner -C ${shellQuote(paths.agentDir)} && rm -f ${shellQuote(archivePath)}`,
3075
+ { timeoutMs: SANDBOX_COMMAND_TIMEOUT_MS2 }
2956
3076
  );
3077
+ if (extractResult.exitCode !== 0) {
3078
+ throw new DeploymentError(
3079
+ `Failed to extract local directories: ${extractResult.stderr || extractResult.stdout}`
3080
+ );
3081
+ }
2957
3082
  }
2958
3083
  await sandbox.writeFile(paths.agentModule, result.outputFiles[0].text);
2959
3084
  await sandbox.writeFile(paths.serverModule, RUNTIME_SERVER_SOURCE);
package/docs/MODAL.md CHANGED
@@ -39,8 +39,12 @@ All settings except `provider` are optional:
39
39
  | `timeoutMs` | `3600000` | Fixed sandbox lifetime, multiples of `1000` milliseconds from `1000` through `86400000` (24 hours); e.g. `1001` is rejected before SDK I/O |
40
40
  | `cpu` | Modal default | Positive finite CPU reservation, fractional values accepted |
41
41
  | `memoryMiB` | Modal default | Positive integer memory reservation |
42
+ | `regions` | any region | Regions the sandbox may run in, such as `['us']` or `['us-east']`; see [Region Selection](#region-selection) |
43
+ | `networkBlockAll` | `false` | Block all outbound traffic; cannot be combined with non-empty allow lists |
44
+ | `networkAllowList` | unset | Comma-separated CIDR ranges the sandbox may reach, any protocol |
45
+ | `domainAllowList` | unset | Comma-separated domains the sandbox may reach over HTTPS; `*.` wildcards match the domain and its subdomains |
42
46
 
43
- The adapter extends the registry image with `USER root`, Bash, Python 3, util-linux (`flock`/`setsid`), coreutils, sudo, curl, and CA certificates. **It forces root for both setup and payload execution, even if your custom image declares a non-root user.** There is currently no user override. Custom images must support `apt-get` and provide a compatible Node.js/npm installation for `Agent`. Home and work directories are `/root`; runtime files live in `/root/agent`. The first image build can add latency; Modal caches image layers.
47
+ The adapter extends the registry image with `USER root`, Bash, Python 3, util-linux (`flock`/`setsid`), coreutils, sudo, curl, and CA certificates. **It forces root for both setup and payload execution, even if your custom image declares a non-root user.** There is currently no user override. Custom images must support `apt-get` and provide a compatible Node.js/npm installation for `Agent`. The runtime starts with a fixed `PATH`, so when the image's `node`, `npm`, or `npx` resolve elsewhere, such as an nvm install, the adapter links them into `/usr/local/bin`. Home and work directories are `/root`; runtime files live in `/root/agent`. The first image build can add latency; Modal caches image layers.
44
48
 
45
49
  Use the same sandbox settings in an Agent:
46
50
 
@@ -123,9 +127,19 @@ No encrypted or unencrypted public tunnels are created. The adapter obtains a po
123
127
  - Stop first, optionally read final diagnostics, then dispose artifacts. Disposal is irreversible and does not replace exact stop confirmation. Do not call stop after disposal; the proof required to stop has intentionally been removed.
124
128
  - `destroy()` waits for Modal termination and tolerates a provider not-found response. Other provider failures still reject. Failed `Agent.deploy()` attempts retain the shared best-effort stop/destroy cleanup and preserve the original error.
125
129
 
130
+ ## Region Selection
131
+
132
+ Without `regions`, Modal may place a sandbox in any region worldwide. Every file and command call from the host pays the round trip, so a sandbox far from the host slows deploys and turns: from a us-east host, measured per-call latency ranged from about 80 ms in us-east to about 1.5 s in ap-south. Pin `regions` near the host, preferring a broad region such as `us`, which Modal bills at 1.15x, over a narrow one such as `us-east`, at 1.75x and with a smaller pool of capacity. See [Region selection](https://modal.com/docs/guide/region-selection).
133
+
134
+ ## Network Policy
135
+
136
+ `networkBlockAll`, `networkAllowList`, and `domainAllowList` take the same shape as the Daytona options, so a Daytona network policy carries over by changing the provider. They map to Modal's `blockNetwork`, `outboundCidrAllowlist`, and `outboundDomainAllowlist` (beta). Blank lists count as unset, traffic matching either list is allowed, and without any of them Modal's default open egress applies. They are creation-only; `connect()` rejects them.
137
+
138
+ Modal matches domains by the TLS SNI, so `domainAllowList` only allows HTTPS on port 443. Plain HTTP and other TCP or UDP traffic is blocked unless its IP is in `networkAllowList`. Debian images fetch apt packages over HTTP, so when `domainAllowList` is set the adapter rewrites the image's apt sources to HTTPS, and `dependencies.apt` installs work if the mirror's domain (for example `deb.debian.org`, covered by `*.debian.org`) is allowed. A custom image whose mirror has no HTTPS endpoint can't install apt packages under a domain allow list. DNS is always allowed unless all traffic is blocked. Modal does not decrypt TLS, so an allowed SNI paired with a different `Host` header on a shared endpoint is not caught. Blocked connections are logged to the sandbox's system output. See [Sandbox networking](https://modal.com/docs/guide/sandbox-networking).
139
+
126
140
  ## Unsupported Options
127
141
 
128
- Modal config uses a strict allowlist. Unknown options are rejected rather than silently dropped, including `apiKey`, `allowPublicTraffic` (even `false`), public tunnel ports, `requestTimeoutMs`, Daytona network policies, auto-stop/auto-delete settings, idle timeout, GPUs, volumes, private registry credentials, custom working directories, snapshots, and experimental SDK features. Network policy passthrough is not part of this adapter. Modal's default outbound network policy applies.
142
+ Modal config uses a strict allowlist. Unknown options are rejected rather than silently dropped, including `apiKey`, `allowPublicTraffic` (even `false`), public tunnel ports, `requestTimeoutMs`, auto-stop/auto-delete settings, idle timeout, GPUs, volumes, private registry credentials, custom working directories, snapshots, and experimental SDK features, including runtime network policy updates.
129
143
 
130
144
  `setTimeout()` is unsupported: choose the lifetime at creation. Foreground command options support only `cwd`, `envs`, `timeoutMs`, `onStdout`, and `onStderr`; do not pass a provider-native `background` option. Use `startDetachedCommand()` instead.
131
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-neckbeard",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "description": "Deploy AI agents to E2B, Daytona, and Modal sandboxes, or local Docker containers",
5
5
  "type": "module",
6
6
  "exports": {