@secure-exec/core 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 (81) 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 +90 -0
  6. package/dist/bridge/child-process.js +606 -0
  7. package/dist/bridge/fs.d.ts +281 -0
  8. package/dist/bridge/fs.js +2151 -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 +75 -0
  12. package/dist/bridge/module.js +308 -0
  13. package/dist/bridge/network.d.ts +249 -0
  14. package/dist/bridge/network.js +1416 -0
  15. package/dist/bridge/os.d.ts +13 -0
  16. package/dist/bridge/os.js +256 -0
  17. package/dist/bridge/polyfills.d.ts +2 -0
  18. package/dist/bridge/polyfills.js +11 -0
  19. package/dist/bridge/process.d.ts +86 -0
  20. package/dist/bridge/process.js +938 -0
  21. package/dist/bridge-setup.d.ts +6 -0
  22. package/dist/bridge-setup.js +9 -0
  23. package/dist/bridge.js +11538 -0
  24. package/dist/esm-compiler.d.ts +14 -0
  25. package/dist/esm-compiler.js +68 -0
  26. package/dist/fs-helpers.d.ts +23 -0
  27. package/dist/fs-helpers.js +41 -0
  28. package/dist/generated/isolate-runtime.d.ts +19 -0
  29. package/dist/generated/isolate-runtime.js +21 -0
  30. package/dist/generated/polyfills.d.ts +82 -0
  31. package/dist/generated/polyfills.js +82 -0
  32. package/dist/index.d.ts +30 -0
  33. package/dist/index.js +25 -0
  34. package/dist/isolate-runtime/apply-custom-global-policy.js +54 -0
  35. package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +44 -0
  36. package/dist/isolate-runtime/apply-timing-mitigation-off.js +14 -0
  37. package/dist/isolate-runtime/bridge-attach.js +29 -0
  38. package/dist/isolate-runtime/bridge-initial-globals.js +246 -0
  39. package/dist/isolate-runtime/eval-script-result.js +8 -0
  40. package/dist/isolate-runtime/global-exposure-helpers.js +36 -0
  41. package/dist/isolate-runtime/init-commonjs-module-globals.js +28 -0
  42. package/dist/isolate-runtime/override-process-cwd.js +8 -0
  43. package/dist/isolate-runtime/override-process-env.js +8 -0
  44. package/dist/isolate-runtime/require-setup.js +650 -0
  45. package/dist/isolate-runtime/set-commonjs-file-globals.js +36 -0
  46. package/dist/isolate-runtime/set-stdin-data.js +10 -0
  47. package/dist/isolate-runtime/setup-dynamic-import.js +64 -0
  48. package/dist/isolate-runtime/setup-fs-facade.js +48 -0
  49. package/dist/module-resolver.d.ts +25 -0
  50. package/dist/module-resolver.js +264 -0
  51. package/dist/package-bundler.d.ts +36 -0
  52. package/dist/package-bundler.js +497 -0
  53. package/dist/python-runtime.d.ts +16 -0
  54. package/dist/python-runtime.js +45 -0
  55. package/dist/runtime-driver.d.ts +62 -0
  56. package/dist/runtime-driver.js +1 -0
  57. package/dist/runtime.d.ts +31 -0
  58. package/dist/runtime.js +69 -0
  59. package/dist/shared/api-types.d.ts +71 -0
  60. package/dist/shared/api-types.js +1 -0
  61. package/dist/shared/bridge-contract.d.ts +302 -0
  62. package/dist/shared/bridge-contract.js +82 -0
  63. package/dist/shared/console-formatter.d.ts +22 -0
  64. package/dist/shared/console-formatter.js +157 -0
  65. package/dist/shared/constants.d.ts +3 -0
  66. package/dist/shared/constants.js +3 -0
  67. package/dist/shared/errors.d.ts +16 -0
  68. package/dist/shared/errors.js +21 -0
  69. package/dist/shared/esm-utils.d.ts +28 -0
  70. package/dist/shared/esm-utils.js +97 -0
  71. package/dist/shared/global-exposure.d.ts +38 -0
  72. package/dist/shared/global-exposure.js +406 -0
  73. package/dist/shared/in-memory-fs.d.ts +42 -0
  74. package/dist/shared/in-memory-fs.js +341 -0
  75. package/dist/shared/permissions.d.ts +38 -0
  76. package/dist/shared/permissions.js +283 -0
  77. package/dist/shared/require-setup.d.ts +6 -0
  78. package/dist/shared/require-setup.js +9 -0
  79. package/dist/types.d.ts +206 -0
  80. package/dist/types.js +1 -0
  81. package/package.json +107 -0
@@ -0,0 +1,13 @@
1
+ import type * as nodeOs from "os";
2
+ export interface OSConfig {
3
+ platform?: string;
4
+ arch?: string;
5
+ type?: string;
6
+ release?: string;
7
+ version?: string;
8
+ homedir?: string;
9
+ tmpdir?: string;
10
+ hostname?: string;
11
+ }
12
+ declare const os: typeof nodeOs;
13
+ export default os;
@@ -0,0 +1,256 @@
1
+ // OS module polyfill for isolated-vm
2
+ // Provides Node.js os module emulation for sandbox compatibility
3
+ import { exposeCustomGlobal } from "../shared/global-exposure.js";
4
+ // Get config with defaults
5
+ const config = {
6
+ platform: (typeof _osConfig !== "undefined" && _osConfig.platform) || "linux",
7
+ arch: (typeof _osConfig !== "undefined" && _osConfig.arch) || "x64",
8
+ type: (typeof _osConfig !== "undefined" && _osConfig.type) || "Linux",
9
+ release: (typeof _osConfig !== "undefined" && _osConfig.release) || "5.15.0",
10
+ version: (typeof _osConfig !== "undefined" && _osConfig.version) || "#1 SMP",
11
+ homedir: (typeof _osConfig !== "undefined" && _osConfig.homedir) || "/root",
12
+ tmpdir: (typeof _osConfig !== "undefined" && _osConfig.tmpdir) || "/tmp",
13
+ hostname: (typeof _osConfig !== "undefined" && _osConfig.hostname) || "sandbox",
14
+ };
15
+ // Signal constants (subset — sandbox only emulates Linux signals)
16
+ const signals = {
17
+ SIGHUP: 1,
18
+ SIGINT: 2,
19
+ SIGQUIT: 3,
20
+ SIGILL: 4,
21
+ SIGTRAP: 5,
22
+ SIGABRT: 6,
23
+ SIGIOT: 6,
24
+ SIGBUS: 7,
25
+ SIGFPE: 8,
26
+ SIGKILL: 9,
27
+ SIGUSR1: 10,
28
+ SIGSEGV: 11,
29
+ SIGUSR2: 12,
30
+ SIGPIPE: 13,
31
+ SIGALRM: 14,
32
+ SIGTERM: 15,
33
+ SIGSTKFLT: 16,
34
+ SIGCHLD: 17,
35
+ SIGCONT: 18,
36
+ SIGSTOP: 19,
37
+ SIGTSTP: 20,
38
+ SIGTTIN: 21,
39
+ SIGTTOU: 22,
40
+ SIGURG: 23,
41
+ SIGXCPU: 24,
42
+ SIGXFSZ: 25,
43
+ SIGVTALRM: 26,
44
+ SIGPROF: 27,
45
+ SIGWINCH: 28,
46
+ SIGIO: 29,
47
+ SIGPOLL: 29,
48
+ SIGPWR: 30,
49
+ SIGSYS: 31,
50
+ };
51
+ // Errno constants
52
+ const errno = {
53
+ E2BIG: 7,
54
+ EACCES: 13,
55
+ EADDRINUSE: 98,
56
+ EADDRNOTAVAIL: 99,
57
+ EAFNOSUPPORT: 97,
58
+ EAGAIN: 11,
59
+ EALREADY: 114,
60
+ EBADF: 9,
61
+ EBADMSG: 74,
62
+ EBUSY: 16,
63
+ ECANCELED: 125,
64
+ ECHILD: 10,
65
+ ECONNABORTED: 103,
66
+ ECONNREFUSED: 111,
67
+ ECONNRESET: 104,
68
+ EDEADLK: 35,
69
+ EDESTADDRREQ: 89,
70
+ EDOM: 33,
71
+ EDQUOT: 122,
72
+ EEXIST: 17,
73
+ EFAULT: 14,
74
+ EFBIG: 27,
75
+ EHOSTUNREACH: 113,
76
+ EIDRM: 43,
77
+ EILSEQ: 84,
78
+ EINPROGRESS: 115,
79
+ EINTR: 4,
80
+ EINVAL: 22,
81
+ EIO: 5,
82
+ EISCONN: 106,
83
+ EISDIR: 21,
84
+ ELOOP: 40,
85
+ EMFILE: 24,
86
+ EMLINK: 31,
87
+ EMSGSIZE: 90,
88
+ EMULTIHOP: 72,
89
+ ENAMETOOLONG: 36,
90
+ ENETDOWN: 100,
91
+ ENETRESET: 102,
92
+ ENETUNREACH: 101,
93
+ ENFILE: 23,
94
+ ENOBUFS: 105,
95
+ ENODATA: 61,
96
+ ENODEV: 19,
97
+ ENOENT: 2,
98
+ ENOEXEC: 8,
99
+ ENOLCK: 37,
100
+ ENOLINK: 67,
101
+ ENOMEM: 12,
102
+ ENOMSG: 42,
103
+ ENOPROTOOPT: 92,
104
+ ENOSPC: 28,
105
+ ENOSR: 63,
106
+ ENOSTR: 60,
107
+ ENOSYS: 38,
108
+ ENOTCONN: 107,
109
+ ENOTDIR: 20,
110
+ ENOTEMPTY: 39,
111
+ ENOTSOCK: 88,
112
+ ENOTSUP: 95,
113
+ ENOTTY: 25,
114
+ ENXIO: 6,
115
+ EOPNOTSUPP: 95,
116
+ EOVERFLOW: 75,
117
+ EPERM: 1,
118
+ EPIPE: 32,
119
+ EPROTO: 71,
120
+ EPROTONOSUPPORT: 93,
121
+ EPROTOTYPE: 91,
122
+ ERANGE: 34,
123
+ EROFS: 30,
124
+ ESPIPE: 29,
125
+ ESRCH: 3,
126
+ ESTALE: 116,
127
+ ETIME: 62,
128
+ ETIMEDOUT: 110,
129
+ ETXTBSY: 26,
130
+ EWOULDBLOCK: 11,
131
+ EXDEV: 18,
132
+ };
133
+ // Priority constants
134
+ const priority = {
135
+ PRIORITY_LOW: 19,
136
+ PRIORITY_BELOW_NORMAL: 10,
137
+ PRIORITY_NORMAL: 0,
138
+ PRIORITY_ABOVE_NORMAL: -7,
139
+ PRIORITY_HIGH: -14,
140
+ PRIORITY_HIGHEST: -20,
141
+ };
142
+ // OS module implementation (polyfill — partial coverage of Node.js os types)
143
+ const os = {
144
+ // Platform information
145
+ platform() {
146
+ return config.platform;
147
+ },
148
+ arch() {
149
+ return config.arch;
150
+ },
151
+ type() {
152
+ return config.type;
153
+ },
154
+ release() {
155
+ return config.release;
156
+ },
157
+ version() {
158
+ return config.version;
159
+ },
160
+ // Directory information
161
+ homedir() {
162
+ return config.homedir;
163
+ },
164
+ tmpdir() {
165
+ return config.tmpdir;
166
+ },
167
+ // System information
168
+ hostname() {
169
+ return config.hostname;
170
+ },
171
+ // User information
172
+ userInfo(_options) {
173
+ return {
174
+ username: "root",
175
+ uid: 0,
176
+ gid: 0,
177
+ shell: "/bin/bash",
178
+ homedir: config.homedir,
179
+ };
180
+ },
181
+ // CPU information
182
+ cpus() {
183
+ return [
184
+ {
185
+ model: "Virtual CPU",
186
+ speed: 2000,
187
+ times: {
188
+ user: 100000,
189
+ nice: 0,
190
+ sys: 50000,
191
+ idle: 800000,
192
+ irq: 0,
193
+ },
194
+ },
195
+ ];
196
+ },
197
+ // Memory information
198
+ totalmem() {
199
+ return 1073741824; // 1GB
200
+ },
201
+ freemem() {
202
+ return 536870912; // 512MB
203
+ },
204
+ // System load
205
+ loadavg() {
206
+ return [0.1, 0.1, 0.1];
207
+ },
208
+ // System uptime
209
+ uptime() {
210
+ return 3600; // 1 hour
211
+ },
212
+ // Network interfaces (empty - not supported in sandbox)
213
+ networkInterfaces() {
214
+ return {};
215
+ },
216
+ // System endianness
217
+ endianness() {
218
+ return "LE";
219
+ },
220
+ // Line endings
221
+ EOL: "\n",
222
+ // Dev null path
223
+ devNull: "/dev/null",
224
+ // Machine type
225
+ machine() {
226
+ return config.arch;
227
+ },
228
+ // Constants (partial — Linux subset, no Windows WSA* or RTLD_DEEPBIND)
229
+ constants: {
230
+ signals: signals,
231
+ errno: errno,
232
+ priority,
233
+ dlopen: {
234
+ RTLD_LAZY: 1,
235
+ RTLD_NOW: 2,
236
+ RTLD_GLOBAL: 256,
237
+ RTLD_LOCAL: 0,
238
+ },
239
+ UV_UDP_REUSEADDR: 4,
240
+ },
241
+ // Priority getters/setters (stubs)
242
+ getPriority(_pid) {
243
+ return 0;
244
+ },
245
+ setPriority(pid, priority) {
246
+ void pid;
247
+ void priority;
248
+ },
249
+ // Parallelism hint
250
+ availableParallelism() {
251
+ return 1;
252
+ },
253
+ };
254
+ // Expose to global for require() to use.
255
+ exposeCustomGlobal("_osModule", os);
256
+ export default os;
@@ -0,0 +1,2 @@
1
+ import { TextEncoder, TextDecoder } from "text-encoding-utf-8";
2
+ export { TextEncoder, TextDecoder };
@@ -0,0 +1,11 @@
1
+ // Early polyfills - this file must be imported FIRST before any other modules
2
+ // that might use TextEncoder/TextDecoder (like whatwg-url)
3
+ import { TextEncoder, TextDecoder } from "text-encoding-utf-8";
4
+ // Install on globalThis so other modules can use them
5
+ if (typeof globalThis.TextEncoder === "undefined") {
6
+ globalThis.TextEncoder = TextEncoder;
7
+ }
8
+ if (typeof globalThis.TextDecoder === "undefined") {
9
+ globalThis.TextDecoder = TextDecoder;
10
+ }
11
+ export { TextEncoder, TextDecoder };
@@ -0,0 +1,86 @@
1
+ import type * as nodeProcess from "process";
2
+ import { TextEncoder, TextDecoder } from "./polyfills.js";
3
+ /**
4
+ * Process configuration injected by the host before the bridge bundle loads.
5
+ * Values default to sensible Linux/x64 stubs when unset.
6
+ */
7
+ export interface ProcessConfig {
8
+ platform?: string;
9
+ arch?: string;
10
+ version?: string;
11
+ cwd?: string;
12
+ env?: Record<string, string>;
13
+ argv?: string[];
14
+ execPath?: string;
15
+ pid?: number;
16
+ ppid?: number;
17
+ uid?: number;
18
+ gid?: number;
19
+ stdin?: string;
20
+ timingMitigation?: "off" | "freeze";
21
+ frozenTimeMs?: number;
22
+ }
23
+ /**
24
+ * Thrown by `process.exit()` to unwind the sandbox call stack. The host
25
+ * catches this to extract the exit code without killing the isolate.
26
+ */
27
+ export declare class ProcessExitError extends Error {
28
+ code: number;
29
+ constructor(code: number);
30
+ }
31
+ declare const _default: typeof nodeProcess;
32
+ export default _default;
33
+ /**
34
+ * Timer handle that mimics Node.js Timeout (ref/unref/Symbol.toPrimitive).
35
+ * Timers with delay > 0 use the host's `_scheduleTimer` bridge to sleep
36
+ * without blocking the isolate's event loop.
37
+ */
38
+ declare class TimerHandle {
39
+ _id: number;
40
+ _destroyed: boolean;
41
+ constructor(id: number);
42
+ ref(): this;
43
+ unref(): this;
44
+ hasRef(): boolean;
45
+ refresh(): this;
46
+ [Symbol.toPrimitive](): number;
47
+ }
48
+ export declare function setTimeout(callback: (...args: unknown[]) => void, delay?: number, ...args: unknown[]): TimerHandle;
49
+ export declare function clearTimeout(timer: TimerHandle | number | undefined): void;
50
+ export declare function setInterval(callback: (...args: unknown[]) => void, delay?: number, ...args: unknown[]): TimerHandle;
51
+ export declare function clearInterval(timer: TimerHandle | number | undefined): void;
52
+ export declare function setImmediate(callback: (...args: unknown[]) => void, ...args: unknown[]): TimerHandle;
53
+ export declare function clearImmediate(id: TimerHandle | number | undefined): void;
54
+ export declare const URL: {
55
+ new (url: string | URL, base?: string | URL): URL;
56
+ prototype: URL;
57
+ canParse(url: string | URL, base?: string | URL): boolean;
58
+ createObjectURL(obj: Blob | MediaSource): string;
59
+ parse(url: string | URL, base?: string | URL): URL | null;
60
+ revokeObjectURL(url: string): void;
61
+ };
62
+ export declare const URLSearchParams: {
63
+ new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
64
+ prototype: URLSearchParams;
65
+ };
66
+ export { TextEncoder, TextDecoder };
67
+ export declare const Buffer: BufferConstructor;
68
+ /**
69
+ * Crypto polyfill that delegates to the host for entropy. `getRandomValues`
70
+ * calls the host's `_cryptoRandomFill` bridge to get cryptographically secure
71
+ * random bytes. Subtle crypto operations are unsupported.
72
+ */
73
+ export declare const cryptoPolyfill: {
74
+ getRandomValues<T extends ArrayBufferView>(array: T): T;
75
+ randomUUID(): string;
76
+ subtle: {
77
+ digest(): Promise<ArrayBuffer>;
78
+ encrypt(): Promise<ArrayBuffer>;
79
+ decrypt(): Promise<ArrayBuffer>;
80
+ };
81
+ };
82
+ /**
83
+ * Install all process/timer/URL/Buffer/crypto polyfills onto `globalThis`.
84
+ * Called once during bridge initialization before user code runs.
85
+ */
86
+ export declare function setupGlobals(): void;