@iso4/sandbox 0.8.0 → 0.8.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.
- package/README.md +72 -13
- package/dist/index.d.mts +63 -48
- package/dist/index.mjs +622 -726
- package/dist/names-BY-6pKkh.mjs +199 -0
- package/dist/utils.d.mts +45 -0
- package/dist/utils.mjs +2 -0
- package/package.json +9 -5
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
//#region src/names.ts
|
|
2
|
+
/**
|
|
3
|
+
* Name rules behind the public `@iso4/sandbox/utils` entry. Imports nothing,
|
|
4
|
+
* so loading it never touches the client or the native binary.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Every global name a fresh sandbox defines: the JS built-ins of the bundled
|
|
8
|
+
* V8 plus the runtime's own (`console`, `waitUntil`, timers, web classes).
|
|
9
|
+
* A host global under one of these names replaces the built-in, unless the
|
|
10
|
+
* runtime reserves the name. Names the grammar
|
|
11
|
+
* forbids outright are in {@link RESERVED_WORDS}.
|
|
12
|
+
*/
|
|
13
|
+
const SANDBOX_GLOBALS = new Set([
|
|
14
|
+
"AggregateError",
|
|
15
|
+
"Array",
|
|
16
|
+
"ArrayBuffer",
|
|
17
|
+
"AsyncDisposableStack",
|
|
18
|
+
"Atomics",
|
|
19
|
+
"BigInt",
|
|
20
|
+
"BigInt64Array",
|
|
21
|
+
"BigUint64Array",
|
|
22
|
+
"Boolean",
|
|
23
|
+
"DataView",
|
|
24
|
+
"Date",
|
|
25
|
+
"DisposableStack",
|
|
26
|
+
"Error",
|
|
27
|
+
"EvalError",
|
|
28
|
+
"FinalizationRegistry",
|
|
29
|
+
"Float16Array",
|
|
30
|
+
"Float32Array",
|
|
31
|
+
"Float64Array",
|
|
32
|
+
"Function",
|
|
33
|
+
"Headers",
|
|
34
|
+
"Infinity",
|
|
35
|
+
"Int16Array",
|
|
36
|
+
"Int32Array",
|
|
37
|
+
"Int8Array",
|
|
38
|
+
"Intl",
|
|
39
|
+
"Iterator",
|
|
40
|
+
"JSON",
|
|
41
|
+
"Map",
|
|
42
|
+
"Math",
|
|
43
|
+
"NaN",
|
|
44
|
+
"Number",
|
|
45
|
+
"Object",
|
|
46
|
+
"Promise",
|
|
47
|
+
"Proxy",
|
|
48
|
+
"RangeError",
|
|
49
|
+
"ReferenceError",
|
|
50
|
+
"Reflect",
|
|
51
|
+
"RegExp",
|
|
52
|
+
"Request",
|
|
53
|
+
"Response",
|
|
54
|
+
"Set",
|
|
55
|
+
"String",
|
|
56
|
+
"SuppressedError",
|
|
57
|
+
"Symbol",
|
|
58
|
+
"SyntaxError",
|
|
59
|
+
"Temporal",
|
|
60
|
+
"TextDecoder",
|
|
61
|
+
"TextEncoder",
|
|
62
|
+
"TypeError",
|
|
63
|
+
"URIError",
|
|
64
|
+
"URL",
|
|
65
|
+
"URLSearchParams",
|
|
66
|
+
"Uint16Array",
|
|
67
|
+
"Uint32Array",
|
|
68
|
+
"Uint8Array",
|
|
69
|
+
"Uint8ClampedArray",
|
|
70
|
+
"WeakMap",
|
|
71
|
+
"WeakRef",
|
|
72
|
+
"WeakSet",
|
|
73
|
+
"clearTimeout",
|
|
74
|
+
"console",
|
|
75
|
+
"decodeURI",
|
|
76
|
+
"decodeURIComponent",
|
|
77
|
+
"encodeURI",
|
|
78
|
+
"encodeURIComponent",
|
|
79
|
+
"escape",
|
|
80
|
+
"eval",
|
|
81
|
+
"globalThis",
|
|
82
|
+
"isFinite",
|
|
83
|
+
"isNaN",
|
|
84
|
+
"parseFloat",
|
|
85
|
+
"parseInt",
|
|
86
|
+
"setTimeout",
|
|
87
|
+
"undefined",
|
|
88
|
+
"unescape",
|
|
89
|
+
"waitUntil"
|
|
90
|
+
]);
|
|
91
|
+
/**
|
|
92
|
+
* Names that cannot be a binding in module source. A host-module key may not
|
|
93
|
+
* use one, except `default`.
|
|
94
|
+
*/
|
|
95
|
+
const RESERVED_WORDS = new Set([
|
|
96
|
+
"break",
|
|
97
|
+
"case",
|
|
98
|
+
"catch",
|
|
99
|
+
"class",
|
|
100
|
+
"const",
|
|
101
|
+
"continue",
|
|
102
|
+
"debugger",
|
|
103
|
+
"default",
|
|
104
|
+
"delete",
|
|
105
|
+
"do",
|
|
106
|
+
"else",
|
|
107
|
+
"export",
|
|
108
|
+
"extends",
|
|
109
|
+
"finally",
|
|
110
|
+
"for",
|
|
111
|
+
"function",
|
|
112
|
+
"if",
|
|
113
|
+
"import",
|
|
114
|
+
"in",
|
|
115
|
+
"instanceof",
|
|
116
|
+
"new",
|
|
117
|
+
"return",
|
|
118
|
+
"super",
|
|
119
|
+
"switch",
|
|
120
|
+
"this",
|
|
121
|
+
"throw",
|
|
122
|
+
"try",
|
|
123
|
+
"typeof",
|
|
124
|
+
"var",
|
|
125
|
+
"void",
|
|
126
|
+
"while",
|
|
127
|
+
"with",
|
|
128
|
+
"yield",
|
|
129
|
+
"let",
|
|
130
|
+
"static",
|
|
131
|
+
"enum",
|
|
132
|
+
"await",
|
|
133
|
+
"implements",
|
|
134
|
+
"package",
|
|
135
|
+
"protected",
|
|
136
|
+
"interface",
|
|
137
|
+
"private",
|
|
138
|
+
"public",
|
|
139
|
+
"null",
|
|
140
|
+
"true",
|
|
141
|
+
"false",
|
|
142
|
+
"eval",
|
|
143
|
+
"arguments"
|
|
144
|
+
]);
|
|
145
|
+
/**
|
|
146
|
+
* A JavaScript identifier name, Unicode included: ID_Start/ID_Continue plus
|
|
147
|
+
* `$`, `_`, ZWNJ and ZWJ. A name that matches and is not in
|
|
148
|
+
* {@link RESERVED_WORDS} can be a binding in module source, so it is a valid
|
|
149
|
+
* host-module export name.
|
|
150
|
+
*/
|
|
151
|
+
const IDENTIFIER_NAME = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u;
|
|
152
|
+
/**
|
|
153
|
+
* Names the runtime owns; a host global under one fails with
|
|
154
|
+
* `ERR_RESERVED_NAME`. The client checks them before sending and the runtime
|
|
155
|
+
* again; this mirrors `RESERVED_GLOBAL_NAMES` in `v8.rs`. `utils.test.ts`
|
|
156
|
+
* checks every name here and every {@link SANDBOX_GLOBALS} name against the
|
|
157
|
+
* runtime.
|
|
158
|
+
*/
|
|
159
|
+
const RUNTIME_OWNED_GLOBALS = new Set([
|
|
160
|
+
"console",
|
|
161
|
+
"waitUntil",
|
|
162
|
+
"setTimeout",
|
|
163
|
+
"clearTimeout",
|
|
164
|
+
"Headers",
|
|
165
|
+
"Request",
|
|
166
|
+
"Response",
|
|
167
|
+
"TextEncoder",
|
|
168
|
+
"TextDecoder",
|
|
169
|
+
"URL",
|
|
170
|
+
"URLSearchParams",
|
|
171
|
+
"NaN",
|
|
172
|
+
"undefined",
|
|
173
|
+
"Infinity",
|
|
174
|
+
"__proto__"
|
|
175
|
+
]);
|
|
176
|
+
/**
|
|
177
|
+
* Whether `name` can be a key of a host-module object in `imports`: an
|
|
178
|
+
* identifier per {@link IDENTIFIER_NAME} that is not in
|
|
179
|
+
* {@link RESERVED_WORDS}, or `default`, which maps to the module's default
|
|
180
|
+
* export. `default` cannot be written as `export const default` in generated source.
|
|
181
|
+
* @param name candidate name
|
|
182
|
+
*/
|
|
183
|
+
function isValidExportName(name) {
|
|
184
|
+
return name === "default" || IDENTIFIER_NAME.test(name) && !RESERVED_WORDS.has(name);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Whether `prepare()` and `run()` accept `name` as a host global name: any
|
|
188
|
+
* well-formed string that is not a runtime-owned name such as `console` or
|
|
189
|
+
* `Response`. A name that is not an identifier is reachable only as
|
|
190
|
+
* `globalThis[name]`. Names starting with `__iso4_` are iso4's internal
|
|
191
|
+
* namespace (the dispatcher, shim handlers): a host global there may be
|
|
192
|
+
* silently overwritten or dropped, and this does not flag it.
|
|
193
|
+
* @param name candidate host global name
|
|
194
|
+
*/
|
|
195
|
+
function isValidGlobalName(name) {
|
|
196
|
+
return name.isWellFormed() && !RUNTIME_OWNED_GLOBALS.has(name);
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
export { isValidExportName as a, SANDBOX_GLOBALS as i, RESERVED_WORDS as n, isValidGlobalName as o, RUNTIME_OWNED_GLOBALS as r, IDENTIFIER_NAME as t };
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/names.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Name rules behind the public `@iso4/sandbox/utils` entry. Imports nothing,
|
|
4
|
+
* so loading it never touches the client or the native binary.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Every global name a fresh sandbox defines: the JS built-ins of the bundled
|
|
8
|
+
* V8 plus the runtime's own (`console`, `waitUntil`, timers, web classes).
|
|
9
|
+
* A host global under one of these names replaces the built-in, unless the
|
|
10
|
+
* runtime reserves the name. Names the grammar
|
|
11
|
+
* forbids outright are in {@link RESERVED_WORDS}.
|
|
12
|
+
*/
|
|
13
|
+
declare const SANDBOX_GLOBALS: ReadonlySet<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Names that cannot be a binding in module source. A host-module key may not
|
|
16
|
+
* use one, except `default`.
|
|
17
|
+
*/
|
|
18
|
+
declare const RESERVED_WORDS: ReadonlySet<string>;
|
|
19
|
+
/**
|
|
20
|
+
* A JavaScript identifier name, Unicode included: ID_Start/ID_Continue plus
|
|
21
|
+
* `$`, `_`, ZWNJ and ZWJ. A name that matches and is not in
|
|
22
|
+
* {@link RESERVED_WORDS} can be a binding in module source, so it is a valid
|
|
23
|
+
* host-module export name.
|
|
24
|
+
*/
|
|
25
|
+
declare const IDENTIFIER_NAME: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* Whether `name` can be a key of a host-module object in `imports`: an
|
|
28
|
+
* identifier per {@link IDENTIFIER_NAME} that is not in
|
|
29
|
+
* {@link RESERVED_WORDS}, or `default`, which maps to the module's default
|
|
30
|
+
* export. `default` cannot be written as `export const default` in generated source.
|
|
31
|
+
* @param name candidate name
|
|
32
|
+
*/
|
|
33
|
+
declare function isValidExportName(name: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether `prepare()` and `run()` accept `name` as a host global name: any
|
|
36
|
+
* well-formed string that is not a runtime-owned name such as `console` or
|
|
37
|
+
* `Response`. A name that is not an identifier is reachable only as
|
|
38
|
+
* `globalThis[name]`. Names starting with `__iso4_` are iso4's internal
|
|
39
|
+
* namespace (the dispatcher, shim handlers): a host global there may be
|
|
40
|
+
* silently overwritten or dropped, and this does not flag it.
|
|
41
|
+
* @param name candidate host global name
|
|
42
|
+
*/
|
|
43
|
+
declare function isValidGlobalName(name: string): boolean;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { IDENTIFIER_NAME, RESERVED_WORDS, SANDBOX_GLOBALS, isValidExportName, isValidGlobalName };
|
package/dist/utils.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iso4/sandbox",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fast, sandboxed V8 isolate runtime for agent-generated JavaScript. Two-process architecture for crash isolation.",
|
|
6
6
|
"keywords": [
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/index.d.mts",
|
|
29
29
|
"import": "./dist/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./utils": {
|
|
32
|
+
"types": "./dist/utils.d.mts",
|
|
33
|
+
"import": "./dist/utils.mjs"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"main": "./dist/index.mjs",
|
|
@@ -49,10 +53,10 @@
|
|
|
49
53
|
"vitest": "^4.1.5"
|
|
50
54
|
},
|
|
51
55
|
"optionalDependencies": {
|
|
52
|
-
"@iso4/v8-darwin-arm64": "^0.8.
|
|
53
|
-
"@iso4/v8-darwin-x64": "^0.8.
|
|
54
|
-
"@iso4/v8-linux-arm64-gnu": "^0.8.
|
|
55
|
-
"@iso4/v8-linux-x64-gnu": "^0.8.
|
|
56
|
+
"@iso4/v8-darwin-arm64": "^0.8.1",
|
|
57
|
+
"@iso4/v8-darwin-x64": "^0.8.1",
|
|
58
|
+
"@iso4/v8-linux-arm64-gnu": "^0.8.1",
|
|
59
|
+
"@iso4/v8-linux-x64-gnu": "^0.8.1"
|
|
56
60
|
},
|
|
57
61
|
"engines": {
|
|
58
62
|
"node": ">=24.0.0"
|