@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.40

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 (97) hide show
  1. package/README.md +126 -83
  2. package/box/Dockerfile +5 -54
  3. package/box/README.md +9 -3
  4. package/box/build-daytona.py +2 -2
  5. package/box/build-e2b.mjs +1 -1
  6. package/box/install.sh +87 -0
  7. package/box/recipe.d.mts +5 -0
  8. package/box/recipe.mjs +12 -10
  9. package/dist/agent37.d.ts +17 -4
  10. package/dist/agent37.js +98 -17
  11. package/dist/box-image.d.ts +14 -0
  12. package/dist/box-image.js +24 -0
  13. package/dist/computerd-linux-amd64 +0 -0
  14. package/dist/computerd-linux-arm64 +0 -0
  15. package/dist/computerd.json +2 -2
  16. package/dist/conformance/agent37.d.ts +9 -4
  17. package/dist/conformance/agent37.js +23 -11
  18. package/dist/conformance/browserbase.js +3 -3
  19. package/dist/conformance/cases/apps.d.ts +1 -1
  20. package/dist/conformance/cases/apps.js +1 -1
  21. package/dist/conformance/cases/isolation.d.ts +18 -3
  22. package/dist/conformance/cases/isolation.js +73 -6
  23. package/dist/conformance/cases/lifetime.js +30 -0
  24. package/dist/conformance/cases/mount.js +4 -2
  25. package/dist/conformance/cases/provider.js +88 -1
  26. package/dist/conformance/cli.js +29 -9
  27. package/dist/conformance/e2b.js +9 -4
  28. package/dist/conformance/exec-stream.d.ts +44 -7
  29. package/dist/conformance/exec-stream.js +347 -88
  30. package/dist/conformance/kernel.js +2 -2
  31. package/dist/conformance/modal.js +1 -1
  32. package/dist/conformance/orgo.js +2 -2
  33. package/dist/conformance/report.js +3 -0
  34. package/dist/conformance/runner.js +127 -9
  35. package/dist/conformance/types.d.ts +21 -0
  36. package/dist/daytona.d.ts +0 -5
  37. package/dist/daytona.js +19 -28
  38. package/dist/descriptor.d.ts +5 -3
  39. package/dist/descriptors/agent37.d.ts +3 -11
  40. package/dist/descriptors/agent37.js +9 -10
  41. package/dist/descriptors/daytona.d.ts +1 -1
  42. package/dist/descriptors/daytona.js +5 -2
  43. package/dist/descriptors/docker.d.ts +13 -1
  44. package/dist/descriptors/docker.js +3 -1
  45. package/dist/descriptors/e2b.d.ts +2 -9
  46. package/dist/descriptors/e2b.js +8 -8
  47. package/dist/descriptors/index.d.ts +21 -19
  48. package/dist/descriptors/index.js +1 -3
  49. package/dist/descriptors/modal.d.ts +2 -6
  50. package/dist/descriptors/modal.js +8 -6
  51. package/dist/descriptors/orgo.js +2 -1
  52. package/dist/docker/egress-main.js +23 -15
  53. package/dist/docker/egress.d.ts +6 -4
  54. package/dist/docker/egress.js +24 -16
  55. package/dist/docker/inspect.d.ts +2 -2
  56. package/dist/docker/inspect.js +5 -5
  57. package/dist/docker.d.ts +6 -5
  58. package/dist/docker.js +12 -11
  59. package/dist/e2b.d.ts +12 -2
  60. package/dist/e2b.js +42 -19
  61. package/dist/host.d.ts +113 -59
  62. package/dist/host.js +5 -0
  63. package/dist/hosted/framed-exec.d.ts +49 -0
  64. package/dist/hosted/framed-exec.js +185 -0
  65. package/dist/hosted/network.d.ts +23 -0
  66. package/dist/hosted/network.js +77 -0
  67. package/dist/hosted/process.d.ts +13 -5
  68. package/dist/hosted/process.js +35 -12
  69. package/dist/hosted/provider.d.ts +16 -9
  70. package/dist/hosted/provider.js +475 -170
  71. package/dist/hosted/rest.d.ts +20 -2
  72. package/dist/hosted/rest.js +24 -10
  73. package/dist/hosted/scripts.d.ts +27 -7
  74. package/dist/hosted/scripts.js +77 -18
  75. package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
  76. package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
  77. package/dist/hosted/values.d.ts +21 -0
  78. package/dist/hosted/values.js +55 -0
  79. package/dist/index.d.ts +1 -1
  80. package/dist/index.js +1 -1
  81. package/dist/isolation.d.ts +0 -2
  82. package/dist/isolation.js +3 -4
  83. package/dist/modal.d.ts +8 -2
  84. package/dist/modal.js +21 -15
  85. package/dist/mount-archil.d.ts +5 -4
  86. package/dist/mount-archil.js +5 -6
  87. package/dist/orgo.js +6 -4
  88. package/dist/providers.d.ts +4 -1
  89. package/dist/surface/api.d.ts +0 -9
  90. package/dist/surface/core.d.ts +7 -2
  91. package/dist/surface/core.js +12 -4
  92. package/dist/surface/index.d.ts +1 -1
  93. package/dist/surface/index.js +1 -1
  94. package/dist/surface/script.d.ts +4 -0
  95. package/dist/surface/script.js +9 -3
  96. package/package.json +1 -1
  97. package/box/build-agent37.mjs +0 -158
@@ -39,7 +39,7 @@ export function settingsFromEnv(env = process.env) {
39
39
  export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
40
40
  function live(env) {
41
41
  if (env[MODAL_ENV.live] !== "1") {
42
- throw new Error(`the Modal conformance module makes real sandboxes: set ${MODAL_ENV.live}=1, with a key the lead has OKed, to run it`);
42
+ throw new Error(`the Modal conformance module makes real sandboxes: set ${MODAL_ENV.live}=1, with a key for an account you can bill, to run it`);
43
43
  }
44
44
  }
45
45
  /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
@@ -1,5 +1,5 @@
1
1
  // Orgo for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider orgo [--image <template>]`.
2
- // It makes real Orgo desktops, so it runs only with AGENTRUN_COMPUTER_LIVE_ORGO=1 and a key the lead has OKed, under
2
+ // It makes real Orgo desktops, so it runs only with AGENTRUN_COMPUTER_LIVE_ORGO=1 and a key for an account you can bill, under
3
3
  // COMPUTER_ORGO_API_KEY (never ORGO_API_KEY), in the workspace COMPUTER_ORGO_WORKSPACE names, or the key's account's one
4
4
  // workspace when it names none. The live switch is checked first, before any other setting is read.
5
5
  //
@@ -36,7 +36,7 @@ export const conformanceNotes = [
36
36
  ];
37
37
  function live(env) {
38
38
  if (env[ORGO_ENV.live] !== "1") {
39
- throw new Error(`the Orgo conformance module makes real computers: set ${ORGO_ENV.live}=1, with a key the lead has OKed, to run it`);
39
+ throw new Error(`the Orgo conformance module makes real computers: set ${ORGO_ENV.live}=1, with a key for an account you can bill, to run it`);
40
40
  }
41
41
  }
42
42
  /** The desktop COMPUTER_ORGO_OS names, linux when it names none; a throw in words for any other. */
@@ -67,6 +67,9 @@ export function formatReport(report) {
67
67
  // What a provider said through onNote, such as a release whose final sync or checkin did not go cleanly.
68
68
  for (const { computer, note } of report.providerNotes ?? [])
69
69
  lines.push(`provider note ${computer}: ${note}`);
70
+ // What a vendor plan or rate limit that keeps fewer would refuse: --concurrency caps it.
71
+ const { peak, cap } = report.computers;
72
+ lines.push(`computers alive at once: ${peak} at most${cap === undefined ? "" : ` (--concurrency ${cap})`}`);
70
73
  const core = results.filter((r) => levelOf(r) === "core");
71
74
  const notDeclared = results.filter((r) => levelOf(r) === "optional").length;
72
75
  const full = results.filter((r) => r.level === "full");
@@ -85,9 +85,12 @@ function whenAborted(signal) {
85
85
  */
86
86
  export async function runConformance(provider, options) {
87
87
  // Given no cases, the run takes its computer's suite: a browser's own cases, as the CLI does, else the suite's.
88
- const { image, only, kind, signal, cases = casesFor(provider.capabilities().kind), drifted, planted, mountFor, onResult, notes, caseTimeoutMs = 180_000, patience = 30_000, cleanupTimeoutMs = 60_000, fixture, gpu } = options;
88
+ const { image, only, kind, signal, cases = casesFor(provider.capabilities().kind), drifted, planted, mountFor, onResult, notes, caseTimeoutMs = 180_000, patience = 30_000, cleanupTimeoutMs = 60_000, fixture, gpu, long = false, concurrency } = options;
89
89
  if (kind !== undefined && only !== undefined)
90
90
  throw new TypeError("a run takes kind and only apart: a kind runs its own cases");
91
+ if (concurrency !== undefined && !(Number.isSafeInteger(concurrency) && concurrency >= 1))
92
+ throw new TypeError(`concurrency is a whole number of computers, 1 or more; got ${concurrency}`);
93
+ const cap = concurrency ?? Infinity;
91
94
  // What the provider declares of itself: as given, else the kind registry's entry for its id (health.declared), its
92
95
  // parked configurations with its offered ones: a parked one built for the suite is held to its own declaration.
93
96
  const entry = PROVIDERS.find((one) => one.id === provider.id);
@@ -97,7 +100,6 @@ export async function runConformance(provider, options) {
97
100
  throw new TypeError(kindProblem);
98
101
  const fetcher = options.fetch ?? ((url, init) => fetch(url, init));
99
102
  const dialer = options.cdp ?? dialCdp;
100
- const clock = options.clock ?? { now: () => Date.now(), sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) };
101
103
  const run = randomBytes(6).toString("hex");
102
104
  const runLabels = { [RUN_LABEL]: run };
103
105
  const capabilities = provider.capabilities();
@@ -119,6 +121,7 @@ export async function runConformance(provider, options) {
119
121
  core: "fail",
120
122
  undeclared: [],
121
123
  cleanup: { deleted: [], left: [], errors: [], late: [] },
124
+ computers: { peak: 0, ...(concurrency === undefined ? {} : { cap: concurrency }) },
122
125
  ...(notes !== undefined && notes.length > 0 ? { notes: [...notes] } : {}),
123
126
  };
124
127
  const deleted = new Set();
@@ -143,17 +146,111 @@ export async function runConformance(provider, options) {
143
146
  ...extra,
144
147
  labels: { ...extra.labels, ...runLabels },
145
148
  });
149
+ /**
150
+ * The computers alive now, by the request that makes each (its retries share it), with its role: held from the
151
+ * request's first create until its computer is deleted, or until its creates settle with none made. One whose delete
152
+ * failed is `lost`: it may still be there, so it is never freed. A create past the cap waits for one to go.
153
+ */
154
+ const alive = new Map();
155
+ /** Each computer the run made, by name: the request that made it. */
156
+ const madeBy = new Map();
157
+ /** The providers built with planted secrets: their creates are not capped (attempt). */
158
+ const plantedBy = new WeakSet();
159
+ /** The creates of each request still unanswered. */
160
+ const flying = new Map();
161
+ const waiting = [];
162
+ const free = (request) => {
163
+ if (alive.delete(request))
164
+ for (const wake of waiting.splice(0))
165
+ wake();
166
+ };
167
+ /** Deletes the computer, its errors in the report; true once it is deleted. */
146
168
  const release = async (ref, by = provider) => {
169
+ let gone = false;
147
170
  try {
148
171
  const released = await within(by.release(ref, "delete"), cleanupTimeoutMs, `release ${ref.name}`);
149
172
  if (released.ok)
150
173
  deleted.add(ref.name);
151
174
  else
152
175
  report.cleanup.errors.push(`release ${ref.name}: ${released.error.code}: ${released.error.message}`);
176
+ gone = released.ok;
153
177
  }
154
178
  catch (error) {
155
179
  report.cleanup.errors.push(words(error).startsWith(`release ${ref.name}`) ? words(error) : `release ${ref.name} threw: ${words(error)}`);
156
180
  }
181
+ const request = madeBy.get(ref.name);
182
+ if (request !== undefined) {
183
+ madeBy.delete(ref.name);
184
+ if (gone)
185
+ free(request);
186
+ else if (alive.has(request))
187
+ alive.get(request).lost = true;
188
+ }
189
+ return gone;
190
+ };
191
+ /** Whether the case running now uses the run's computer: while it does, the run's computer is not deleted for room. */
192
+ let usingShared = false;
193
+ /**
194
+ * Room for `request`'s computer, of `role`, under the cap; a retry of a request that holds room already has it. While
195
+ * there is none, the run's computer makes way when the case running doesn't use it (and nothing more is made when it
196
+ * can't be deleted); a case whose own computers, the run's computer it uses and those that could not be deleted fill
197
+ * the cap fails in words; else the create waits for a computer to be deleted, or for `signal`.
198
+ */
199
+ const hold = async (request, role, signal) => {
200
+ while (!alive.has(request) && alive.size >= cap) {
201
+ if (sharedRef !== undefined && !usingShared) {
202
+ const ref = sharedRef;
203
+ [shared, sharedRef] = [undefined, undefined];
204
+ if (!(await release(ref)))
205
+ throw new Error(`the run's computer ${ref.name} could not be deleted to make room, so --concurrency ${cap} lets no other be made`);
206
+ continue;
207
+ }
208
+ const held = [...alive.values()];
209
+ if (held.every((one) => one.lost || one.role === role || (one.role === "shared" && usingShared))) {
210
+ const lost = held.filter((one) => one.lost).length;
211
+ throw new Error(lost > 0
212
+ ? `--concurrency ${cap} is full: ${lost} of the run's computers could not be deleted, so no other is made`
213
+ : `this case needs more than ${cap} ${cap === 1 ? "computer" : "computers"} alive at once, and --concurrency ${cap} caps them`);
214
+ }
215
+ signal?.throwIfAborted();
216
+ await new Promise((resolve) => {
217
+ const wake = () => {
218
+ signal?.removeEventListener("abort", wake);
219
+ resolve();
220
+ };
221
+ waiting.push(wake);
222
+ signal?.addEventListener("abort", wake, { once: true });
223
+ });
224
+ signal?.throwIfAborted();
225
+ }
226
+ if (alive.has(request))
227
+ return;
228
+ alive.set(request, { role });
229
+ report.computers.peak = Math.max(report.computers.peak, alive.size);
230
+ };
231
+ /**
232
+ * A create of `request`, under the cap (hold): the room it holds is the computer's it made until that computer's
233
+ * delete, or is freed once every create of the request has answered with none made.
234
+ */
235
+ const capped = async (request, role, signal, create) => {
236
+ flying.set(request, (flying.get(request) ?? 0) + 1);
237
+ try {
238
+ await hold(request, role, signal);
239
+ const created = await create();
240
+ if (created.ok && !madeBy.has(created.value.name))
241
+ madeBy.set(created.value.name, request);
242
+ return created;
243
+ }
244
+ finally {
245
+ const left = flying.get(request) - 1;
246
+ if (left > 0)
247
+ flying.set(request, left);
248
+ else {
249
+ flying.delete(request);
250
+ if (![...madeBy.values()].includes(request))
251
+ free(request);
252
+ }
253
+ }
157
254
  };
158
255
  /** Each computer the run made, by name: its role, "shared" or the id of the case that made it. */
159
256
  const roles = new Map();
@@ -185,14 +282,21 @@ export async function runConformance(provider, options) {
185
282
  return;
186
283
  report.daemons.push({ computer, role: roles.get(computer) ?? role, version: hello.version, os: hello.os, arch: hello.arch, ...(hello.fence === undefined ? {} : { fence: hello.fence }) });
187
284
  };
188
- /** The run's shared computer, made the first time a case needs it or the daemon's hello. */
285
+ /**
286
+ * The run's shared computer, made the first time a case needs it or the daemon's hello, and again after it made way
287
+ * for a case's own under the cap (hold); `hello` is its first one's.
288
+ */
189
289
  let shared;
190
290
  let sharedRef;
291
+ let hello;
292
+ let made = 0;
191
293
  const getShared = () => (shared ??= (async () => {
192
294
  // The run's signal ends the wait at once (Ctrl-C during setup) and reaches the create; a computer that arrives
193
295
  // after it is deleted as it lands (lateCreate).
194
296
  const stop = new AbortController();
195
- const creating = provider.create(spec(), { signal: signal ? AbortSignal.any([signal, stop.signal]) : stop.signal, requestId: `${run}/shared` });
297
+ const both = signal ? AbortSignal.any([signal, stop.signal]) : stop.signal;
298
+ const requestId = `${run}/shared${++made > 1 ? `/${made}` : ""}`;
299
+ const creating = capped(requestId, "shared", both, () => provider.create(spec(), { signal: both, requestId }));
196
300
  let created;
197
301
  try {
198
302
  created = await within(creating, caseTimeoutMs, "create", signal);
@@ -219,6 +323,7 @@ export async function runConformance(provider, options) {
219
323
  return { error: `connect: ${connected.error.code}: ${connected.error.message}` };
220
324
  await bounded(connected.value.close(), CLOSE_MS);
221
325
  sawHello(created.value.name, connected.value.hello, "shared");
326
+ hello ??= connected.value.hello;
222
327
  return { ref: created.value, hello: connected.value.hello };
223
328
  })().catch((error) => ({ error: `the provider threw: ${words(error)}` })));
224
329
  /** Why a case cannot run here, or undefined when everything it needs is declared. */
@@ -232,7 +337,8 @@ export async function runConformance(provider, options) {
232
337
  else if (GROUP_NAMES.has(need)) {
233
338
  if (!groups.includes(need))
234
339
  return `the provider does not declare ${need}`;
235
- const got = await getShared();
340
+ // The run's first computer's hello: one that made way under the cap is not made again to be read.
341
+ const got = hello === undefined ? await getShared() : { hello };
236
342
  if ("hello" in got && !(Array.isArray(got.hello.groups) && got.hello.groups.includes(need))) {
237
343
  return `the ${capabilities.daemon === "none" ? "computer's" : "daemon's"} hello does not declare ${need}`;
238
344
  }
@@ -282,6 +388,7 @@ export async function runConformance(provider, options) {
282
388
  });
283
389
  if (signal?.aborted)
284
390
  return result("fail", "not run: the run was aborted");
391
+ usingShared = (c.computer ?? "shared") === "shared";
285
392
  const why = await missing(c.needs);
286
393
  if (why !== undefined) {
287
394
  const lacking = [];
@@ -348,9 +455,13 @@ export async function runConformance(provider, options) {
348
455
  };
349
456
  /** Each create of the case is its own request: the run, the case and the create's count. */
350
457
  let creates = 0;
351
- /** create through by, kept: what it gives is deleted when the case ends, or as it comes after that. */
458
+ /**
459
+ * create through by, kept: what it gives is deleted when the case ends, or as it comes after that. A create with
460
+ * planted secrets is outside the cap: it can't use the account, so it holds no room (one it makes anyway fails its case).
461
+ */
352
462
  const attempt = (whole, by = provider, requestId = `${run}/${c.id}/${++creates}`) => {
353
- const creating = by.create(whole, { signal: caseSignal, requestId }).then((created) => {
463
+ const make = () => by.create(whole, { signal: caseSignal, requestId });
464
+ const creating = (plantedBy.has(by) ? make() : capped(requestId, c.id, caseSignal, make)).then((created) => {
354
465
  noteCreated(created, c.id);
355
466
  // A retry of one request answers the computer the first attempt made: it is tracked once.
356
467
  if (created.ok && !refs.some((one) => one.ref.id === created.value.id))
@@ -443,7 +554,8 @@ export async function runConformance(provider, options) {
443
554
  sockets.push(socket);
444
555
  return socket;
445
556
  },
446
- clock,
557
+ // The wall clock's wait ends with the case (its timeout, or the run's abort), so no timer outlives the run.
558
+ clock: options.clock ?? { now: () => Date.now(), sleep: (ms) => sleep(ms, undefined, { signal: caseSignal }).catch(() => undefined) },
447
559
  async drifted() {
448
560
  if (drifted === undefined)
449
561
  return t.skip("no drifted provider was given: a provider module exports createDriftedProvider() for the drift cases");
@@ -453,7 +565,9 @@ export async function runConformance(provider, options) {
453
565
  async planted() {
454
566
  if (planted === undefined)
455
567
  return t.skip("no provider with planted secrets was given: the provider takes no secret, or its module lists none in ENV");
456
- return await planted();
568
+ const got = await planted();
569
+ plantedBy.add(got.provider);
570
+ return got;
457
571
  },
458
572
  async runFolder(kind) {
459
573
  const none = `the run was given no run folder for mount kind ${kind}`;
@@ -474,6 +588,10 @@ export async function runConformance(provider, options) {
474
588
  return t.skip("the run named no GPU: give --gpu <type>[:<count>] (or options.gpu), one the provider declares in capabilities().gpu");
475
589
  return { type: gpu.type, count: gpu.count };
476
590
  },
591
+ long(what) {
592
+ if (!long)
593
+ t.skip(`a long case (${what}): run with --long (or options.long), as the live sweep does`);
594
+ },
477
595
  async exec(argv, extra = {}, client = t.client) {
478
596
  const ran = unwrap(await client.call("exec.run", { argv, timeoutMs: patience, ...extra }, { signal: caseSignal }), `exec.run ${show(argv)}`);
479
597
  const decode = (base64) => Buffer.from(base64, "base64").toString("utf8");
@@ -97,6 +97,8 @@ export interface CaseContext {
97
97
  runFolder(kind: MountKind): Promise<RunFolder>;
98
98
  /** The GPU the run pays for (options.gpu, the CLI's --gpu); skips the case when the run names none. */
99
99
  gpu(): GpuSpec;
100
+ /** Skips the case, saying what makes it long, unless the run takes long cases (options.long, the CLI's --long). */
101
+ long(what: string): void;
100
102
  /**
101
103
  * Starts the run's fixture in the case's computer and waits until it is up: an app that logs each input event it
102
104
  * gets, so a case checks what an action did with no model. It is stopped when the case ends. Skips the case when the
@@ -218,6 +220,14 @@ export interface ConformanceReport {
218
220
  leftAlone: number;
219
221
  };
220
222
  };
223
+ /**
224
+ * The most computers the run had alive at once, each counted from its create's call until it was released or its
225
+ * create made none, and the cap the run was given (concurrency), when it was.
226
+ */
227
+ computers: {
228
+ peak: number;
229
+ cap?: number;
230
+ };
221
231
  /** What the provider module says of its configuration, for whoever reads the report; absent when it says nothing. */
222
232
  notes?: string[];
223
233
  /**
@@ -301,6 +311,12 @@ export interface ConformanceOptions {
301
311
  patience?: number;
302
312
  /** The longest each cleanup call (release, the sweep, list) may take; default 60 s. */
303
313
  cleanupTimeoutMs?: number;
314
+ /**
315
+ * The most computers alive at once, for a vendor plan or rate limit that keeps fewer: a create waits for one to be
316
+ * released, the run's computer is deleted while a case that doesn't use it needs room (and made again for the next
317
+ * case that does), and a case that needs more at once than this fails in words. Default no cap.
318
+ */
319
+ concurrency?: number;
304
320
  /**
305
321
  * The fixture on this machine, for the cases that check what input did: computerd-fixture for a desktop, the
306
322
  * fixture APK for an Android phone. Without it those cases skip, and Core cannot pass where kind requires them.
@@ -311,6 +327,11 @@ export interface ConformanceOptions {
311
327
  * the one it pays for; without it the case skips in words.
312
328
  */
313
329
  gpu?: GpuSpec;
330
+ /**
331
+ * Run the long cases, which wait minutes on a vendor's timer (lifetime.idle leaves a computer quiet 6 min): the CLI's
332
+ * --long, which the live sweep gives. Without it they skip in words.
333
+ */
334
+ long?: boolean;
314
335
  /** fetch for screen.stream; default the global one. */
315
336
  fetch?: CaseContext["fetch"];
316
337
  /** How the browser cases open a CDP socket; default a WebSocket (dialCdp). Tests give a fake browser's. */
package/dist/daytona.d.ts CHANGED
@@ -62,11 +62,6 @@ export interface DaytonaProviderOptions extends Omit<HostedOptions, "kind" | "de
62
62
  export declare function create(options: DaytonaProviderOptions): DaytonaProvider;
63
63
  /** The conformance CLI's module for Daytona: the run's idle stop and auto-delete, its snapshot, notes and drifted twin. */
64
64
  export declare const conformance: () => Promise<typeof import("./conformance/daytona.js")>;
65
- /**
66
- * Daytona's own path sockets outside /run: its D-Bus session bus, /tmp/dbus-<10 characters> (the live baseline's
67
- * isolation.vendor-agent connected to /tmp/dbus-Y8OW6E3FDx as the tool user). Create closes them to the tool user.
68
- */
69
- export declare const DAYTONA_SOCKETS: readonly string[];
70
65
  /**
71
66
  * Computers that are Daytona sandboxes, on the shared adapter. A spec's image is a Daytona snapshot (its id or name),
72
67
  * which gives the class and the size; "default" is Daytona's default snapshot. See the README's Daytona section for
package/dist/daytona.js CHANGED
@@ -5,14 +5,14 @@
5
5
  // Every Daytona fact used here is cited in the README's Daytona section.
6
6
  import { randomBytes } from "node:crypto";
7
7
  import { PassThrough } from "node:stream";
8
- import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, DAYTONA_NO_ARCHIL, daytonaGpu, daytonaGpuSnapshot } from "./descriptors/daytona.js";
8
+ import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_NO_ARCHIL, daytonaGpuSnapshot } from "./descriptors/daytona.js";
9
9
  import { COMPUTER_LABEL } from "./drift.js";
10
10
  import { HostError } from "./host.js";
11
11
  import { HostedProvider, timeoutsOf } from "./hosted/provider.js";
12
12
  import { boundOf, orThrow, pause as sleep } from "./hosted/process.js";
13
13
  import { allPages, jsonOf, rest } from "./hosted/rest.js";
14
14
  import { shellLine } from "./hosted/scripts.js";
15
- import { dateOf, isWhole } from "./hosted/values.js";
15
+ import { dateOf, isWhole, sizeRefusals } from "./hosted/values.js";
16
16
  import { MAX_LINE_BYTES } from "./protocol.js";
17
17
  import { checkGpu } from "./provider.js";
18
18
  import { ok, vendorFail } from "./result.js";
@@ -38,11 +38,6 @@ const MAX_PAGES = 1000;
38
38
  const MAX_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
39
39
  /** The toolbox's port, on every interface of the sandbox (daytonaio/daytona@b5a5d9e7 apps/daemon/pkg/toolbox/config/config.go:6). */
40
40
  const TOOLBOX_PORT = 2280;
41
- /**
42
- * Daytona's own path sockets outside /run: its D-Bus session bus, /tmp/dbus-<10 characters> (the live baseline's
43
- * isolation.vendor-agent connected to /tmp/dbus-Y8OW6E3FDx as the tool user). Create closes them to the tool user.
44
- */
45
- export const DAYTONA_SOCKETS = ["/tmp/dbus-*"];
46
41
  const QUOTA = /quota|capacity|limit exceeded|too many/i;
47
42
  const STARTING = new Set(["creating", "restoring", "starting", "pending_build", "building_snapshot", "pulling_snapshot", "resizing", "snapshotting", "forking", "resuming", "unknown"]);
48
43
  const GONE = new Set(["destroyed", "destroying"]);
@@ -121,8 +116,8 @@ class DaytonaHost {
121
116
  // daemon child: Daytona's toolbox daemon is the sandbox's first process, and init a command started through it.
122
117
  // maxLifetimeMs is the 30 days check() has always given; Daytona's TTL is in whole minutes and documents no cap of
123
118
  // its own. The toolbox listens on 2280 on every interface and runs commands for whoever reaches it, so init starts
124
- // with --own-network, and network none is all a computer takes. Its D-Bus session bus in /tmp, which no network
125
- // namespace cuts, is closed to the tool user before init starts (vendorSockets).
119
+ // with --own-network, and network none is all a computer takes. Its D-Bus session bus in /tmp (/tmp/dbus-*), which
120
+ // no network namespace cuts, is closed to the tool user before init starts, as on every child host.
126
121
  this.facts = {
127
122
  daemon: "child",
128
123
  isolation: options.sandboxClass === "linux-vm" ? "vm" : "container",
@@ -130,26 +125,22 @@ class DaytonaHost {
130
125
  maxLifetimeMs: MAX_LIFETIME_MS,
131
126
  arch: options.arch,
132
127
  vendorAgentPorts: [TOOLBOX_PORT],
133
- vendorSockets: [...DAYTONA_SOCKETS],
134
- // get reads sb.gpu and sb.gpuType back: a sandbox with none reads none.
135
- gpuReadBack: true,
136
- // A GPU sandbox's limits are stated in gpu: its stop deletes it, it runs in region earth, its size is per GPU.
137
- gpu: daytonaGpu(options.gpu.snapshot === DAYTONA_GPU_SNAPSHOT ? undefined : options.gpu.snapshot),
138
128
  };
139
129
  }
140
130
  /**
141
- * A snapshot name has no control characters; a GPU computer is made from the provider's GPU snapshot, which a spec
142
- * names, or Daytona's default, never another. No call.
131
+ * A snapshot name has no control characters, and its size is the snapshot's; a GPU computer is made from the
132
+ * provider's GPU snapshot, which a spec names, or Daytona's default, never another. No call.
143
133
  */
144
134
  check(given) {
145
135
  const { image } = given;
146
- const refusals = [];
136
+ const refusals = sizeRefusals(given, "a Daytona computer", "snapshot");
147
137
  if (typeof image === "string" && image !== "" && image.trim() === "")
148
138
  refusals.push({ field: "image", message: `an image is the id or name of a Daytona snapshot, or "${DAYTONA_DEFAULT_SNAPSHOT}" for Daytona's default snapshot` });
149
139
  else if (typeof image === "string" && /[\x01-\x1f]/.test(image))
150
140
  refusals.push({ field: "image", message: "a snapshot name has no control characters" });
151
141
  const gpuSnapshot = this.#gpu.snapshot;
152
- if (given.gpu !== undefined && checkGpu(given.gpu, this.facts, given.mount).length === 0 && typeof image === "string" && image !== DAYTONA_DEFAULT_SNAPSHOT && image !== gpuSnapshot) {
142
+ const offered = { gpu: { ...DAYTONA_GPU, types: [this.#gpu.type], max: this.#gpu.count } };
143
+ if (given.gpu !== undefined && checkGpu(given.gpu, offered, given.mount).length === 0 && typeof image === "string" && image !== DAYTONA_DEFAULT_SNAPSHOT && image !== gpuSnapshot) {
153
144
  refusals.push({
154
145
  field: "image",
155
146
  message: `a Daytona GPU computer here is made from the GPU snapshot ${gpuSnapshot} alone, not ${JSON.stringify(image)}: give "${gpuSnapshot}" or "${DAYTONA_DEFAULT_SNAPSHOT}"; no other snapshot is proven to give a GPU computer`,
@@ -157,7 +148,7 @@ class DaytonaHost {
157
148
  }
158
149
  return refusals;
159
150
  }
160
- /** A sandbox as the adapter reads a machine: its state, labels, start, end, GPUs, and Daytona's words for a failure. */
151
+ /** A sandbox as the adapter reads a machine: its state, labels, start, end, and Daytona's words for a failure. */
161
152
  #machineOf(sb) {
162
153
  const endsAt = dateOf(sb.autoDestroyAt);
163
154
  const made = dateOf(sb.createdAt);
@@ -167,7 +158,6 @@ class DaytonaHost {
167
158
  state: stateOf(sb),
168
159
  ...(made ? { createdAt: made } : {}),
169
160
  ...(endsAt ? { endsAt } : {}),
170
- ...(isWhole(sb.gpu) && sb.gpu > 0 ? { gpu: { type: String(sb.gpuType), count: sb.gpu } } : {}),
171
161
  // A failed sandbox always carries a why, Daytona's or ours, so create stops on it as vendor, never as gone.
172
162
  ...(typeof sb.errorReason === "string" && sb.errorReason !== "" ? { why: sb.errorReason } : FAILED.has(sb.state ?? "") ? { why: `Daytona reads the sandbox ${sb.state}, with no reason given` } : {}),
173
163
  };
@@ -176,7 +166,9 @@ class DaytonaHost {
176
166
  * POST /sandbox: its native name and labels, the lifetime as a TTL in whole minutes, the idle stop and auto-delete,
177
167
  * no public port, and network none (block-all), the one network check() takes. A GPU
178
168
  * computer is made from the GPU snapshot in region earth, ephemeral (its stop deletes it). Never cancelled: the adapter
179
- * races it, and deletes by name one whose answer never comes. A name Daytona already holds (409) made nothing: exists.
169
+ * races it, and deletes by name one whose answer never comes. A name Daytona already holds (409) made nothing: exists,
170
+ * and the adapter adopts the sandbox the name lists, as a retry does. req.backstopAt is left: the TTL is Daytona's own
171
+ * timer at the deadline (lifetime "vendor"), and autoDeleteInterval counts from a stop, not from create.
180
172
  */
181
173
  async create(req, ctx) {
182
174
  const gpu = req.gpu !== undefined;
@@ -189,19 +181,17 @@ class DaytonaHost {
189
181
  public: false,
190
182
  // A GPU sandbox runs in region earth alone, whatever the provider's target.
191
183
  ...(gpu ? { target: DAYTONA_GPU_REGION } : this.#target === undefined ? {} : { target: this.#target }),
192
- ttlMinutes: Math.max(1, Math.ceil((req.lifetimeMs ?? 0) / 60_000)),
184
+ ttlMinutes: Math.max(1, Math.ceil(req.lifetimeMs / 60_000)),
193
185
  autoStopInterval: this.#autoStop,
194
186
  // A GPU sandbox's stop deletes it (no pause, no snapshot): autoDeleteInterval 0 is Daytona's ephemeral (its SDK's
195
187
  // ephemeral sets it; CreateSandbox has no ephemeral field).
196
188
  autoDeleteInterval: gpu ? 0 : this.#autoDelete,
197
- networkBlockAll: req.network === "none",
189
+ networkBlockAll: !req.egress,
198
190
  // No resource field (cpu, gpu, gpuType, memory, disk): a snapshot carries its own, and Daytona refuses a create that
199
191
  // names a snapshot and sends any (400 "Cannot specify Sandbox resources when using a snapshot"). A GPU computer's
200
- // GPU is the snapshot's, held in the read-back.
192
+ // GPU is the snapshot's, held by the adapter's GPU label.
201
193
  };
202
- const posted = await this.#rest.json("POST", sandboxUrl(this.#rest), { json: body, timeoutMs: ctx.timeoutMs });
203
- if (!posted.ok && /: 409 /.test(posted.error.message))
204
- throw new HostError("exists", `Daytona already has a sandbox named ${req.name}: ${posted.error.message}`);
194
+ const posted = await this.#rest.json("POST", sandboxUrl(this.#rest), { json: body, timeoutMs: ctx.timeoutMs, named: true });
205
195
  const id = orThrow(posted)?.id;
206
196
  if (typeof id !== "string" || id === "")
207
197
  throw new Error("POST /sandbox: no sandbox id in the answer");
@@ -414,7 +404,8 @@ class DaytonaHost {
414
404
  bound.clear();
415
405
  }
416
406
  // Input: whole lines, one call after another; the rest of a line waits for its end (or end()).
417
- const utf8 = new TextDecoder();
407
+ // ignoreBOM: a U+FEFF that starts stdin is text, never a mark to drop.
408
+ const utf8 = new TextDecoder("utf-8", { ignoreBOM: true });
418
409
  let queued = "";
419
410
  let sending = Promise.resolve();
420
411
  const send = (data) => {
@@ -66,9 +66,11 @@ export interface ProviderDescriptor<Module extends ProviderModule = ProviderModu
66
66
  */
67
67
  readonly unmounted?: Unmounted;
68
68
  /**
69
- * The network forms its computers make, as its providers' capabilities().network declare them: ["none"], a remote
70
- * computer whose programs run in a network of their own; ["open"], the vendor's own network, which no allowlist of
71
- * this server reaches; Docker's makes all three. A provider of several configurations declares every form they make.
69
+ * The network forms its computers make and enforce, as its providers' capabilities().network declare them: ["none"],
70
+ * a remote computer whose programs run in a network of their own and nothing else; ["open"], the vendor's own network,
71
+ * which no allowlist of this server reaches; a hosted computer through init's egress proxy (hosted/network.ts) makes
72
+ * all three, as Docker's does. A form not declared is refused at check, never widened or narrowed to another. A
73
+ * provider of several configurations declares every form they make.
72
74
  */
73
75
  readonly network: readonly NetworkForm[];
74
76
  /**
@@ -1,10 +1,5 @@
1
- /** Agent37's plain Linux template: a sandbox when its setting names no image. */
1
+ /** Agent37's plain Linux template, a spec's image for a caller of the provider that names its own. */
2
2
  export declare const AGENT37_BASE_TEMPLATE = "agent37-base";
3
- /**
4
- * Our box image (box/Dockerfile, its desktop included) as a template of the key's own workspace, which box/build-agent37.mjs builds
5
- * and publishes under this one name: a desktop when its setting names no image.
6
- */
7
- export declare const AGENT37_BOX_TEMPLATE = "agentrun-box";
8
3
  export declare const AGENT37: {
9
4
  readonly id: "agent37";
10
5
  readonly label: "Agent37";
@@ -19,7 +14,7 @@ export declare const AGENT37: {
19
14
  }];
20
15
  readonly metered: true;
21
16
  readonly mounts: readonly ["archil"];
22
- readonly network: readonly ["none"];
17
+ readonly network: readonly ["none", "open", "allow"];
23
18
  readonly capabilities: readonly [import("../kinds.js").KindCapabilities, {
24
19
  readonly options: {
25
20
  readonly kind: "desktop";
@@ -33,9 +28,6 @@ export declare const AGENT37: {
33
28
  };
34
29
  readonly image?: string;
35
30
  }];
36
- readonly defaultImage: {
37
- readonly sandbox: "agent37-base";
38
- readonly desktop: "agentrun-box";
39
- };
31
+ readonly prepareImage: true;
40
32
  readonly load: () => Promise<typeof import("../agent37.js")>;
41
33
  };
@@ -1,14 +1,10 @@
1
1
  // Agent37's descriptor: a Linux sandbox or a Linux desktop on an Agent37 instance (a VM by default), the run's folder on
2
- // an Archil disk. The desktop starts from our box image built as a workspace template (box/build-agent37.mjs).
2
+ // an Archil disk. Both start from our box image, which its prepareImage() registers in the key's own workspace from the
3
+ // public image the release publishes (box-image.ts).
3
4
  import { defineProvider } from "../descriptor.js";
4
5
  import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
5
- /** Agent37's plain Linux template: a sandbox when its setting names no image. */
6
+ /** Agent37's plain Linux template, a spec's image for a caller of the provider that names its own. */
6
7
  export const AGENT37_BASE_TEMPLATE = "agent37-base";
7
- /**
8
- * Our box image (box/Dockerfile, its desktop included) as a template of the key's own workspace, which box/build-agent37.mjs builds
9
- * and publishes under this one name: a desktop when its setting names no image.
10
- */
11
- export const AGENT37_BOX_TEMPLATE = "agentrun-box";
12
8
  export const AGENT37 = defineProvider({
13
9
  id: "agent37",
14
10
  label: "Agent37",
@@ -19,10 +15,13 @@ export const AGENT37 = defineProvider({
19
15
  ],
20
16
  metered: true,
21
17
  mounts: ["archil"],
22
- // None: its programs run in a network of their own (isolation.ts OWN_NETWORK_ONLY).
23
- network: ["none"],
18
+ // None: its programs run in a network of their own, their loopback alone (isolation.ts), and the instance is made
19
+ // deny-all. Open and a list: the instance is made allow-all, and its programs' one way out is init's egress proxy,
20
+ // which reaches the public internet alone, and with a list its hosts alone (hosted/network.ts).
21
+ network: ["none", "open", "allow"],
24
22
  // Each configuration built by its own create() options: kind linux is the provider's default.
25
23
  capabilities: [SANDBOX, { ...LINUX_DESKTOP, options: { kind: "desktop" } }],
26
- defaultImage: { sandbox: AGENT37_BASE_TEMPLATE, desktop: AGENT37_BOX_TEMPLATE },
24
+ // No default image: every computer starts from the box template its prepareImage() registers (agentrun-box-<hash>).
25
+ prepareImage: true,
27
26
  load: () => import("../agent37.js"),
28
27
  });
@@ -64,7 +64,7 @@ export declare const DAYTONA: {
64
64
  readonly unmounted: {
65
65
  readonly archil: "Archil mounts don't work on Daytona yet: Archil's client hangs on its sandboxes";
66
66
  };
67
- readonly network: readonly ["none"];
67
+ readonly network: readonly ["none", "open", "allow"];
68
68
  readonly capabilities: readonly [{
69
69
  readonly gpu: Readonly<GpuCapability>;
70
70
  readonly kind: import("../protocol.js").ComputerKind;
@@ -74,8 +74,11 @@ export const DAYTONA = defineProvider({
74
74
  // no linux-vm class to try instead. An Archil mount is refused in these words, before any request.
75
75
  mounts: [],
76
76
  unmounted: { archil: DAYTONA_NO_ARCHIL },
77
- // None: its programs run in a network of their own (isolation.ts OWN_NETWORK_ONLY).
78
- network: ["none"],
77
+ // None: its programs run in a network of their own, their loopback alone (isolation.ts), and the sandbox is made with
78
+ // networkBlockAll. Open and a list: the sandbox is not blocked (the account's tier may still limit where it goes), and
79
+ // its programs' one way out is init's egress proxy, which reaches the public internet alone, and with a list its hosts
80
+ // alone (hosted/network.ts).
81
+ network: ["none", "open", "allow"],
79
82
  // A linux computer, with GPUs when asked.
80
83
  capabilities: [{ ...SANDBOX, gpu: DAYTONA_GPU }],
81
84
  defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
@@ -5,7 +5,19 @@ export declare const DOCKER: {
5
5
  readonly metered: false;
6
6
  readonly mounts: readonly ["bind"];
7
7
  readonly network: readonly ["none", "open", "allow"];
8
- readonly capabilities: readonly [import("../kinds.js").KindCapabilities, import("../kinds.js").KindCapabilities];
8
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities, {
9
+ readonly options: {
10
+ readonly desktop: {};
11
+ };
12
+ readonly kind: import("../protocol.js").ComputerKind;
13
+ readonly groups: import("../protocol.js").Group[];
14
+ readonly gpu?: import("../provider.js").GpuCapability;
15
+ readonly persistence?: {
16
+ keepsState: true;
17
+ resume: boolean;
18
+ };
19
+ readonly image?: string;
20
+ }];
9
21
  readonly prepareImage: true;
10
22
  readonly local: true;
11
23
  readonly load: () => Promise<typeof import("../docker.js")>;
@@ -9,7 +9,9 @@ export const DOCKER = defineProvider({
9
9
  mounts: ["bind"],
10
10
  // None, open, or an allowlist through the server's egress proxy.
11
11
  network: ["none", "open", "allow"],
12
- capabilities: [SANDBOX, LINUX_DESKTOP],
12
+ // Each configuration built by its own create() options: the desktop's start the X server (desktop: {}); without them
13
+ // the provider makes a linux computer, with no screen and no apps.
14
+ capabilities: [SANDBOX, { ...LINUX_DESKTOP, options: { desktop: {} } }],
13
15
  // No default image: the server makes one from the provider's recipe (prepareImage) before the first create.
14
16
  prepareImage: true,
15
17
  local: true,