sandboxedjs 0.1.68 → 0.1.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17953,7 +17953,7 @@ var wheels_default = {
17953
17953
 
17954
17954
  // package.json
17955
17955
  var package_default = {
17956
- version: "0.1.68"};
17956
+ version: "0.1.70"};
17957
17957
 
17958
17958
  // src/runtime/python/config.ts
17959
17959
  var bundledManifest = {
@@ -18498,9 +18498,6 @@ function toPosixError(error) {
18498
18498
  };
18499
18499
  return new PosixError(code && mapped[code] ? mapped[code] : Errno.EIO, message);
18500
18500
  }
18501
-
18502
- // src/runtime/python/backend.ts
18503
- init_signals();
18504
18501
  var DescriptorTable = class _DescriptorTable {
18505
18502
  slots = /* @__PURE__ */ new Map();
18506
18503
  /** Descriptions this table shares with others, so close counts correctly. */
@@ -18571,6 +18568,10 @@ var DescriptorTable = class _DescriptorTable {
18571
18568
  }
18572
18569
  }
18573
18570
  }
18571
+ /** The numbers this table currently holds, in ascending order. */
18572
+ fds() {
18573
+ return [...this.slots.keys()].sort((a, b) => a - b);
18574
+ }
18574
18575
  get openCount() {
18575
18576
  return this.slots.size;
18576
18577
  }
@@ -18672,6 +18673,9 @@ var FileService = class {
18672
18673
  }
18673
18674
  };
18674
18675
 
18676
+ // src/runtime/python/backend.ts
18677
+ init_signals();
18678
+
18675
18679
  // src/runtime/python/protocol.ts
18676
18680
  var ProtocolError = class extends Error {
18677
18681
  code = "ERR_SBX_ABI_PROTOCOL";
@@ -19787,7 +19791,9 @@ async function startPythonProcess(options) {
19787
19791
  table.set(0, stdin);
19788
19792
  table.set(1, stdout);
19789
19793
  table.set(2, stderr);
19790
- for (const [fd, description] of options.inherit ?? []) table.set(fd, description);
19794
+ const inheritedFds = options.inherit?.fds() ?? [];
19795
+ for (const fd of inheritedFds) table.set(fd, options.inherit.get(fd));
19796
+ options.inherit?.closeAll();
19791
19797
  const controller = new AbortController();
19792
19798
  const abort = () => controller.abort();
19793
19799
  options.signal.addEventListener("abort", abort, { once: true });
@@ -19867,7 +19873,11 @@ async function startPythonProcess(options) {
19867
19873
  pid: options.pid,
19868
19874
  ppid: options.ppid,
19869
19875
  mounts: options.mounts,
19870
- isTty: options.isTty
19876
+ isTty: options.isTty,
19877
+ /* Only beyond the standard three: 0, 1 and 2 are bound as the process's
19878
+ * terminal-or-pipe streams by the worker itself, and installing a second
19879
+ * stream over one of them would leave two objects claiming the number. */
19880
+ inheritFds: inheritedFds.filter((fd) => fd > 2)
19871
19881
  });
19872
19882
  return {
19873
19883
  write: (data) => stdin.push(data),
@@ -20346,11 +20356,18 @@ function consoleLauncher(target) {
20346
20356
  return `#!/usr/bin/python3
20347
20357
  import sys
20348
20358
  from importlib import import_module
20349
- entry = import_module(${JSON.stringify(module)})
20350
- for part in ${JSON.stringify(attribute)}.split('.'):
20351
- if part:
20352
- entry = getattr(entry, part)
20353
- raise SystemExit(entry())
20359
+
20360
+
20361
+ def _entry():
20362
+ entry = import_module(${JSON.stringify(module)})
20363
+ for part in ${JSON.stringify(attribute)}.split('.'):
20364
+ if part:
20365
+ entry = getattr(entry, part)
20366
+ return entry
20367
+
20368
+
20369
+ if __name__ == '__main__':
20370
+ sys.exit(_entry()())
20354
20371
  `;
20355
20372
  }
20356
20373
 
@@ -20361,10 +20378,10 @@ var WNOHANG = 1;
20361
20378
  function claimInheritance(env2) {
20362
20379
  const token = env2[INHERIT_TOKEN];
20363
20380
  if (!token) return void 0;
20364
- const files = PENDING_INHERITANCE.get(token);
20381
+ const held = PENDING_INHERITANCE.get(token);
20365
20382
  PENDING_INHERITANCE.delete(token);
20366
20383
  delete env2[INHERIT_TOKEN];
20367
- return files;
20384
+ return held;
20368
20385
  }
20369
20386
  function waitStatus(proc) {
20370
20387
  if (proc.termSignal) return signalNumber(proc.termSignal) & 127;
@@ -20390,15 +20407,11 @@ function createProcessService(ctx) {
20390
20407
  return {
20391
20408
  async spawn(request) {
20392
20409
  const token = `${ctx.proc.pid}:${Math.random().toString(36).slice(2)}`;
20393
- const extra = /* @__PURE__ */ new Map();
20394
- for (const [fd, description] of request.files) {
20395
- if (fd > 2) extra.set(fd, description);
20396
- }
20397
20410
  const env2 = { ...request.env };
20398
- if (extra.size > 0) {
20399
- PENDING_INHERITANCE.set(token, extra);
20400
- env2[INHERIT_TOKEN] = token;
20401
- }
20411
+ const held = new DescriptorTable();
20412
+ for (const [fd, description] of request.files) held.set(fd, description);
20413
+ PENDING_INHERITANCE.set(token, held);
20414
+ env2[INHERIT_TOKEN] = token;
20402
20415
  const stdin = request.files.get(0);
20403
20416
  const argv = [containerProgram(ctx, request.argv[0] ?? ""), ...request.argv.slice(1)];
20404
20417
  const proc = ctx.kernel.spawn(argv, {
@@ -20411,7 +20424,9 @@ function createProcessService(ctx) {
20411
20424
  stderr: outputFor(request.files.get(2), ctx.stderr)
20412
20425
  });
20413
20426
  children.set(proc.pid, proc);
20414
- void proc.wait().finally(() => PENDING_INHERITANCE.delete(token));
20427
+ void proc.wait().finally(() => {
20428
+ if (PENDING_INHERITANCE.delete(token)) held.closeAll();
20429
+ });
20415
20430
  return proc.pid;
20416
20431
  },
20417
20432
  async wait(pid, options) {