sandboxedjs 0.1.69 → 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.cjs CHANGED
@@ -17970,7 +17970,7 @@ var wheels_default = {
17970
17970
 
17971
17971
  // package.json
17972
17972
  var package_default = {
17973
- version: "0.1.69"};
17973
+ version: "0.1.70"};
17974
17974
 
17975
17975
  // src/runtime/python/config.ts
17976
17976
  var bundledManifest = {
@@ -18515,9 +18515,6 @@ function toPosixError(error) {
18515
18515
  };
18516
18516
  return new PosixError(code && mapped[code] ? mapped[code] : Errno.EIO, message);
18517
18517
  }
18518
-
18519
- // src/runtime/python/backend.ts
18520
- init_signals();
18521
18518
  var DescriptorTable = class _DescriptorTable {
18522
18519
  slots = /* @__PURE__ */ new Map();
18523
18520
  /** Descriptions this table shares with others, so close counts correctly. */
@@ -18588,6 +18585,10 @@ var DescriptorTable = class _DescriptorTable {
18588
18585
  }
18589
18586
  }
18590
18587
  }
18588
+ /** The numbers this table currently holds, in ascending order. */
18589
+ fds() {
18590
+ return [...this.slots.keys()].sort((a, b) => a - b);
18591
+ }
18591
18592
  get openCount() {
18592
18593
  return this.slots.size;
18593
18594
  }
@@ -18689,6 +18690,9 @@ var FileService = class {
18689
18690
  }
18690
18691
  };
18691
18692
 
18693
+ // src/runtime/python/backend.ts
18694
+ init_signals();
18695
+
18692
18696
  // src/runtime/python/protocol.ts
18693
18697
  var ProtocolError = class extends Error {
18694
18698
  code = "ERR_SBX_ABI_PROTOCOL";
@@ -19804,7 +19808,9 @@ async function startPythonProcess(options) {
19804
19808
  table.set(0, stdin);
19805
19809
  table.set(1, stdout);
19806
19810
  table.set(2, stderr);
19807
- for (const [fd, description] of options.inherit ?? []) table.set(fd, description);
19811
+ const inheritedFds = options.inherit?.fds() ?? [];
19812
+ for (const fd of inheritedFds) table.set(fd, options.inherit.get(fd));
19813
+ options.inherit?.closeAll();
19808
19814
  const controller = new AbortController();
19809
19815
  const abort = () => controller.abort();
19810
19816
  options.signal.addEventListener("abort", abort, { once: true });
@@ -19888,7 +19894,7 @@ async function startPythonProcess(options) {
19888
19894
  /* Only beyond the standard three: 0, 1 and 2 are bound as the process's
19889
19895
  * terminal-or-pipe streams by the worker itself, and installing a second
19890
19896
  * stream over one of them would leave two objects claiming the number. */
19891
- inheritFds: [...options.inherit?.keys() ?? []].filter((fd) => fd > 2)
19897
+ inheritFds: inheritedFds.filter((fd) => fd > 2)
19892
19898
  });
19893
19899
  return {
19894
19900
  write: (data) => stdin.push(data),
@@ -20367,11 +20373,18 @@ function consoleLauncher(target) {
20367
20373
  return `#!/usr/bin/python3
20368
20374
  import sys
20369
20375
  from importlib import import_module
20370
- entry = import_module(${JSON.stringify(module)})
20371
- for part in ${JSON.stringify(attribute)}.split('.'):
20372
- if part:
20373
- entry = getattr(entry, part)
20374
- raise SystemExit(entry())
20376
+
20377
+
20378
+ def _entry():
20379
+ entry = import_module(${JSON.stringify(module)})
20380
+ for part in ${JSON.stringify(attribute)}.split('.'):
20381
+ if part:
20382
+ entry = getattr(entry, part)
20383
+ return entry
20384
+
20385
+
20386
+ if __name__ == '__main__':
20387
+ sys.exit(_entry()())
20375
20388
  `;
20376
20389
  }
20377
20390
 
@@ -20382,10 +20395,10 @@ var WNOHANG = 1;
20382
20395
  function claimInheritance(env2) {
20383
20396
  const token = env2[INHERIT_TOKEN];
20384
20397
  if (!token) return void 0;
20385
- const files = PENDING_INHERITANCE.get(token);
20398
+ const held = PENDING_INHERITANCE.get(token);
20386
20399
  PENDING_INHERITANCE.delete(token);
20387
20400
  delete env2[INHERIT_TOKEN];
20388
- return files;
20401
+ return held;
20389
20402
  }
20390
20403
  function waitStatus(proc) {
20391
20404
  if (proc.termSignal) return signalNumber(proc.termSignal) & 127;
@@ -20412,10 +20425,10 @@ function createProcessService(ctx) {
20412
20425
  async spawn(request) {
20413
20426
  const token = `${ctx.proc.pid}:${Math.random().toString(36).slice(2)}`;
20414
20427
  const env2 = { ...request.env };
20415
- if (request.files.size > 0) {
20416
- PENDING_INHERITANCE.set(token, new Map(request.files));
20417
- env2[INHERIT_TOKEN] = token;
20418
- }
20428
+ const held = new DescriptorTable();
20429
+ for (const [fd, description] of request.files) held.set(fd, description);
20430
+ PENDING_INHERITANCE.set(token, held);
20431
+ env2[INHERIT_TOKEN] = token;
20419
20432
  const stdin = request.files.get(0);
20420
20433
  const argv = [containerProgram(ctx, request.argv[0] ?? ""), ...request.argv.slice(1)];
20421
20434
  const proc = ctx.kernel.spawn(argv, {
@@ -20428,7 +20441,9 @@ function createProcessService(ctx) {
20428
20441
  stderr: outputFor(request.files.get(2), ctx.stderr)
20429
20442
  });
20430
20443
  children.set(proc.pid, proc);
20431
- void proc.wait().finally(() => PENDING_INHERITANCE.delete(token));
20444
+ void proc.wait().finally(() => {
20445
+ if (PENDING_INHERITANCE.delete(token)) held.closeAll();
20446
+ });
20432
20447
  return proc.pid;
20433
20448
  },
20434
20449
  async wait(pid, options) {