sandbox 3.0.0-beta.5 → 3.0.0-beta.7

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.
@@ -7427,7 +7427,7 @@ const scope = {
7427
7427
 
7428
7428
  //#endregion
7429
7429
  //#region package.json
7430
- var version = "3.0.0-beta.5";
7430
+ var version = "3.0.0-beta.7";
7431
7431
 
7432
7432
  //#endregion
7433
7433
  //#region src/error.ts
@@ -11251,16 +11251,23 @@ var import_ms$3 = /* @__PURE__ */ __toESM(require_ms());
11251
11251
  const debug$2 = createDebugger("sandbox:timeout");
11252
11252
  const BUFFER = (0, import_ms$3.default)("10 seconds");
11253
11253
  async function extendSandboxTimeoutPeriodically(sandbox, signal) {
11254
- const nextTick = sandbox.createdAt.getTime() + sandbox.timeout;
11254
+ const session = sandbox.currentSession();
11255
+ const timeout$1 = session.timeout;
11256
+ if (timeout$1 == null) return;
11257
+ const nextTick = session.createdAt.getTime() + timeout$1;
11255
11258
  debug$2(`next tick: ${new Date(nextTick).toISOString()}`);
11256
11259
  while (!signal.aborted) {
11257
- const timeout$1 = sandbox.createdAt.getTime() + sandbox.timeout - Date.now() - BUFFER;
11258
- if (timeout$1 > 2e3) {
11259
- debug$2(`sleeping for ${timeout$1}ms until next timeout extension`);
11260
- await setTimeout$1(timeout$1, null, { signal });
11260
+ const currentTimeout = session.timeout;
11261
+ if (currentTimeout == null) return;
11262
+ const sleepMs = session.createdAt.getTime() + currentTimeout - Date.now() - BUFFER;
11263
+ if (sleepMs > 2e3) {
11264
+ debug$2(`sleeping for ${sleepMs}ms until next timeout extension`);
11265
+ await setTimeout$1(sleepMs, null, { signal });
11261
11266
  }
11262
11267
  await sandbox.extendTimeout((0, import_ms$3.default)("5 minutes"));
11263
- const nextTick$1 = sandbox.createdAt.getTime() + sandbox.timeout;
11268
+ const updatedTimeout = session.timeout;
11269
+ if (updatedTimeout == null) return;
11270
+ const nextTick$1 = session.createdAt.getTime() + updatedTimeout;
11264
11271
  debug$2(`extended sandbox timeout by 5 minutes. next tick: ${new Date(nextTick$1).toISOString()}`);
11265
11272
  }
11266
11273
  }
@@ -11388,11 +11395,16 @@ async function startInteractiveShell(options) {
11388
11395
  await setupSandboxEnvironment(options.sandbox, progress);
11389
11396
  progress.text = "Booting up interactive listener...";
11390
11397
  command$1 = await startServerCommand(options.sandbox, listener, options.execution, options.sudo, options.envVars, options.cwd);
11398
+ debug$1("startServerCommand completed, cmdId=%s, interactivePort=%s", command$1.cmdId, options.sandbox.interactivePort);
11391
11399
  const waitForProcess = _usingCtx3.u(createAbortController("Connection established successfully"));
11392
11400
  listener.connection.then(() => {
11401
+ debug$1("listener.connection resolved");
11393
11402
  waitForProcess.abort();
11394
11403
  });
11395
- connect$1(command$1, listener, waitForProcess.signal).catch(waitForProcess.ignoreInterruptions);
11404
+ connect$1(command$1, listener, waitForProcess.signal).catch((err$1) => {
11405
+ if (waitForProcess.signal.aborted) return;
11406
+ listener.stdoutStream.destroy(err$1 instanceof Error ? err$1 : new Error(String(err$1)));
11407
+ });
11396
11408
  await Promise.all([throwIfCommandPrematurelyExited(command$1, waitForProcess.signal), attach({
11397
11409
  sandbox: options.sandbox,
11398
11410
  progress,
@@ -11495,6 +11507,7 @@ async function connect$1(command$1, listener, signal) {
11495
11507
  const stderrStream = _usingCtx5.u(getStderrStream());
11496
11508
  for await (const chunk of logs) if (chunk.stream === "stdout") listener.stdoutStream.write(chunk.data);
11497
11509
  else stderrStream.write(chunk.data);
11510
+ listener.stdoutStream.end();
11498
11511
  } catch (_) {
11499
11512
  _usingCtx5.e = _;
11500
11513
  } finally {
@@ -11767,6 +11780,12 @@ const args$2 = {
11767
11780
  type: ObjectFromKeyValue,
11768
11781
  description: "Default environment variables for sandbox commands"
11769
11782
  }),
11783
+ tags: import_cjs$14.multioption({
11784
+ long: "tag",
11785
+ short: "t",
11786
+ type: ObjectFromKeyValue,
11787
+ description: "Key-value tags to associate with the sandbox (e.g. --tag env=staging)"
11788
+ }),
11770
11789
  ...networkPolicyArgs,
11771
11790
  scope
11772
11791
  };
@@ -11778,7 +11797,7 @@ const create = import_cjs$14.command({
11778
11797
  description: "Create and connect to a sandbox without a network access",
11779
11798
  command: `sandbox run --network-policy=none --connect`
11780
11799
  }],
11781
- async handler({ name, nonPersistent, ports, scope: scope$1, runtime: runtime$1, timeout: timeout$1, vcpus: vcpus$1, silent, snapshot: snapshot$1, connect: connect$2, envVars, networkPolicy: networkPolicyMode$1, allowedDomains: allowedDomains$1, allowedCIDRs: allowedCIDRs$1, deniedCIDRs: deniedCIDRs$1 }) {
11800
+ async handler({ name, nonPersistent, ports, scope: scope$1, runtime: runtime$1, timeout: timeout$1, vcpus: vcpus$1, silent, snapshot: snapshot$1, connect: connect$2, envVars, tags, networkPolicy: networkPolicyMode$1, allowedDomains: allowedDomains$1, allowedCIDRs: allowedCIDRs$1, deniedCIDRs: deniedCIDRs$1 }) {
11782
11801
  const networkPolicy$1 = buildNetworkPolicy({
11783
11802
  networkPolicy: networkPolicyMode$1,
11784
11803
  allowedDomains: allowedDomains$1,
@@ -11787,6 +11806,7 @@ const create = import_cjs$14.command({
11787
11806
  });
11788
11807
  const persistent = !nonPersistent;
11789
11808
  const resources = vcpus$1 ? { vcpus: vcpus$1 } : void 0;
11809
+ const tagsObj = Object.keys(tags).length > 0 ? tags : void 0;
11790
11810
  const spinner = silent ? void 0 : ora("Creating sandbox...").start();
11791
11811
  const sandbox = snapshot$1 ? await sandboxClient.create({
11792
11812
  name,
@@ -11802,6 +11822,7 @@ const create = import_cjs$14.command({
11802
11822
  resources,
11803
11823
  networkPolicy: networkPolicy$1,
11804
11824
  env: envVars,
11825
+ tags: tagsObj,
11805
11826
  persistent,
11806
11827
  __interactive: true
11807
11828
  }) : await sandboxClient.create({
@@ -11815,6 +11836,7 @@ const create = import_cjs$14.command({
11815
11836
  resources,
11816
11837
  networkPolicy: networkPolicy$1,
11817
11838
  env: envVars,
11839
+ tags: tagsObj,
11818
11840
  persistent,
11819
11841
  __interactive: true
11820
11842
  });
@@ -11945,22 +11967,27 @@ const list = import_cjs$12.command({
11945
11967
  description: "Sort sandboxes by field. Options: createdAt (default), name",
11946
11968
  type: import_cjs$12.optional(import_cjs$12.oneOf(["createdAt", "name"]))
11947
11969
  }),
11970
+ tags: import_cjs$12.multioption({
11971
+ long: "tag",
11972
+ description: "Filter sandboxes by tag. Format: \"key=value\"",
11973
+ type: ObjectFromKeyValue
11974
+ }),
11948
11975
  scope
11949
11976
  },
11950
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, namePrefix, sortBy }) {
11977
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, namePrefix, sortBy, tags }) {
11951
11978
  const sandboxes = await (async () => {
11952
11979
  try {
11953
11980
  var _usingCtx$1 = _usingCtx();
11954
11981
  const _spinner$1 = _usingCtx$1.u(acquireRelease(() => ora("Fetching sandboxes...").start(), (s$1) => s$1.stop()));
11955
- const { json } = await sandboxClient.list({
11982
+ let { sandboxes: sandboxes$1 } = await sandboxClient.list({
11956
11983
  token: token$1,
11957
11984
  teamId: team$1,
11958
11985
  projectId: project$1,
11959
11986
  limit: 100,
11960
11987
  ...namePrefix && { namePrefix },
11961
- ...sortBy && { sortBy }
11988
+ ...sortBy && { sortBy },
11989
+ ...Object.keys(tags).length > 0 && { tags }
11962
11990
  });
11963
- let sandboxes$1 = json.sandboxes;
11964
11991
  if (!all) sandboxes$1 = sandboxes$1.filter((x) => x.status === "running");
11965
11992
  return sandboxes$1;
11966
11993
  } catch (_) {
@@ -11980,11 +12007,12 @@ const list = import_cjs$12.command({
11980
12007
  color: (s$1) => SandboxStatusColor[s$1.status] ?? source_default.reset
11981
12008
  },
11982
12009
  CREATED: { value: (s$1) => timeAgo(s$1.createdAt) },
11983
- MEMORY: { value: (s$1) => memoryFormatter.format(s$1.memory) },
11984
- VCPUS: { value: (s$1) => s$1.vcpus },
11985
- RUNTIME: { value: (s$1) => s$1.runtime },
11986
- TIMEOUT: { value: (s$1) => timeAgo(s$1.createdAt + s$1.timeout) },
11987
- SNAPSHOT: { value: (s$1) => s$1.currentSnapshotId ?? "-" }
12010
+ MEMORY: { value: (s$1) => s$1.memory != null ? memoryFormatter.format(s$1.memory) : "-" },
12011
+ VCPUS: { value: (s$1) => s$1.vcpus ?? "-" },
12012
+ RUNTIME: { value: (s$1) => s$1.runtime ?? "-" },
12013
+ TIMEOUT: { value: (s$1) => s$1.timeout != null ? timeAgo(s$1.createdAt + s$1.timeout) : "-" },
12014
+ SNAPSHOT: { value: (s$1) => s$1.currentSnapshotId ?? "-" },
12015
+ TAGS: { value: (s$1) => s$1.tags && Object.keys(s$1.tags).length > 0 ? Object.entries(s$1.tags).map(([k, v]) => `${k}:${v}`).join(", ") : "-" }
11988
12016
  };
11989
12017
  if (all) {
11990
12018
  columns.CPU = { value: (s$1) => s$1.totalActiveCpuDurationMs ? formatRunDuration(s$1.totalActiveCpuDurationMs) : "-" };
@@ -14326,9 +14354,9 @@ const stop = import_cjs$10.command({
14326
14354
  scope
14327
14355
  },
14328
14356
  async handler({ scope: { token: token$1, team: team$1, project: project$1 }, sandboxName: sandboxName$1, sandboxNames }) {
14329
- await new Listr(Array.from(new Set([sandboxName$1, ...sandboxNames]), (sandboxName$2) => {
14357
+ const tasks = Array.from(new Set([sandboxName$1, ...sandboxNames]), (sandboxName$2) => {
14330
14358
  return {
14331
- title: `Stopping sandbox ${sandboxName$2}`,
14359
+ title: `Stopping active session from ${sandboxName$2}`,
14332
14360
  async task() {
14333
14361
  await (await sandboxClient.get({
14334
14362
  token: token$1,
@@ -14338,7 +14366,12 @@ const stop = import_cjs$10.command({
14338
14366
  })).stop();
14339
14367
  }
14340
14368
  };
14341
- }), { concurrent: true }).run();
14369
+ });
14370
+ try {
14371
+ await new Listr(tasks, { concurrent: true }).run();
14372
+ } catch {
14373
+ process.exitCode = 1;
14374
+ }
14342
14375
  }
14343
14376
  });
14344
14377
 
@@ -14358,14 +14391,10 @@ const remove = import_cjs$9.command({
14358
14391
  type: sandboxName,
14359
14392
  description: "more sandboxes to remove"
14360
14393
  }),
14361
- preserveSnapshots: import_cjs$9.flag({
14362
- long: "preserve-snapshots",
14363
- description: "Keep snapshots when removing the sandbox"
14364
- }),
14365
14394
  scope
14366
14395
  },
14367
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, sandboxName: sandboxName$1, sandboxNames, preserveSnapshots }) {
14368
- await new Listr(Array.from(new Set([sandboxName$1, ...sandboxNames]), (name) => ({
14396
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, sandboxName: sandboxName$1, sandboxNames }) {
14397
+ const tasks = Array.from(new Set([sandboxName$1, ...sandboxNames]), (name) => ({
14369
14398
  title: `Removing sandbox ${name}`,
14370
14399
  async task() {
14371
14400
  await (await sandboxClient.get({
@@ -14373,9 +14402,14 @@ const remove = import_cjs$9.command({
14373
14402
  teamId: team$1,
14374
14403
  projectId: project$1,
14375
14404
  name
14376
- })).delete({ preserveSnapshots });
14405
+ })).delete();
14377
14406
  }
14378
- })), { concurrent: true }).run();
14407
+ }));
14408
+ try {
14409
+ await new Listr(tasks, { concurrent: true }).run();
14410
+ } catch {
14411
+ process.exitCode = 1;
14412
+ }
14379
14413
  }
14380
14414
  });
14381
14415
 
@@ -14557,14 +14591,14 @@ const list$2 = import_cjs$4.command({
14557
14591
  try {
14558
14592
  var _usingCtx$1 = _usingCtx();
14559
14593
  const _spinner$1 = _usingCtx$1.u(acquireRelease(() => ora("Fetching snapshots...").start(), (s$1) => s$1.stop()));
14560
- const { json } = await snapshotClient.list({
14594
+ const { snapshots: snapshots$2 } = await snapshotClient.list({
14561
14595
  token: token$1,
14562
14596
  teamId: team$1,
14563
14597
  projectId: project$1,
14564
14598
  name,
14565
14599
  limit: 100
14566
14600
  });
14567
- return json.snapshots;
14601
+ return snapshots$2;
14568
14602
  } catch (_) {
14569
14603
  _usingCtx$1.e = _;
14570
14604
  } finally {
@@ -14582,7 +14616,7 @@ const list$2 = import_cjs$4.command({
14582
14616
  CREATED: { value: (s$1) => timeAgo(s$1.createdAt) },
14583
14617
  EXPIRATION: { value: (s$1) => s$1.status === "deleted" ? source_default.gray.dim("deleted") : timeAgo(s$1.expiresAt) },
14584
14618
  SIZE: { value: (s$1) => formatBytes(s$1.sizeBytes) },
14585
- ["SOURCE SESSION"]: { value: (s$1) => s$1.sourceSandboxId }
14619
+ ["SOURCE SESSION"]: { value: (s$1) => s$1.sourceSessionId }
14586
14620
  }
14587
14621
  }));
14588
14622
  }
@@ -14625,7 +14659,7 @@ const get = import_cjs$4.command({
14625
14659
  CREATED: { value: (s$1) => timeAgo(s$1.createdAt) },
14626
14660
  EXPIRATION: { value: (s$1) => s$1.status === "deleted" ? source_default.gray.dim("deleted") : timeAgo(s$1.expiresAt) },
14627
14661
  SIZE: { value: (s$1) => formatBytes(s$1.sizeBytes) },
14628
- ["SOURCE SESSION"]: { value: (s$1) => s$1.sourceSandboxId }
14662
+ ["SOURCE SESSION"]: { value: (s$1) => s$1.sourceSessionId }
14629
14663
  }
14630
14664
  }));
14631
14665
  }
@@ -14646,7 +14680,7 @@ const remove$1 = import_cjs$4.command({
14646
14680
  scope
14647
14681
  },
14648
14682
  async handler({ scope: { team: team$1, token: token$1, project: project$1 }, snapshotId: snapshotId$1, snapshotIds }) {
14649
- await new Listr(Array.from(new Set([snapshotId$1, ...snapshotIds]), (snapshotId$2) => {
14683
+ const tasks = Array.from(new Set([snapshotId$1, ...snapshotIds]), (snapshotId$2) => {
14650
14684
  return {
14651
14685
  title: `Deleting snapshot ${snapshotId$2}`,
14652
14686
  async task() {
@@ -14660,7 +14694,12 @@ const remove$1 = import_cjs$4.command({
14660
14694
  await snapshot$1.delete();
14661
14695
  }
14662
14696
  };
14663
- }), { concurrent: true }).run();
14697
+ });
14698
+ try {
14699
+ await new Listr(tasks, { concurrent: true }).run();
14700
+ } catch {
14701
+ process.exitCode = 1;
14702
+ }
14664
14703
  }
14665
14704
  });
14666
14705
  const snapshots = (0, import_cjs$5.subcommands)({
@@ -14688,20 +14727,25 @@ const list$1 = import_cjs$2.command({
14688
14727
  aliases: ["ls"],
14689
14728
  description: "List sessions from a sandbox",
14690
14729
  args: {
14730
+ all: import_cjs$2.flag({
14731
+ long: "all",
14732
+ short: "a",
14733
+ description: "Show all sessions (default shows just running)"
14734
+ }),
14691
14735
  sandbox: import_cjs$2.positional({
14692
14736
  type: sandboxName,
14693
14737
  description: "Sandbox name to list sessions for"
14694
14738
  }),
14695
14739
  scope
14696
14740
  },
14697
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, sandbox: name }) {
14741
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, sandbox: name }) {
14698
14742
  const sandbox = await sandboxClient.get({
14699
14743
  name,
14700
14744
  projectId: project$1,
14701
14745
  teamId: team$1,
14702
14746
  token: token$1
14703
14747
  });
14704
- const sessions$1 = (await (async () => {
14748
+ let { sessions: sessions$1 } = await (async () => {
14705
14749
  try {
14706
14750
  var _usingCtx$1 = _usingCtx();
14707
14751
  const _spinner$1 = _usingCtx$1.u(acquireRelease(() => ora("Fetching sessions...").start(), (s$1) => s$1.stop()));
@@ -14711,22 +14755,33 @@ const list$1 = import_cjs$2.command({
14711
14755
  } finally {
14712
14756
  _usingCtx$1.d();
14713
14757
  }
14714
- })()).json.sandboxes;
14758
+ })();
14759
+ if (!all) sessions$1 = sessions$1.filter((x) => x.status === "running");
14760
+ const memoryFormatter = new Intl.NumberFormat(void 0, {
14761
+ style: "unit",
14762
+ unit: "megabyte"
14763
+ });
14764
+ const columns = {
14765
+ ID: { value: (s$1) => s$1.id },
14766
+ STATUS: {
14767
+ value: (s$1) => s$1.status,
14768
+ color: (s$1) => SessionStatusColor[s$1.status] ?? source_default.reset
14769
+ },
14770
+ CREATED: { value: (s$1) => timeAgo(s$1.createdAt) },
14771
+ MEMORY: { value: (s$1) => memoryFormatter.format(s$1.memory) },
14772
+ VCPUS: { value: (s$1) => s$1.vcpus },
14773
+ RUNTIME: { value: (s$1) => s$1.runtime },
14774
+ TIMEOUT: { value: (s$1) => timeAgo(s$1.createdAt + s$1.timeout) },
14775
+ DURATION: { value: (s$1) => s$1.duration ? formatRunDuration(s$1.duration) : "-" },
14776
+ SNAPSHOT: { value: (s$1) => s$1.sourceSnapshotId ?? "-" }
14777
+ };
14778
+ if (all) {
14779
+ columns.CPU = { value: (s$1) => s$1.activeCpuDurationMs ? formatRunDuration(s$1.activeCpuDurationMs) : "-" };
14780
+ columns["NETWORK (OUT/IN)"] = { value: (s$1) => s$1.networkTransfer?.egress || s$1.networkTransfer?.ingress ? `${formatBytes(s$1.networkTransfer?.egress ?? 0)} / ${formatBytes(s$1.networkTransfer?.ingress ?? 0)}` : "- / -" };
14781
+ }
14715
14782
  console.log(table({
14716
14783
  rows: sessions$1,
14717
- columns: {
14718
- ID: { value: (s$1) => s$1.id },
14719
- STATUS: {
14720
- value: (s$1) => s$1.status,
14721
- color: (s$1) => SessionStatusColor[s$1.status] ?? source_default.reset
14722
- },
14723
- CREATED: { value: (s$1) => timeAgo(s$1.createdAt) },
14724
- MEMORY: { value: (s$1) => s$1.memory },
14725
- VCPUS: { value: (s$1) => s$1.vcpus },
14726
- RUNTIME: { value: (s$1) => s$1.runtime },
14727
- TIMEOUT: { value: (s$1) => timeAgo(s$1.createdAt + s$1.timeout) },
14728
- DURATION: { value: (s$1) => s$1.duration ? formatRunDuration(s$1.duration) : "-" }
14729
- }
14784
+ columns
14730
14785
  }));
14731
14786
  }
14732
14787
  });
@@ -14883,11 +14938,11 @@ const listCommand = import_cjs$1.command({
14883
14938
  const rows = [
14884
14939
  {
14885
14940
  field: "vCPUs",
14886
- value: String(sandbox.vcpus)
14941
+ value: String(sandbox.vcpus ?? "-")
14887
14942
  },
14888
14943
  {
14889
14944
  field: "Timeout",
14890
- value: (0, import_ms.default)(sandbox.timeout, { long: true })
14945
+ value: sandbox.timeout != null ? (0, import_ms.default)(sandbox.timeout, { long: true }) : "-"
14891
14946
  },
14892
14947
  {
14893
14948
  field: "Persistent",
@@ -15006,4 +15061,4 @@ const app = (opts) => (0, import_cjs.subcommands)({
15006
15061
 
15007
15062
  //#endregion
15008
15063
  export { source_exports as a, init_source as i, StyledError as n, require_cjs as r, app as t };
15009
- //# sourceMappingURL=app-BvyZgr9h.mjs.map
15064
+ //# sourceMappingURL=app-CZIqoxxn.mjs.map