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.cjs CHANGED
@@ -17970,7 +17970,7 @@ var wheels_default = {
17970
17970
 
17971
17971
  // package.json
17972
17972
  var package_default = {
17973
- version: "0.1.68"};
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 });
@@ -19884,7 +19890,11 @@ async function startPythonProcess(options) {
19884
19890
  pid: options.pid,
19885
19891
  ppid: options.ppid,
19886
19892
  mounts: options.mounts,
19887
- isTty: options.isTty
19893
+ isTty: options.isTty,
19894
+ /* Only beyond the standard three: 0, 1 and 2 are bound as the process's
19895
+ * terminal-or-pipe streams by the worker itself, and installing a second
19896
+ * stream over one of them would leave two objects claiming the number. */
19897
+ inheritFds: inheritedFds.filter((fd) => fd > 2)
19888
19898
  });
19889
19899
  return {
19890
19900
  write: (data) => stdin.push(data),
@@ -20363,11 +20373,18 @@ function consoleLauncher(target) {
20363
20373
  return `#!/usr/bin/python3
20364
20374
  import sys
20365
20375
  from importlib import import_module
20366
- entry = import_module(${JSON.stringify(module)})
20367
- for part in ${JSON.stringify(attribute)}.split('.'):
20368
- if part:
20369
- entry = getattr(entry, part)
20370
- 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()())
20371
20388
  `;
20372
20389
  }
20373
20390
 
@@ -20378,10 +20395,10 @@ var WNOHANG = 1;
20378
20395
  function claimInheritance(env2) {
20379
20396
  const token = env2[INHERIT_TOKEN];
20380
20397
  if (!token) return void 0;
20381
- const files = PENDING_INHERITANCE.get(token);
20398
+ const held = PENDING_INHERITANCE.get(token);
20382
20399
  PENDING_INHERITANCE.delete(token);
20383
20400
  delete env2[INHERIT_TOKEN];
20384
- return files;
20401
+ return held;
20385
20402
  }
20386
20403
  function waitStatus(proc) {
20387
20404
  if (proc.termSignal) return signalNumber(proc.termSignal) & 127;
@@ -20407,15 +20424,11 @@ function createProcessService(ctx) {
20407
20424
  return {
20408
20425
  async spawn(request) {
20409
20426
  const token = `${ctx.proc.pid}:${Math.random().toString(36).slice(2)}`;
20410
- const extra = /* @__PURE__ */ new Map();
20411
- for (const [fd, description] of request.files) {
20412
- if (fd > 2) extra.set(fd, description);
20413
- }
20414
20427
  const env2 = { ...request.env };
20415
- if (extra.size > 0) {
20416
- PENDING_INHERITANCE.set(token, extra);
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) {