secure-exec 0.0.1 → 0.1.0-rc.1

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.
Files changed (112) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +7 -0
  3. package/dist/bridge/active-handles.d.ts +21 -0
  4. package/dist/bridge/active-handles.js +60 -0
  5. package/dist/bridge/child-process.d.ts +87 -0
  6. package/dist/bridge/child-process.js +523 -0
  7. package/dist/bridge/fs.d.ts +227 -0
  8. package/dist/bridge/fs.js +1572 -0
  9. package/dist/bridge/index.d.ts +10 -0
  10. package/dist/bridge/index.js +41 -0
  11. package/dist/bridge/module.d.ts +73 -0
  12. package/dist/bridge/module.js +329 -0
  13. package/dist/bridge/network.d.ts +208 -0
  14. package/dist/bridge/network.js +1117 -0
  15. package/dist/bridge/os.d.ts +13 -0
  16. package/dist/bridge/os.js +257 -0
  17. package/dist/bridge/polyfills.d.ts +2 -0
  18. package/dist/bridge/polyfills.js +12 -0
  19. package/dist/bridge/process.d.ts +64 -0
  20. package/dist/bridge/process.js +916 -0
  21. package/dist/bridge-loader.d.ts +1 -0
  22. package/dist/bridge-loader.js +2 -0
  23. package/dist/bridge-setup.d.ts +1 -0
  24. package/dist/bridge-setup.js +2 -0
  25. package/dist/bridge.js +10586 -0
  26. package/dist/browser/driver.d.ts +42 -0
  27. package/dist/browser/driver.js +263 -0
  28. package/dist/browser/index.d.ts +5 -0
  29. package/dist/browser/index.js +4 -0
  30. package/dist/browser/worker.d.ts +1 -0
  31. package/dist/browser/worker.js +3 -0
  32. package/dist/browser-runtime.d.ts +6 -0
  33. package/dist/browser-runtime.js +4 -0
  34. package/dist/esm-compiler.d.ts +1 -0
  35. package/dist/esm-compiler.js +2 -0
  36. package/dist/execution.d.ts +1 -0
  37. package/dist/execution.js +2 -0
  38. package/dist/fs-helpers.d.ts +2 -0
  39. package/dist/fs-helpers.js +1 -0
  40. package/dist/generated/isolate-runtime.d.ts +19 -0
  41. package/dist/generated/isolate-runtime.js +21 -0
  42. package/dist/generated/polyfills.d.ts +82 -0
  43. package/dist/generated/polyfills.js +82 -0
  44. package/dist/index.d.ts +15 -0
  45. package/dist/index.js +11 -0
  46. package/dist/isolate-runtime/apply-custom-global-policy.js +54 -0
  47. package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +44 -0
  48. package/dist/isolate-runtime/apply-timing-mitigation-off.js +14 -0
  49. package/dist/isolate-runtime/bridge-attach.js +29 -0
  50. package/dist/isolate-runtime/bridge-initial-globals.js +78 -0
  51. package/dist/isolate-runtime/eval-script-result.js +8 -0
  52. package/dist/isolate-runtime/global-exposure-helpers.js +36 -0
  53. package/dist/isolate-runtime/init-commonjs-module-globals.js +28 -0
  54. package/dist/isolate-runtime/override-process-cwd.js +8 -0
  55. package/dist/isolate-runtime/override-process-env.js +8 -0
  56. package/dist/isolate-runtime/require-setup.js +606 -0
  57. package/dist/isolate-runtime/set-commonjs-file-globals.js +36 -0
  58. package/dist/isolate-runtime/set-stdin-data.js +10 -0
  59. package/dist/isolate-runtime/setup-dynamic-import.js +64 -0
  60. package/dist/isolate-runtime/setup-fs-facade.js +40 -0
  61. package/dist/isolate.d.ts +1 -0
  62. package/dist/isolate.js +2 -0
  63. package/dist/module-resolver.d.ts +1 -0
  64. package/dist/module-resolver.js +2 -0
  65. package/dist/node/bridge-setup.d.ts +1 -0
  66. package/dist/node/bridge-setup.js +2 -0
  67. package/dist/node/driver.d.ts +2 -0
  68. package/dist/node/driver.js +2 -0
  69. package/dist/node/esm-compiler.d.ts +1 -0
  70. package/dist/node/esm-compiler.js +2 -0
  71. package/dist/node/execution-driver.d.ts +2 -0
  72. package/dist/node/execution-driver.js +2 -0
  73. package/dist/node/execution-lifecycle.d.ts +1 -0
  74. package/dist/node/execution-lifecycle.js +2 -0
  75. package/dist/node/isolate-bootstrap.d.ts +2 -0
  76. package/dist/node/isolate-bootstrap.js +1 -0
  77. package/dist/node/module-access.d.ts +2 -0
  78. package/dist/node/module-access.js +2 -0
  79. package/dist/node/module-resolver.d.ts +1 -0
  80. package/dist/node/module-resolver.js +2 -0
  81. package/dist/package-bundler.d.ts +2 -0
  82. package/dist/package-bundler.js +1 -0
  83. package/dist/polyfills.d.ts +1 -0
  84. package/dist/polyfills.js +2 -0
  85. package/dist/python-runtime.d.ts +2 -0
  86. package/dist/python-runtime.js +2 -0
  87. package/dist/runtime-driver.d.ts +1 -0
  88. package/dist/runtime-driver.js +1 -0
  89. package/dist/runtime.d.ts +2 -0
  90. package/dist/runtime.js +2 -0
  91. package/dist/shared/api-types.d.ts +1 -0
  92. package/dist/shared/api-types.js +1 -0
  93. package/dist/shared/bridge-contract.d.ts +2 -0
  94. package/dist/shared/bridge-contract.js +1 -0
  95. package/dist/shared/console-formatter.d.ts +2 -0
  96. package/dist/shared/console-formatter.js +1 -0
  97. package/dist/shared/errors.d.ts +2 -0
  98. package/dist/shared/errors.js +1 -0
  99. package/dist/shared/esm-utils.d.ts +1 -0
  100. package/dist/shared/esm-utils.js +2 -0
  101. package/dist/shared/global-exposure.d.ts +2 -0
  102. package/dist/shared/global-exposure.js +1 -0
  103. package/dist/shared/in-memory-fs.d.ts +1 -0
  104. package/dist/shared/in-memory-fs.js +2 -0
  105. package/dist/shared/permissions.d.ts +1 -0
  106. package/dist/shared/permissions.js +2 -0
  107. package/dist/shared/require-setup.d.ts +1 -0
  108. package/dist/shared/require-setup.js +2 -0
  109. package/dist/types.d.ts +2 -0
  110. package/dist/types.js +1 -0
  111. package/package.json +51 -4
  112. package/index.js +0 -1
@@ -0,0 +1,15 @@
1
+ export { NodeRuntime } from "./runtime.js";
2
+ export type { NodeRuntimeOptions } from "./runtime.js";
3
+ export type { ResourceBudgets } from "./runtime-driver.js";
4
+ export { PythonRuntime } from "./python-runtime.js";
5
+ export type { PythonRuntimeOptions } from "./python-runtime.js";
6
+ export type { CommandExecutor, NodeRuntimeDriver, NodeRuntimeDriverFactory, NetworkAdapter, Permissions, PythonRuntimeDriver, PythonRuntimeDriverFactory, RuntimeDriver, RuntimeDriverFactory, SharedRuntimeDriver, SystemDriver, VirtualFileSystem, } from "./types.js";
7
+ export type { DirEntry, StatInfo } from "./fs-helpers.js";
8
+ export type { StdioChannel, StdioEvent, StdioHook, ExecOptions, ExecResult, OSConfig, PythonRunOptions, PythonRunResult, ProcessConfig, RunResult, TimingMitigation, } from "./shared/api-types.js";
9
+ export { createDefaultNetworkAdapter, createNodeDriver, createNodeRuntimeDriverFactory, NodeExecutionDriver, NodeFileSystem, } from "@secure-exec/node";
10
+ export type { ModuleAccessOptions, NodeRuntimeDriverFactoryOptions, } from "@secure-exec/node";
11
+ export { createPyodideRuntimeDriverFactory, PyodideRuntimeDriver, } from "@secure-exec/python";
12
+ export { createBrowserDriver, createBrowserNetworkAdapter, createBrowserRuntimeDriverFactory, createOpfsFileSystem, } from "@secure-exec/browser";
13
+ export type { BrowserDriverOptions, BrowserRuntimeDriverFactoryOptions, BrowserRuntimeSystemOptions, } from "@secure-exec/browser";
14
+ export { createInMemoryFileSystem } from "./shared/in-memory-fs.js";
15
+ export { allowAll, allowAllChildProcess, allowAllEnv, allowAllFs, allowAllNetwork, } from "./shared/permissions.js";
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ // Re-export core runtime surface.
2
+ export { NodeRuntime } from "./runtime.js";
3
+ export { PythonRuntime } from "./python-runtime.js";
4
+ // Re-export Node driver factories.
5
+ export { createDefaultNetworkAdapter, createNodeDriver, createNodeRuntimeDriverFactory, NodeExecutionDriver, NodeFileSystem, } from "@secure-exec/node";
6
+ // Re-export Python runtime-driver factories.
7
+ export { createPyodideRuntimeDriverFactory, PyodideRuntimeDriver, } from "@secure-exec/python";
8
+ // Re-export browser driver factories.
9
+ export { createBrowserDriver, createBrowserNetworkAdapter, createBrowserRuntimeDriverFactory, createOpfsFileSystem, } from "@secure-exec/browser";
10
+ export { createInMemoryFileSystem } from "./shared/in-memory-fs.js";
11
+ export { allowAll, allowAllChildProcess, allowAllEnv, allowAllFs, allowAllNetwork, } from "./shared/permissions.js";
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-access.ts
4
+ function hasOwnGlobal(name) {
5
+ return Object.prototype.hasOwnProperty.call(globalThis, name);
6
+ }
7
+ function getGlobalValue(name) {
8
+ return Reflect.get(globalThis, name);
9
+ }
10
+
11
+ // isolate-runtime/src/common/global-exposure.ts
12
+ function defineRuntimeGlobalBinding(name, value, mutable) {
13
+ Object.defineProperty(globalThis, name, {
14
+ value,
15
+ writable: mutable,
16
+ configurable: mutable,
17
+ enumerable: true
18
+ });
19
+ }
20
+ function createRuntimeGlobalExposer(mutable) {
21
+ return (name, value) => {
22
+ defineRuntimeGlobalBinding(name, value, mutable);
23
+ };
24
+ }
25
+ function getRuntimeExposeCustomGlobal() {
26
+ if (typeof globalThis.__runtimeExposeCustomGlobal === "function") {
27
+ return globalThis.__runtimeExposeCustomGlobal;
28
+ }
29
+ return createRuntimeGlobalExposer(false);
30
+ }
31
+ function getRuntimeExposeMutableGlobal() {
32
+ if (typeof globalThis.__runtimeExposeMutableGlobal === "function") {
33
+ return globalThis.__runtimeExposeMutableGlobal;
34
+ }
35
+ return createRuntimeGlobalExposer(true);
36
+ }
37
+
38
+ // isolate-runtime/src/inject/apply-custom-global-policy.ts
39
+ var __runtimeExposeCustomGlobal = getRuntimeExposeCustomGlobal();
40
+ var __runtimeExposeMutableGlobal = getRuntimeExposeMutableGlobal();
41
+ var __globalPolicy = globalThis.__runtimeCustomGlobalPolicy ?? {};
42
+ var __hardenedGlobals = Array.isArray(__globalPolicy.hardenedGlobals) ? __globalPolicy.hardenedGlobals : [];
43
+ var __mutableGlobals = Array.isArray(__globalPolicy.mutableGlobals) ? __globalPolicy.mutableGlobals : [];
44
+ for (const globalName of __hardenedGlobals) {
45
+ if (hasOwnGlobal(globalName)) {
46
+ __runtimeExposeCustomGlobal(globalName, getGlobalValue(globalName));
47
+ }
48
+ }
49
+ for (const globalName of __mutableGlobals) {
50
+ if (hasOwnGlobal(globalName)) {
51
+ __runtimeExposeMutableGlobal(globalName, getGlobalValue(globalName));
52
+ }
53
+ }
54
+ })();
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-access.ts
4
+ function setGlobalValue(name, value) {
5
+ Reflect.set(globalThis, name, value);
6
+ }
7
+
8
+ // isolate-runtime/src/inject/apply-timing-mitigation-freeze.ts
9
+ var __timingConfig = globalThis.__runtimeTimingMitigationConfig ?? {};
10
+ var __frozenTimeMs = typeof __timingConfig.frozenTimeMs === "number" && Number.isFinite(__timingConfig.frozenTimeMs) ? __timingConfig.frozenTimeMs : Date.now();
11
+ var __frozenDateNow = () => __frozenTimeMs;
12
+ try {
13
+ Object.defineProperty(Date, "now", {
14
+ value: __frozenDateNow,
15
+ configurable: true,
16
+ writable: true
17
+ });
18
+ } catch {
19
+ Date.now = __frozenDateNow;
20
+ }
21
+ var __frozenPerformanceNow = () => 0;
22
+ var __performance = globalThis.performance;
23
+ if (typeof __performance !== "undefined" && __performance !== null) {
24
+ try {
25
+ Object.defineProperty(__performance, "now", {
26
+ value: __frozenPerformanceNow,
27
+ configurable: true,
28
+ writable: true
29
+ });
30
+ } catch {
31
+ try {
32
+ Object.assign(__performance, { now: __frozenPerformanceNow });
33
+ } catch {
34
+ }
35
+ }
36
+ } else {
37
+ setGlobalValue("performance", {
38
+ now: __frozenPerformanceNow
39
+ });
40
+ }
41
+ if (!Reflect.deleteProperty(globalThis, "SharedArrayBuffer")) {
42
+ setGlobalValue("SharedArrayBuffer", void 0);
43
+ }
44
+ })();
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-access.ts
4
+ function setGlobalValue(name, value) {
5
+ Reflect.set(globalThis, name, value);
6
+ }
7
+
8
+ // isolate-runtime/src/inject/apply-timing-mitigation-off.ts
9
+ if (typeof globalThis.performance === "undefined" || globalThis.performance === null) {
10
+ setGlobalValue("performance", {
11
+ now: () => Date.now()
12
+ });
13
+ }
14
+ })();
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-exposure.ts
4
+ function defineRuntimeGlobalBinding(name, value, mutable) {
5
+ Object.defineProperty(globalThis, name, {
6
+ value,
7
+ writable: mutable,
8
+ configurable: mutable,
9
+ enumerable: true
10
+ });
11
+ }
12
+ function createRuntimeGlobalExposer(mutable) {
13
+ return (name, value) => {
14
+ defineRuntimeGlobalBinding(name, value, mutable);
15
+ };
16
+ }
17
+ function getRuntimeExposeCustomGlobal() {
18
+ if (typeof globalThis.__runtimeExposeCustomGlobal === "function") {
19
+ return globalThis.__runtimeExposeCustomGlobal;
20
+ }
21
+ return createRuntimeGlobalExposer(false);
22
+ }
23
+
24
+ // isolate-runtime/src/inject/bridge-attach.ts
25
+ var __runtimeExposeCustomGlobal = getRuntimeExposeCustomGlobal();
26
+ if (typeof globalThis.bridge !== "undefined") {
27
+ __runtimeExposeCustomGlobal("bridge", globalThis.bridge);
28
+ }
29
+ })();
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-exposure.ts
4
+ function defineRuntimeGlobalBinding(name, value, mutable) {
5
+ Object.defineProperty(globalThis, name, {
6
+ value,
7
+ writable: mutable,
8
+ configurable: mutable,
9
+ enumerable: true
10
+ });
11
+ }
12
+ function createRuntimeGlobalExposer(mutable) {
13
+ return (name, value) => {
14
+ defineRuntimeGlobalBinding(name, value, mutable);
15
+ };
16
+ }
17
+ function getRuntimeExposeMutableGlobal() {
18
+ if (typeof globalThis.__runtimeExposeMutableGlobal === "function") {
19
+ return globalThis.__runtimeExposeMutableGlobal;
20
+ }
21
+ return createRuntimeGlobalExposer(true);
22
+ }
23
+
24
+ // isolate-runtime/src/inject/bridge-initial-globals.ts
25
+ var __runtimeExposeMutableGlobal = getRuntimeExposeMutableGlobal();
26
+ var __bridgeSetupConfig = globalThis.__runtimeBridgeSetupConfig ?? {};
27
+ var __initialCwd = typeof __bridgeSetupConfig.initialCwd === "string" ? __bridgeSetupConfig.initialCwd : "/";
28
+ var __jsonPayloadLimitBytes = typeof __bridgeSetupConfig.jsonPayloadLimitBytes === "number" && Number.isFinite(__bridgeSetupConfig.jsonPayloadLimitBytes) ? Math.max(0, Math.floor(__bridgeSetupConfig.jsonPayloadLimitBytes)) : 4 * 1024 * 1024;
29
+ var __payloadLimitErrorCode = typeof __bridgeSetupConfig.payloadLimitErrorCode === "string" && __bridgeSetupConfig.payloadLimitErrorCode.length > 0 ? __bridgeSetupConfig.payloadLimitErrorCode : "ERR_SANDBOX_PAYLOAD_TOO_LARGE";
30
+ __runtimeExposeMutableGlobal("_moduleCache", {});
31
+ globalThis._moduleCache = globalThis._moduleCache ?? {};
32
+ var __moduleCache = globalThis._moduleCache;
33
+ if (__moduleCache) {
34
+ __moduleCache["v8"] = {
35
+ getHeapStatistics: function() {
36
+ return {
37
+ total_heap_size: 67108864,
38
+ total_heap_size_executable: 1048576,
39
+ total_physical_size: 67108864,
40
+ total_available_size: 67108864,
41
+ used_heap_size: 52428800,
42
+ heap_size_limit: 134217728,
43
+ malloced_memory: 8192,
44
+ peak_malloced_memory: 16384,
45
+ does_zap_garbage: 0,
46
+ number_of_native_contexts: 1,
47
+ number_of_detached_contexts: 0,
48
+ external_memory: 0
49
+ };
50
+ },
51
+ getHeapSpaceStatistics: function() {
52
+ return [];
53
+ },
54
+ getHeapCodeStatistics: function() {
55
+ return {};
56
+ },
57
+ setFlagsFromString: function() {
58
+ },
59
+ serialize: function(value) {
60
+ return Buffer.from(JSON.stringify(value));
61
+ },
62
+ deserialize: function(buffer) {
63
+ const text = buffer.toString();
64
+ if (Buffer.byteLength(text, "utf8") > __jsonPayloadLimitBytes) {
65
+ throw new Error(
66
+ __payloadLimitErrorCode + ": v8.deserialize exceeds " + String(__jsonPayloadLimitBytes) + " bytes"
67
+ );
68
+ }
69
+ return JSON.parse(text);
70
+ },
71
+ cachedDataVersionTag: function() {
72
+ return 0;
73
+ }
74
+ };
75
+ }
76
+ __runtimeExposeMutableGlobal("_pendingModules", {});
77
+ __runtimeExposeMutableGlobal("_currentModule", { dirname: __initialCwd });
78
+ })();
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/inject/eval-script-result.ts
4
+ var __runtimeIndirectEval = globalThis.eval;
5
+ globalThis.__scriptResult__ = __runtimeIndirectEval(
6
+ String(globalThis.__runtimeExecCode)
7
+ );
8
+ })();
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-exposure.ts
4
+ function defineRuntimeGlobalBinding(name, value, mutable) {
5
+ Object.defineProperty(globalThis, name, {
6
+ value,
7
+ writable: mutable,
8
+ configurable: mutable,
9
+ enumerable: true
10
+ });
11
+ }
12
+ function createRuntimeGlobalExposer(mutable) {
13
+ return (name, value) => {
14
+ defineRuntimeGlobalBinding(name, value, mutable);
15
+ };
16
+ }
17
+ function ensureRuntimeExposureHelpers() {
18
+ if (typeof globalThis.__runtimeExposeCustomGlobal !== "function") {
19
+ defineRuntimeGlobalBinding(
20
+ "__runtimeExposeCustomGlobal",
21
+ createRuntimeGlobalExposer(false),
22
+ false
23
+ );
24
+ }
25
+ if (typeof globalThis.__runtimeExposeMutableGlobal !== "function") {
26
+ defineRuntimeGlobalBinding(
27
+ "__runtimeExposeMutableGlobal",
28
+ createRuntimeGlobalExposer(true),
29
+ false
30
+ );
31
+ }
32
+ }
33
+
34
+ // isolate-runtime/src/inject/global-exposure-helpers.ts
35
+ ensureRuntimeExposureHelpers();
36
+ })();
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/common/global-exposure.ts
4
+ function defineRuntimeGlobalBinding(name, value, mutable) {
5
+ Object.defineProperty(globalThis, name, {
6
+ value,
7
+ writable: mutable,
8
+ configurable: mutable,
9
+ enumerable: true
10
+ });
11
+ }
12
+ function createRuntimeGlobalExposer(mutable) {
13
+ return (name, value) => {
14
+ defineRuntimeGlobalBinding(name, value, mutable);
15
+ };
16
+ }
17
+ function getRuntimeExposeMutableGlobal() {
18
+ if (typeof globalThis.__runtimeExposeMutableGlobal === "function") {
19
+ return globalThis.__runtimeExposeMutableGlobal;
20
+ }
21
+ return createRuntimeGlobalExposer(true);
22
+ }
23
+
24
+ // isolate-runtime/src/inject/init-commonjs-module-globals.ts
25
+ var __runtimeExposeMutableGlobal = getRuntimeExposeMutableGlobal();
26
+ __runtimeExposeMutableGlobal("module", { exports: {} });
27
+ __runtimeExposeMutableGlobal("exports", globalThis.module.exports);
28
+ })();
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/inject/override-process-cwd.ts
4
+ var __cwd = globalThis.__runtimeProcessCwdOverride;
5
+ if (typeof __cwd === "string") {
6
+ process.cwd = () => __cwd;
7
+ }
8
+ })();
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ (() => {
3
+ // isolate-runtime/src/inject/override-process-env.ts
4
+ var __envPatch = globalThis.__runtimeProcessEnvOverride;
5
+ if (__envPatch && typeof __envPatch === "object") {
6
+ Object.assign(process.env, __envPatch);
7
+ }
8
+ })();