sandbox 3.0.2 → 3.1.0

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.
@@ -3102,13 +3102,13 @@ var require_ms = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ms@2.1
3102
3102
  * @return {String}
3103
3103
  * @api private
3104
3104
  */
3105
- function fmtShort(ms$6) {
3106
- var msAbs = Math.abs(ms$6);
3107
- if (msAbs >= d) return Math.round(ms$6 / d) + "d";
3108
- if (msAbs >= h) return Math.round(ms$6 / h) + "h";
3109
- if (msAbs >= m) return Math.round(ms$6 / m) + "m";
3110
- if (msAbs >= s) return Math.round(ms$6 / s) + "s";
3111
- return ms$6 + "ms";
3105
+ function fmtShort(ms$7) {
3106
+ var msAbs = Math.abs(ms$7);
3107
+ if (msAbs >= d) return Math.round(ms$7 / d) + "d";
3108
+ if (msAbs >= h) return Math.round(ms$7 / h) + "h";
3109
+ if (msAbs >= m) return Math.round(ms$7 / m) + "m";
3110
+ if (msAbs >= s) return Math.round(ms$7 / s) + "s";
3111
+ return ms$7 + "ms";
3112
3112
  }
3113
3113
  /**
3114
3114
  * Long format for `ms`.
@@ -3117,20 +3117,20 @@ var require_ms = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/ms@2.1
3117
3117
  * @return {String}
3118
3118
  * @api private
3119
3119
  */
3120
- function fmtLong(ms$6) {
3121
- var msAbs = Math.abs(ms$6);
3122
- if (msAbs >= d) return plural(ms$6, msAbs, d, "day");
3123
- if (msAbs >= h) return plural(ms$6, msAbs, h, "hour");
3124
- if (msAbs >= m) return plural(ms$6, msAbs, m, "minute");
3125
- if (msAbs >= s) return plural(ms$6, msAbs, s, "second");
3126
- return ms$6 + " ms";
3120
+ function fmtLong(ms$7) {
3121
+ var msAbs = Math.abs(ms$7);
3122
+ if (msAbs >= d) return plural(ms$7, msAbs, d, "day");
3123
+ if (msAbs >= h) return plural(ms$7, msAbs, h, "hour");
3124
+ if (msAbs >= m) return plural(ms$7, msAbs, m, "minute");
3125
+ if (msAbs >= s) return plural(ms$7, msAbs, s, "second");
3126
+ return ms$7 + " ms";
3127
3127
  }
3128
3128
  /**
3129
3129
  * Pluralization helper.
3130
3130
  */
3131
- function plural(ms$6, msAbs, n, name) {
3131
+ function plural(ms$7, msAbs, n, name) {
3132
3132
  var isPlural = msAbs >= n * 1.5;
3133
- return Math.round(ms$6 / n) + " " + name + (isPlural ? "s" : "");
3133
+ return Math.round(ms$7 / n) + " " + name + (isPlural ? "s" : "");
3134
3134
  }
3135
3135
  }) });
3136
3136
 
@@ -7290,7 +7290,7 @@ const scope = {
7290
7290
 
7291
7291
  //#endregion
7292
7292
  //#region package.json
7293
- var version = "3.0.2";
7293
+ var version = "3.1.0";
7294
7294
 
7295
7295
  //#endregion
7296
7296
  //#region src/error.ts
@@ -11190,9 +11190,9 @@ function printCommand(command$1, args$5) {
11190
11190
 
11191
11191
  //#endregion
11192
11192
  //#region src/interactive-shell/extend-sandbox-timeout.ts
11193
- var import_ms$5 = /* @__PURE__ */ __toESM(require_ms());
11193
+ var import_ms$6 = /* @__PURE__ */ __toESM(require_ms());
11194
11194
  const debug$2 = createDebugger("sandbox:timeout");
11195
- const BUFFER = (0, import_ms$5.default)("10 seconds");
11195
+ const BUFFER = (0, import_ms$6.default)("10 seconds");
11196
11196
  async function extendSandboxTimeoutPeriodically(sandbox, signal) {
11197
11197
  const session = sandbox.currentSession();
11198
11198
  const timeout$1 = session.timeout;
@@ -11207,7 +11207,7 @@ async function extendSandboxTimeoutPeriodically(sandbox, signal) {
11207
11207
  debug$2(`sleeping for ${sleepMs}ms until next timeout extension`);
11208
11208
  await setTimeout$1(sleepMs, null, { signal });
11209
11209
  }
11210
- await sandbox.extendTimeout((0, import_ms$5.default)("5 minutes"));
11210
+ await sandbox.extendTimeout((0, import_ms$6.default)("5 minutes"));
11211
11211
  const updatedTimeout = session.timeout;
11212
11212
  if (updatedTimeout == null) return;
11213
11213
  const nextTick$1 = session.createdAt.getTime() + updatedTimeout;
@@ -11480,11 +11480,11 @@ async function openWithRetry(create$1) {
11480
11480
  factor: 0
11481
11481
  });
11482
11482
  }
11483
- function withTimeout(promise, ms$6) {
11483
+ function withTimeout(promise, ms$7) {
11484
11484
  promise.catch(() => {});
11485
11485
  let timer;
11486
11486
  const timeout$1 = new Promise((_, reject) => {
11487
- timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Operation timed out after ${ms$6}ms`)), ms$6);
11487
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Operation timed out after ${ms$7}ms`)), ms$7);
11488
11488
  });
11489
11489
  return Promise.race([promise, timeout$1]).finally(() => {
11490
11490
  if (timer) clearTimeout(timer);
@@ -11545,6 +11545,7 @@ const ObjectFromKeyValue = import_cjs$18.extendType(import_cjs$18.array(KeyValue
11545
11545
  //#endregion
11546
11546
  //#region src/commands/exec.ts
11547
11547
  var import_cjs$17 = /* @__PURE__ */ __toESM(require_cjs());
11548
+ var import_ms$5 = /* @__PURE__ */ __toESM(require_ms());
11548
11549
  init_source();
11549
11550
  const args$4 = {
11550
11551
  sandbox: import_cjs$17.positional({ type: sandboxName }),
@@ -11595,13 +11596,19 @@ const args$4 = {
11595
11596
  type: ObjectFromKeyValue,
11596
11597
  description: "Environment variables to set for the command"
11597
11598
  }),
11599
+ timeout: import_cjs$17.option({
11600
+ long: "timeout",
11601
+ type: import_cjs$17.optional(Duration),
11602
+ description: "Maximum duration to wait for the command (e.g. 30s, 5m). On expiry the process is killed with SIGKILL. Cannot be combined with --interactive."
11603
+ }),
11598
11604
  scope
11599
11605
  };
11600
11606
  const exec = import_cjs$17.command({
11601
11607
  name: "exec",
11602
11608
  description: "Execute a command in an existing sandbox",
11603
11609
  args: args$4,
11604
- async handler({ command: command$1, cwd, args: args$5, asSudo, sandbox: sandboxName$1, scope: { token: token$1, team: team$1, project: project$1 }, interactive, envVars, skipExtendingTimeout }) {
11610
+ async handler({ command: command$1, cwd, args: args$5, asSudo, sandbox: sandboxName$1, scope: { token: token$1, team: team$1, project: project$1 }, interactive, envVars, skipExtendingTimeout, timeout: timeout$1 }) {
11611
+ if (interactive && timeout$1) throw new Error(["--timeout cannot be combined with --interactive.", `${source_default.bold("hint:")} Remove one of the two flags. Interactive sessions do not enforce a command timeout.`].join("\n"));
11605
11612
  const sandbox = typeof sandboxName$1 !== "string" ? sandboxName$1 : await sandboxClient.get({
11606
11613
  name: sandboxName$1,
11607
11614
  projectId: project$1,
@@ -11618,8 +11625,10 @@ const exec = import_cjs$17.command({
11618
11625
  stdout: process.stdout,
11619
11626
  sudo: asSudo,
11620
11627
  cwd,
11621
- env: envVars
11628
+ env: envVars,
11629
+ timeoutMs: timeout$1 ? (0, import_ms$5.default)(timeout$1) : void 0
11622
11630
  });
11631
+ if (timeout$1 && result.exitCode === 137) console.error(`${source_default.yellow("Command was killed (SIGKILL, exit code 137)")}.`);
11623
11632
  process.exitCode = result.exitCode;
11624
11633
  } else await startInteractiveShell({
11625
11634
  sandbox,
@@ -11889,7 +11898,8 @@ const create = import_cjs$15.command({
11889
11898
  command: "sh",
11890
11899
  interactive: true,
11891
11900
  tty: true,
11892
- sandbox
11901
+ sandbox,
11902
+ timeout: void 0
11893
11903
  });
11894
11904
  return sandbox;
11895
11905
  }
@@ -12010,7 +12020,8 @@ const fork = import_cjs$14.command({
12010
12020
  command: "sh",
12011
12021
  interactive: true,
12012
12022
  tty: true,
12013
- sandbox
12023
+ sandbox,
12024
+ timeout: void 0
12014
12025
  });
12015
12026
  return sandbox;
12016
12027
  }
@@ -12029,7 +12040,7 @@ function omit(obj, ...keys) {
12029
12040
  var import_cjs$13 = /* @__PURE__ */ __toESM(require_cjs());
12030
12041
  const args$1 = {
12031
12042
  ...args$3,
12032
- ...omit(args$4, "sandbox"),
12043
+ ...omit(args$4, "sandbox", "timeout"),
12033
12044
  removeAfterUse: import_cjs$13.flag({
12034
12045
  long: "rm",
12035
12046
  description: "Automatically remove the sandbox when the command exits."
@@ -12069,7 +12080,8 @@ const run = import_cjs$13.command({
12069
12080
  try {
12070
12081
  await exec.handler({
12071
12082
  ...rest$1,
12072
- sandbox
12083
+ sandbox,
12084
+ timeout: void 0
12073
12085
  });
12074
12086
  } finally {
12075
12087
  if (removeAfterUse) await sandbox.delete();
@@ -14798,10 +14810,10 @@ const snapshot = import_cjs$6.command({
14798
14810
  init_source();
14799
14811
  function formatExpires(expiresAt) {
14800
14812
  if (expiresAt === void 0) return source_default.gray("never");
14801
- const ms$6 = expiresAt - Date.now();
14802
- if (ms$6 <= 0) return source_default.red("expired");
14813
+ const ms$7 = expiresAt - Date.now();
14814
+ if (ms$7 <= 0) return source_default.red("expired");
14803
14815
  const formatted = timeAgo(expiresAt);
14804
- return ms$6 <= 3600 * 1e3 ? source_default.red(formatted) : source_default.green(formatted);
14816
+ return ms$7 <= 3600 * 1e3 ? source_default.red(formatted) : source_default.green(formatted);
14805
14817
  }
14806
14818
  function renderNode(id, expiresAt, isCurrent) {
14807
14819
  const bullet = isCurrent ? source_default.magenta.bold("●") : source_default.magenta("●");
@@ -15860,4 +15872,4 @@ const app = (opts) => (0, import_cjs.subcommands)({
15860
15872
 
15861
15873
  //#endregion
15862
15874
  export { source_exports as a, init_source as i, StyledError as n, require_cjs as r, app as t };
15863
- //# sourceMappingURL=app-C9tVyCZD.mjs.map
15875
+ //# sourceMappingURL=app-CUphjb1B.mjs.map