@madarco/agentbox 0.23.5 → 0.24.1

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.
Files changed (180) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -2
  4. package/dist/{_cloud-attach-D4OQO5AJ.js → _cloud-attach-T6GPR6LJ.js} +5 -5
  5. package/dist/{chunk-KY32JO6J.js → chunk-5KHEH47T.js} +91 -79
  6. package/dist/chunk-5KHEH47T.js.map +1 -0
  7. package/dist/{chunk-YRTM3KNT.js → chunk-6U2S6QWD.js} +219 -18
  8. package/dist/chunk-6U2S6QWD.js.map +1 -0
  9. package/dist/{chunk-JYEZ6Q5M.js → chunk-DEDTPG2D.js} +874 -146
  10. package/dist/chunk-DEDTPG2D.js.map +1 -0
  11. package/dist/chunk-G3H2L3O2.js +0 -0
  12. package/dist/{chunk-JNY5GPIM.js → chunk-I654PBHA.js} +290 -330
  13. package/dist/chunk-I654PBHA.js.map +1 -0
  14. package/dist/{chunk-6KOQRSHH.js → chunk-K2EDQGZP.js} +18 -4
  15. package/dist/chunk-K2EDQGZP.js.map +1 -0
  16. package/dist/{chunk-KZWJMNLP.js → chunk-LC4E2EIZ.js} +3 -3
  17. package/dist/{chunk-KZWJMNLP.js.map → chunk-LC4E2EIZ.js.map} +1 -1
  18. package/dist/{chunk-DADOEMXP.js → chunk-NACA6AM7.js} +183 -49
  19. package/dist/chunk-NACA6AM7.js.map +1 -0
  20. package/dist/{chunk-FX32NZD4.js → chunk-RYQLFKCP.js} +20 -10
  21. package/dist/chunk-RYQLFKCP.js.map +1 -0
  22. package/dist/{chunk-QT3SHMLY.js → chunk-UIRBYL4G.js} +43 -12
  23. package/dist/chunk-UIRBYL4G.js.map +1 -0
  24. package/dist/chunk-WJFZJZIM.js +0 -0
  25. package/dist/chunk-WLHJZPFJ.js +845 -0
  26. package/dist/chunk-WLHJZPFJ.js.map +1 -0
  27. package/dist/cloud-poller-SUNA6ZQC-7M5LJHHE.js +0 -0
  28. package/dist/dist-3KIJ2KQ2.js +1437 -0
  29. package/dist/dist-3KIJ2KQ2.js.map +1 -0
  30. package/dist/{dist-564EDHFF.js → dist-7OUOHQPA.js} +196 -151
  31. package/dist/dist-7OUOHQPA.js.map +1 -0
  32. package/dist/{dist-CAT2TN75.js → dist-B7TNWGVG.js} +8 -4
  33. package/dist/{dist-UDQMBWYW.js → dist-KYV3LEHG.js} +10 -6
  34. package/dist/{dist-EAR4BLL2.js → dist-PHYCFYKH.js} +37 -17
  35. package/dist/dist-PHYCFYKH.js.map +1 -0
  36. package/dist/{dist-2BTJQUJS.js → dist-T5MXBZGP.js} +2 -2
  37. package/dist/{dist-O5Y4X4C5.js → dist-Z7KEPQC7.js} +6 -6
  38. package/dist/index.js +2617 -1094
  39. package/dist/index.js.map +1 -1
  40. package/dist/{prepared-state-BUO75YLZ-PW64VQMT.js → prepared-state-BUO75YLZ-RQRFFBJW.js} +2 -2
  41. package/package.json +28 -28
  42. package/runtime/_shared/agentbox-checkpoint-cleanup +0 -0
  43. package/runtime/_shared/agentbox-codex-hooks.json +1 -1
  44. package/runtime/_shared/agentbox-dockerd-start +0 -0
  45. package/runtime/_shared/agentbox-open +0 -0
  46. package/runtime/_shared/agentbox-portless-trust +0 -0
  47. package/runtime/_shared/agentbox-vnc-start +0 -0
  48. package/runtime/_shared/ctl.cjs +468 -97
  49. package/runtime/_shared/gh-shim +0 -0
  50. package/runtime/_shared/git-shim +53 -3
  51. package/runtime/_shared/linear-shim +0 -0
  52. package/runtime/_shared/ntn-shim +0 -0
  53. package/runtime/daytona/custom-system-CLAUDE.md +1 -1
  54. package/runtime/digitalocean/agentbox-checkpoint-cleanup +55 -0
  55. package/runtime/digitalocean/agentbox-codex-hooks.json +68 -0
  56. package/runtime/digitalocean/agentbox-dockerd-start +145 -0
  57. package/runtime/digitalocean/agentbox-open +28 -0
  58. package/runtime/digitalocean/agentbox-portless-trust +82 -0
  59. package/runtime/digitalocean/agentbox-setup-skill.md +317 -0
  60. package/runtime/digitalocean/agentbox-vnc-start +102 -0
  61. package/runtime/digitalocean/claude-managed-settings.json +116 -0
  62. package/runtime/digitalocean/ctl.cjs +27852 -0
  63. package/runtime/digitalocean/custom-system-CLAUDE.md +39 -0
  64. package/runtime/digitalocean/gh-shim +344 -0
  65. package/runtime/digitalocean/git-shim +181 -0
  66. package/runtime/digitalocean/linear-shim +181 -0
  67. package/runtime/digitalocean/ntn-shim +95 -0
  68. package/runtime/digitalocean/opencode-agentbox-plugin.js +76 -0
  69. package/runtime/digitalocean/scripts/install-box.sh +462 -0
  70. package/runtime/docker/Dockerfile.box +5 -0
  71. package/runtime/docker/packages/ctl/dist/bin.cjs +468 -97
  72. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-checkpoint-cleanup +0 -0
  73. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-codex-hooks.json +1 -1
  74. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-dockerd-start +0 -0
  75. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-open +0 -0
  76. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-portless-trust +0 -0
  77. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-sshd-start +0 -0
  78. package/runtime/docker/packages/sandbox-docker/scripts/agentbox-vnc-start +0 -0
  79. package/runtime/docker/packages/sandbox-docker/scripts/chromium-resolver +0 -0
  80. package/runtime/docker/packages/sandbox-docker/scripts/custom-system-CLAUDE.md +2 -1
  81. package/runtime/docker/packages/sandbox-docker/scripts/gh-shim +0 -0
  82. package/runtime/docker/packages/sandbox-docker/scripts/git-shim +53 -3
  83. package/runtime/docker/packages/sandbox-docker/scripts/linear-shim +0 -0
  84. package/runtime/docker/packages/sandbox-docker/scripts/ntn-shim +0 -0
  85. package/runtime/e2b/agentbox-checkpoint-cleanup +0 -0
  86. package/runtime/e2b/agentbox-codex-hooks.json +1 -1
  87. package/runtime/e2b/agentbox-dockerd-start +0 -0
  88. package/runtime/e2b/agentbox-open +0 -0
  89. package/runtime/e2b/agentbox-vnc-start +0 -0
  90. package/runtime/e2b/ctl.cjs +468 -97
  91. package/runtime/e2b/custom-system-CLAUDE.md +6 -3
  92. package/runtime/e2b/gh-shim +0 -0
  93. package/runtime/e2b/git-shim +53 -3
  94. package/runtime/e2b/linear-shim +0 -0
  95. package/runtime/e2b/ntn-shim +0 -0
  96. package/runtime/e2b/scripts/build-template.sh +16 -0
  97. package/runtime/hetzner/agentbox-checkpoint-cleanup +0 -0
  98. package/runtime/hetzner/agentbox-codex-hooks.json +1 -1
  99. package/runtime/hetzner/agentbox-dockerd-start +0 -0
  100. package/runtime/hetzner/agentbox-open +0 -0
  101. package/runtime/hetzner/agentbox-portless-trust +0 -0
  102. package/runtime/hetzner/agentbox-vnc-start +0 -0
  103. package/runtime/hetzner/ctl.cjs +468 -97
  104. package/runtime/hetzner/custom-system-CLAUDE.md +1 -1
  105. package/runtime/hetzner/gh-shim +0 -0
  106. package/runtime/hetzner/git-shim +53 -3
  107. package/runtime/hetzner/linear-shim +0 -0
  108. package/runtime/hetzner/ntn-shim +0 -0
  109. package/runtime/hetzner/scripts/install-box.sh +5 -0
  110. package/runtime/hub/apps/hub/.next/BUILD_ID +1 -1
  111. package/runtime/hub/apps/hub/.next/build-manifest.json +3 -3
  112. package/runtime/hub/apps/hub/.next/server/app/(dashboard)/settings/page_client-reference-manifest.js +1 -1
  113. package/runtime/hub/apps/hub/.next/server/app/_global-error.html +1 -1
  114. package/runtime/hub/apps/hub/.next/server/app/_global-error.rsc +1 -1
  115. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  116. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  117. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  118. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  119. package/runtime/hub/apps/hub/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  120. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0d1lmiq._.js +12 -12
  121. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__0keu6we._.js +1 -1
  122. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1bqbkd5._.js +1 -1
  123. package/runtime/hub/apps/hub/.next/server/chunks/[root-of-the-server]__1qa4a0v._.js +1 -1
  124. package/runtime/hub/apps/hub/.next/server/chunks/_0760z6y._.js +8 -8
  125. package/runtime/hub/apps/hub/.next/server/chunks/ssr/_0ro6vh6._.js +1 -1
  126. package/runtime/hub/apps/hub/.next/server/chunks/ssr/apps_hub_0b_hsjl._.js +1 -1
  127. package/runtime/hub/apps/hub/.next/server/middleware-build-manifest.js +3 -3
  128. package/runtime/hub/apps/hub/.next/server/pages/500.html +1 -1
  129. package/runtime/hub/apps/hub/.next/static/chunks/380qcmusmigzz.js +1 -0
  130. package/runtime/hub/apps/hub/{auth-675P3LQS.js → auth-Q447765C.js} +2 -2
  131. package/runtime/hub/apps/hub/{auth-config-AOBEKRZQ.js → auth-config-SIL635ZD.js} +2 -2
  132. package/runtime/hub/apps/hub/{chunk-FSEPYTQ6.js → chunk-3VE7AYVK.js} +594 -145
  133. package/runtime/hub/apps/hub/{chunk-EXQCBM5Q.js → chunk-64WEKO34.js} +42 -11
  134. package/runtime/hub/apps/hub/{chunk-56YQBVN2.js → chunk-DZPQB2JZ.js} +1 -1
  135. package/runtime/hub/apps/hub/{chunk-7M6FXZIO.js → chunk-FGBXEXUV.js} +350 -292
  136. package/runtime/hub/apps/hub/{chunk-Z7ZAL24C.js → chunk-YVELHPNY.js} +218 -17
  137. package/runtime/hub/apps/hub/{dist-EKQHCXWE.js → dist-33ZNVTC6.js} +183 -49
  138. package/runtime/hub/apps/hub/{dist-V4TJ44MT.js → dist-4SXAJBOC.js} +195 -150
  139. package/runtime/hub/apps/hub/{dist-QIXUPGPP.js → dist-EPJFN2J3.js} +116 -86
  140. package/runtime/hub/apps/hub/{dist-STQK5XM6.js → dist-GF5EBRNG.js} +1 -1
  141. package/runtime/hub/apps/hub/{dist-JGZ55OIJ.js → dist-UJVIROA4.js} +19 -5
  142. package/runtime/hub/apps/hub/dist-XULFTIMT.js +2212 -0
  143. package/runtime/hub/apps/hub/{dist-GGWYKXJE.js → dist-YM5J25H6.js} +7 -3
  144. package/runtime/hub/apps/hub/{hub-token-2BZFBBW3.js → hub-token-UITZEWVP.js} +2 -2
  145. package/runtime/hub/apps/hub/package.json +1 -0
  146. package/runtime/hub/apps/hub/{prepared-state-BUO75YLZ-UICXTY25.js → prepared-state-BUO75YLZ-O4GZMDRF.js} +1 -1
  147. package/runtime/hub/apps/hub/server.js +17 -15
  148. package/runtime/relay/bin.cjs +275 -59
  149. package/runtime/vercel/agentbox-checkpoint-cleanup +0 -0
  150. package/runtime/vercel/agentbox-codex-hooks.json +1 -1
  151. package/runtime/vercel/agentbox-dockerd-start +0 -0
  152. package/runtime/vercel/agentbox-open +0 -0
  153. package/runtime/vercel/agentbox-vnc-start +0 -0
  154. package/runtime/vercel/ctl.cjs +468 -97
  155. package/runtime/vercel/custom-system-CLAUDE.md +3 -2
  156. package/runtime/vercel/gh-shim +0 -0
  157. package/runtime/vercel/git-shim +53 -3
  158. package/runtime/vercel/linear-shim +0 -0
  159. package/runtime/vercel/ntn-shim +0 -0
  160. package/runtime/vercel/scripts/provision.sh +16 -0
  161. package/dist/chunk-6KOQRSHH.js.map +0 -1
  162. package/dist/chunk-DADOEMXP.js.map +0 -1
  163. package/dist/chunk-FX32NZD4.js.map +0 -1
  164. package/dist/chunk-JNY5GPIM.js.map +0 -1
  165. package/dist/chunk-JYEZ6Q5M.js.map +0 -1
  166. package/dist/chunk-KY32JO6J.js.map +0 -1
  167. package/dist/chunk-QT3SHMLY.js.map +0 -1
  168. package/dist/chunk-YRTM3KNT.js.map +0 -1
  169. package/dist/dist-564EDHFF.js.map +0 -1
  170. package/dist/dist-EAR4BLL2.js.map +0 -1
  171. package/runtime/hub/apps/hub/.next/static/chunks/0joh_xsiowfc4.js +0 -1
  172. /package/dist/{_cloud-attach-D4OQO5AJ.js.map → _cloud-attach-T6GPR6LJ.js.map} +0 -0
  173. /package/dist/{dist-2BTJQUJS.js.map → dist-B7TNWGVG.js.map} +0 -0
  174. /package/dist/{dist-CAT2TN75.js.map → dist-KYV3LEHG.js.map} +0 -0
  175. /package/dist/{dist-O5Y4X4C5.js.map → dist-T5MXBZGP.js.map} +0 -0
  176. /package/dist/{dist-UDQMBWYW.js.map → dist-Z7KEPQC7.js.map} +0 -0
  177. /package/dist/{prepared-state-BUO75YLZ-PW64VQMT.js.map → prepared-state-BUO75YLZ-RQRFFBJW.js.map} +0 -0
  178. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → 3tBexekuTKIr_6nriQjKE}/_buildManifest.js +0 -0
  179. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → 3tBexekuTKIr_6nriQjKE}/_clientMiddlewareManifest.js +0 -0
  180. /package/runtime/hub/apps/hub/.next/static/{lOi70Di6lcnEBsUUHKrQ5 → 3tBexekuTKIr_6nriQjKE}/_ssgManifest.js +0 -0
@@ -12,36 +12,39 @@ import {
12
12
  } from "./chunk-OF242BLD.js";
13
13
  import {
14
14
  createCloudProvider
15
- } from "./chunk-Z7ZAL24C.js";
15
+ } from "./chunk-YVELHPNY.js";
16
16
  import {
17
17
  detectPortless,
18
18
  portlessDoctorRow
19
- } from "./chunk-7M6FXZIO.js";
19
+ } from "./chunk-FGBXEXUV.js";
20
20
  import "./chunk-3LAHFDJF.js";
21
21
  import {
22
22
  UserFacingError,
23
23
  claudeInstallFingerprint,
24
24
  computeContextSha256,
25
+ describeInbound,
25
26
  errSummary,
26
27
  hostOpenCommand,
27
28
  mintSshKey,
29
+ parseInboundSpec,
28
30
  preparedStatePathFor,
29
31
  readCliStamp,
30
32
  readPreparedStateRaw,
33
+ resolveInboundSources,
31
34
  stageAgentsStaticForUpload,
32
35
  stageClaudeStaticForUpload,
33
36
  stageCodexStaticForUpload,
34
37
  stageOpencodeStaticForUpload,
35
38
  writeManagedSecrets,
36
39
  writePreparedStateRaw
37
- } from "./chunk-FSEPYTQ6.js";
40
+ } from "./chunk-3VE7AYVK.js";
38
41
  import {
39
42
  execa
40
43
  } from "./chunk-EFW34I43.js";
41
- import "./chunk-EXQCBM5Q.js";
44
+ import "./chunk-64WEKO34.js";
42
45
  import "./chunk-TZFWAJVB.js";
43
46
 
44
- // ../../packages/sandbox-hetzner/dist/chunk-3ZWBEZND.js
47
+ // ../../packages/sandbox-hetzner/dist/chunk-YIQFCUWT.js
45
48
  import { existsSync, readFileSync } from "fs";
46
49
  import { homedir } from "os";
47
50
  import { resolve } from "path";
@@ -216,6 +219,21 @@ function makeHetznerClient(opts = {}) {
216
219
  const r = await req("GET", `/images/${String(id)}`);
217
220
  return r?.image ?? null;
218
221
  },
222
+ async listServerTypes() {
223
+ const params = new URLSearchParams();
224
+ params.set("per_page", "50");
225
+ const all = [];
226
+ let pageNum = 1;
227
+ while (true) {
228
+ params.set("page", String(pageNum));
229
+ const r = await reqExpect("GET", `/server_types?${params.toString()}`);
230
+ all.push(...r.server_types);
231
+ const next = r.meta?.pagination?.next_page;
232
+ if (typeof next !== "number") break;
233
+ pageNum = next;
234
+ }
235
+ return all;
236
+ },
219
237
  async listImages(opts2) {
220
238
  const params = new URLSearchParams();
221
239
  if (opts2?.type) params.set("type", opts2.type);
@@ -537,14 +555,15 @@ function errorSummary(err) {
537
555
  function truncate(s, max = 160) {
538
556
  return s.length > max ? `${s.slice(0, max)}\u2026` : s;
539
557
  }
540
- function sshOnlyInboundRule(sourceCidr) {
558
+ function sshOnlyInboundRule(sources) {
559
+ const source_ips = Array.isArray(sources) ? sources : [sources];
541
560
  return [
542
561
  {
543
562
  direction: "in",
544
563
  protocol: "tcp",
545
564
  port: "22",
546
- source_ips: [sourceCidr],
547
- description: "agentbox: SSH from host egress IP only"
565
+ source_ips,
566
+ description: "agentbox: SSH inbound"
548
567
  }
549
568
  ];
550
569
  }
@@ -578,7 +597,7 @@ async function createPerBoxFirewall(client2, opts) {
578
597
  { method: "createFirewall", retryOnAmbiguous: false, attemptTimeoutMs: 6e4 },
579
598
  () => client2.createFirewall({
580
599
  name: opts.name,
581
- rules: sshOnlyInboundRule(opts.sourceCidr),
600
+ rules: sshOnlyInboundRule(opts.sources),
582
601
  labels: {
583
602
  "agentbox.managed": "true",
584
603
  "agentbox.role": "box",
@@ -587,10 +606,10 @@ async function createPerBoxFirewall(client2, opts) {
587
606
  })
588
607
  );
589
608
  }
590
- async function syncFirewallSource(client2, firewallId, sourceCidr) {
609
+ async function syncFirewallSource(client2, firewallId, sources) {
591
610
  await withHetznerRetry(
592
611
  { method: "setFirewallRules", retryOnAmbiguous: true, attemptTimeoutMs: 6e4 },
593
- () => client2.setFirewallRules(firewallId, sshOnlyInboundRule(sourceCidr))
612
+ () => client2.setFirewallRules(firewallId, sshOnlyInboundRule(sources))
594
613
  );
595
614
  }
596
615
  async function deletePerBoxFirewall(client2, firewallId, opts = {}) {
@@ -617,9 +636,10 @@ async function deletePerBoxFirewall(client2, firewallId, opts = {}) {
617
636
  }
618
637
  }
619
638
  }
620
- function firewallNeedsSync(allowedSource, currentEgress) {
621
- if (allowedSource === "0.0.0.0/0") return false;
622
- return allowedSource !== currentEgress;
639
+ function firewallNeedsSync(allowedSources, currentEgress) {
640
+ const list = Array.isArray(allowedSources) ? allowedSources : allowedSources ? [allowedSources] : [];
641
+ if (list.includes("0.0.0.0/0")) return false;
642
+ return !list.includes(currentEgress);
623
643
  }
624
644
  function normalizeSourceCidr(raw) {
625
645
  const trimmed = raw.trim();
@@ -916,6 +936,76 @@ async function pollUntil(label, check, opts = {}) {
916
936
  interval = Math.min(interval * 2, max);
917
937
  }
918
938
  }
939
+ function isDeprecated(t) {
940
+ return t.deprecated === true || t.deprecation !== void 0 && t.deprecation !== null;
941
+ }
942
+ function suggestTypes(catalog, limit = 6) {
943
+ return catalog.filter((t) => t.architecture === "x86" && !isDeprecated(t)).map((t) => t.name).slice(0, limit);
944
+ }
945
+ function offeredLocations(t) {
946
+ const seen = /* @__PURE__ */ new Set();
947
+ for (const p of t.prices) {
948
+ if (p.location) seen.add(p.location);
949
+ }
950
+ return [...seen];
951
+ }
952
+ function validateServerChoice(choice, catalog, image) {
953
+ const { serverType, location } = choice;
954
+ const type = catalog.find((t) => t.name === serverType);
955
+ if (!type) {
956
+ const suggestions = suggestTypes(catalog);
957
+ const hint = suggestions.length > 0 ? ` Valid types include: ${suggestions.join(", ")}.` : "";
958
+ throw new UserFacingError(
959
+ `Hetzner server type "${serverType}" does not exist.${hint}
960
+ Set one with \`--size <type>\` or \`agentbox config set box.sizeHetzner <type>\`.`
961
+ );
962
+ }
963
+ if (type.architecture !== "x86") {
964
+ throw new UserFacingError(
965
+ `Hetzner server type "${serverType}" is ${type.architecture} (ARM). AgentBox base snapshots are x86-only, so ARM types (e.g. \`cax*\`) are not supported.
966
+ Pick an x86 type instead: ${suggestTypes(catalog).join(", ")}.`
967
+ );
968
+ }
969
+ if (isDeprecated(type)) {
970
+ const after = type.deprecation?.unavailable_after;
971
+ const when = after ? ` (unavailable after ${after})` : "";
972
+ throw new UserFacingError(
973
+ `Hetzner server type "${serverType}" is deprecated${when} and can't be used for new servers.
974
+ Pick a current type instead: ${suggestTypes(catalog).join(", ")}.`
975
+ );
976
+ }
977
+ if (image && typeof image.disk_size === "number" && type.disk < image.disk_size) {
978
+ throw new UserFacingError(
979
+ `Hetzner server type "${serverType}" has a ${String(type.disk)} GB disk, but the base snapshot needs at least ${String(image.disk_size)} GB.
980
+ Choose a larger type (bigger plans have bigger disks).`
981
+ );
982
+ }
983
+ const locations = offeredLocations(type);
984
+ if (locations.length > 0 && !locations.includes(location)) {
985
+ throw new UserFacingError(
986
+ `Hetzner server type "${serverType}" is not offered in location "${location}".
987
+ It is available in: ${locations.join(", ")}.
988
+ Pick one with \`--location <name>\` or \`agentbox config set box.hetznerLocation <name>\`.`
989
+ );
990
+ }
991
+ }
992
+ function mapHetznerProvisionError(err, choice) {
993
+ if (!(err instanceof HetznerApiError)) return err;
994
+ const { serverType, location } = choice;
995
+ if (err.code === "resource_limit_exceeded") {
996
+ return new UserFacingError(
997
+ `Hetzner refused to create the server: your account resource limit was exceeded (${err.message}).
998
+ New Hetzner Cloud accounts start with a low server limit. Request an increase in the Hetzner Console (Limits page: https://console.hetzner.cloud/ \u2192 your project \u2192 Limits), then retry.`
999
+ );
1000
+ }
1001
+ if (err.code === "resource_unavailable" || err.code === "placement_error") {
1002
+ return new UserFacingError(
1003
+ `Hetzner has no capacity for "${serverType}" in "${location}" right now (${err.message}).
1004
+ Retry, or pick another datacenter with \`--location fsn1\` / \`hel1\` / \`ash\` (or \`agentbox config set box.hetznerLocation <name>\`).`
1005
+ );
1006
+ }
1007
+ return err;
1008
+ }
919
1009
  async function mintPrepareKey() {
920
1010
  const root = resolve4(homedirOrCwd(), ".agentbox", "hetzner", `prepare-${Date.now().toString(36)}`);
921
1011
  const key = await mintSshKey(root, `agentbox-prepare-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}`);
@@ -1090,7 +1180,7 @@ async function prepareHetzner(opts = {}) {
1090
1180
  progress(`creating firewall ${firewallName} (source ${source})`);
1091
1181
  const firewall = await createPerBoxFirewall(client2, {
1092
1182
  name: firewallName,
1093
- sourceCidr: source,
1183
+ sources: [source],
1094
1184
  labels: { "agentbox.role": "prepare" }
1095
1185
  });
1096
1186
  firewallId = firewall.id;
@@ -1286,6 +1376,9 @@ var prepareHetznerProvider = (req) => prepareHetzner({
1286
1376
  name: req.name,
1287
1377
  hostWorkspace: req.hostWorkspace ?? process.cwd(),
1288
1378
  force: req.force,
1379
+ // Datacenter for the temp bake VPS (defaults to nbg1 when unset). Resolved
1380
+ // by the CLI from `--location` / `box.hetznerLocation`.
1381
+ location: req.location,
1289
1382
  onLog: req.onLog,
1290
1383
  // Forward the Claude install mode (native | npm). Without this the Hetzner
1291
1384
  // bake always ran the native `curl install.sh`, whose CDN 403s datacenter
@@ -1535,7 +1628,7 @@ async function pickFreePort() {
1535
1628
  var HETZNER_DEFAULT_BOX_IMAGE_REF = "agentbox-base";
1536
1629
  var SCAFFOLDING_FALLBACK_IMAGE = "agentbox/box:dev";
1537
1630
  var VPS_USER = "vscode";
1538
- var PROVISION_SSH_DEADLINE_MS = 5 * 6e4;
1631
+ var PROVISION_SSH_DEADLINE_MS = 10 * 6e4;
1539
1632
  var ACTION_DEADLINE_MS = 5 * 6e4;
1540
1633
  var SNAPSHOT_DEADLINE_MS2 = 20 * 6e4;
1541
1634
  var HETZNER_DEFAULT_SERVER_TYPE = "cx23";
@@ -1643,11 +1736,11 @@ async function firewallEgressStatus(sandboxId) {
1643
1736
  if (!Number.isFinite(firewallId)) return null;
1644
1737
  const firewall = await client().getFirewall(firewallId);
1645
1738
  const sshRule = firewall?.rules.find((r) => r.direction === "in" && r.port === "22");
1646
- const allowedSource = sshRule?.source_ips?.[0];
1739
+ const allowedSources = sshRule?.source_ips ?? [];
1647
1740
  const currentEgress = `${await detectEgressIp({})}/32`;
1648
1741
  return {
1649
1742
  firewallId,
1650
- allowedSource,
1743
+ allowedSources,
1651
1744
  currentEgress,
1652
1745
  boxRef: server.labels["agentbox.box"] ?? sandboxId
1653
1746
  };
@@ -1662,11 +1755,11 @@ async function ensureTunnel(sandboxId, state, vpsIp) {
1662
1755
  });
1663
1756
  } catch (err) {
1664
1757
  const s = await firewallEgressStatus(sandboxId).catch(() => null);
1665
- if (s && firewallNeedsSync(s.allowedSource, s.currentEgress)) {
1758
+ if (s && firewallNeedsSync(s.allowedSources, s.currentEgress)) {
1666
1759
  throw new Error(
1667
1760
  `${err.message}
1668
1761
 
1669
- hetzner: SSH is blocked by the box firewall \u2014 it allows ${s.allowedSource ?? "(no rule)"} but your egress IP is now ${s.currentEgress}. Your IP changed; run:
1762
+ hetzner: SSH is blocked by the box firewall \u2014 it allows ${s.allowedSources.join(", ") || "(no rule)"} but your egress IP is now ${s.currentEgress}. Your IP changed; run:
1670
1763
  agentbox hetzner firewall sync ${s.boxRef}
1671
1764
  (or \`agentbox recover ${s.boxRef}\`, which auto-syncs).`
1672
1765
  );
@@ -1703,9 +1796,17 @@ var hetznerBackend = {
1703
1796
  const progress = (s) => onLog(`hetzner: ${s}`);
1704
1797
  await ensureHetznerBaseSnapshot();
1705
1798
  const imageRef = await resolveImageId(c, req);
1799
+ const serverType = req.size && req.size.trim() || HETZNER_DEFAULT_SERVER_TYPE;
1800
+ const location = req.location && req.location.trim() || HETZNER_DEFAULT_LOCATION;
1801
+ const choice = { serverType, location };
1802
+ const image = typeof imageRef === "number" ? await c.getImage(imageRef) : null;
1803
+ const catalog = await c.listServerTypes();
1804
+ validateServerChoice(choice, catalog, image);
1805
+ const inboundPolicy = parseInboundSpec(req.inbound);
1706
1806
  const egressOverride = req.env?.AGENTBOX_HETZNER_FIREWALL_SOURCE ?? process.env.AGENTBOX_HETZNER_FIREWALL_SOURCE;
1707
- const source = egressOverride ? normalizeSourceCidr(egressOverride) : `${await detectEgressIp({ onLog })}/32`;
1708
- progress(`firewall source: ${source}`);
1807
+ const hostEgress = inboundPolicy.mode === "open" ? null : egressOverride ? normalizeSourceCidr(egressOverride) : `${await detectEgressIp({ onLog })}/32`;
1808
+ const sources = resolveInboundSources(inboundPolicy, hostEgress);
1809
+ progress(`firewall inbound: ${describeInbound(inboundPolicy)} -> ${sources.join(", ")}`);
1709
1810
  const stamp = Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 8);
1710
1811
  const tempDir = resolvePath(
1711
1812
  process.env.HOME ?? process.cwd(),
@@ -1720,7 +1821,7 @@ var hetznerBackend = {
1720
1821
  try {
1721
1822
  const firewall = await createPerBoxFirewall(c, {
1722
1823
  name: `agentbox-${req.name}-${stamp}`,
1723
- sourceCidr: source,
1824
+ sources,
1724
1825
  labels: {
1725
1826
  "agentbox.box": req.name,
1726
1827
  "agentbox.role": "box"
@@ -1733,29 +1834,34 @@ var hetznerBackend = {
1733
1834
  boxName: req.name,
1734
1835
  boxEnv: Object.keys(boxEnv).length > 0 ? boxEnv : void 0
1735
1836
  });
1736
- const serverType = req.size && req.size.trim() || HETZNER_DEFAULT_SERVER_TYPE;
1737
1837
  progress(
1738
- `creating VPS '${req.name}' from image ${String(imageRef)} (${serverType} / ${HETZNER_DEFAULT_LOCATION})`
1739
- );
1740
- const created = await withHetznerRetry(
1741
- { method: "createServer", retryOnAmbiguous: false, attemptTimeoutMs: 12e4 },
1742
- () => c.createServer({
1743
- name: `agentbox-${req.name}-${stamp}`,
1744
- server_type: serverType,
1745
- image: imageRef,
1746
- location: HETZNER_DEFAULT_LOCATION,
1747
- user_data: cloudInit,
1748
- firewalls: [{ firewall: firewall.id }],
1749
- labels: {
1750
- "agentbox.managed": "true",
1751
- "agentbox.role": "box",
1752
- "agentbox.box": req.name,
1753
- "agentbox.firewall": String(firewall.id)
1754
- },
1755
- start_after_create: true
1756
- })
1838
+ `creating VPS '${req.name}' from image ${String(imageRef)} (${serverType} / ${location})`
1757
1839
  );
1840
+ let created;
1841
+ try {
1842
+ created = await withHetznerRetry(
1843
+ { method: "createServer", retryOnAmbiguous: false, attemptTimeoutMs: 12e4 },
1844
+ () => c.createServer({
1845
+ name: `agentbox-${req.name}-${stamp}`,
1846
+ server_type: serverType,
1847
+ image: imageRef,
1848
+ location,
1849
+ user_data: cloudInit,
1850
+ firewalls: [{ firewall: firewall.id }],
1851
+ labels: {
1852
+ "agentbox.managed": "true",
1853
+ "agentbox.role": "box",
1854
+ "agentbox.box": req.name,
1855
+ "agentbox.firewall": String(firewall.id)
1856
+ },
1857
+ start_after_create: true
1858
+ })
1859
+ );
1860
+ } catch (createErr) {
1861
+ throw mapHetznerProvisionError(createErr, choice);
1862
+ }
1758
1863
  serverId = created.server.id;
1864
+ const provisioned = created.server.server_type;
1759
1865
  const vpsIp = created.server.public_net.ipv4?.ip;
1760
1866
  if (!vpsIp) {
1761
1867
  throw new Error(`hetzner: server ${String(serverId)} came up without an IPv4 address`);
@@ -1770,11 +1876,21 @@ var hetznerBackend = {
1770
1876
  await rm2(pendingParent, { recursive: true, force: true });
1771
1877
  const up = await waitForSsh(buildSshTarget(state, vpsIp), PROVISION_SSH_DEADLINE_MS);
1772
1878
  if (!up) {
1773
- throw new Error(`hetzner: ssh on ${vpsIp} did not come up within ${String(PROVISION_SSH_DEADLINE_MS / 1e3)}s`);
1879
+ throw new Error(
1880
+ `hetzner: ssh on ${vpsIp} did not come up within ${String(PROVISION_SSH_DEADLINE_MS / 1e3)}s; the server has been deleted. This is usually transient \u2014 just retry the create. If it keeps failing, check that your host's egress IP is stable (the box firewall is locked to it, so a mid-provision IP change blocks ssh).`
1881
+ );
1774
1882
  }
1775
1883
  await ensureTunnel(sandboxId, state, vpsIp);
1776
1884
  progress("ssh up; ControlMaster open");
1777
- return { sandboxId };
1885
+ return {
1886
+ sandboxId,
1887
+ inbound: inboundPolicy,
1888
+ resources: {
1889
+ cpu: provisioned.cores,
1890
+ memory: provisioned.memory,
1891
+ disk: provisioned.disk
1892
+ }
1893
+ };
1778
1894
  } catch (err) {
1779
1895
  if (serverId !== null) {
1780
1896
  progress(`cleanup \u2014 deleting server ${String(serverId)} after provision failure`);
@@ -1838,7 +1954,7 @@ var hetznerBackend = {
1838
1954
  const up = await waitForSsh(buildSshTarget(state, vpsIp), PROVISION_SSH_DEADLINE_MS);
1839
1955
  if (!up) {
1840
1956
  throw new Error(
1841
- `hetzner: ssh on ${vpsIp} did not come up within ${String(PROVISION_SSH_DEADLINE_MS / 1e3)}s after start`
1957
+ `hetzner: ssh on ${vpsIp} did not come up within ${String(PROVISION_SSH_DEADLINE_MS / 1e3)}s after start. This is usually transient \u2014 retry (\`agentbox start\` / \`agentbox recover\`). If it persists, check that your host's egress IP is stable (the box firewall is locked to it, so an IP change blocks ssh).`
1842
1958
  );
1843
1959
  }
1844
1960
  },
@@ -1975,14 +2091,30 @@ var hetznerBackend = {
1975
2091
  return { url: `http://127.0.0.1:${String(localPort)}` };
1976
2092
  },
1977
2093
  async repairReachability(h) {
2094
+ const policy = h.inbound ?? { mode: "locked", sources: [] };
2095
+ if (policy.mode === "open") return { changed: false };
1978
2096
  const s = await firewallEgressStatus(h.sandboxId).catch(() => null);
1979
- if (!s || !firewallNeedsSync(s.allowedSource, s.currentEgress)) return { changed: false };
1980
- await syncFirewallSource(client(), s.firewallId, s.currentEgress);
2097
+ if (!s || !firewallNeedsSync(s.allowedSources, s.currentEgress)) return { changed: false };
2098
+ const sources = resolveInboundSources(policy, s.currentEgress);
2099
+ await syncFirewallSource(client(), s.firewallId, sources);
1981
2100
  return {
1982
2101
  changed: true,
1983
- detail: `firewall updated: SSH now allowed from ${s.currentEgress} (was ${s.allowedSource ?? "(no rule)"})`
2102
+ detail: `firewall updated: SSH now allowed from ${sources.join(", ")} (was ${s.allowedSources.join(", ") || "(no rule)"})`
1984
2103
  };
1985
2104
  },
2105
+ async setInbound(h, policy) {
2106
+ const id = Number.parseInt(h.sandboxId, 10);
2107
+ const server = await client().getServer(id);
2108
+ if (!server) throw new Error(`hetzner: server ${h.sandboxId} not found`);
2109
+ const firewallId = Number.parseInt(server.labels["agentbox.firewall"] ?? "", 10);
2110
+ if (!Number.isFinite(firewallId)) {
2111
+ throw new Error(`hetzner: no per-box firewall recorded for server ${h.sandboxId}`);
2112
+ }
2113
+ const hostEgress = policy.mode === "open" ? null : `${await detectEgressIp({})}/32`;
2114
+ const sources = resolveInboundSources(policy, hostEgress);
2115
+ await syncFirewallSource(client(), firewallId, sources);
2116
+ return { sources };
2117
+ },
1986
2118
  async startInBoxPortless(h, opts) {
1987
2119
  const tlsFlag = opts.tls ? "" : "--no-tls";
1988
2120
  const startCmd = `sudo portless proxy start ${tlsFlag} -p ${String(opts.proxyPort)}`.replace(/\s+/g, " ");
@@ -2241,6 +2373,7 @@ export {
2241
2373
  isAttemptTimeout,
2242
2374
  isRetriable,
2243
2375
  makeHetznerClient,
2376
+ mapHetznerProvisionError,
2244
2377
  maskKey,
2245
2378
  mintPrepareKey,
2246
2379
  mintSshKey,
@@ -2262,6 +2395,7 @@ export {
2262
2395
  sshOptArgs,
2263
2396
  syncFirewallSource,
2264
2397
  updatePreparedState,
2398
+ validateServerChoice,
2265
2399
  waitForSsh,
2266
2400
  withHetznerRetry,
2267
2401
  writePreparedState