@molecule/api-code-sandbox-e2b 1.2.3 → 1.2.5
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/LICENSE +111 -24
- package/README.md +50 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/provider.d.ts +41 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +94 -17
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
Apache License
|
|
2
3
|
Version 2.0, January 2004
|
|
3
4
|
http://www.apache.org/licenses/
|
|
@@ -34,21 +35,33 @@
|
|
|
34
35
|
|
|
35
36
|
"Work" shall mean the work of authorship, whether in Source or
|
|
36
37
|
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
38
40
|
|
|
39
41
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
42
|
form, that is based on (or derived from) the Work and for which the
|
|
41
43
|
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
-
represent, as a whole, an original work of authorship.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
49
62
|
|
|
50
63
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
-
on behalf of whom a Contribution has been received by
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
52
65
|
subsequently incorporated within the Work.
|
|
53
66
|
|
|
54
67
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
@@ -61,8 +74,18 @@
|
|
|
61
74
|
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
75
|
this License, each Contributor hereby grants to You a perpetual,
|
|
63
76
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
-
|
|
65
|
-
and otherwise transfer the Work
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
66
89
|
|
|
67
90
|
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
91
|
Work or Derivative Works thereof in any medium, with or without
|
|
@@ -84,23 +107,87 @@
|
|
|
84
107
|
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
108
|
distribution, then any Derivative Works that You distribute must
|
|
86
109
|
include a readable copy of the attribution notices contained
|
|
87
|
-
within such NOTICE file
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
90
138
|
|
|
91
139
|
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
-
names, trademarks, service marks, or product names of the Licensor
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
93
143
|
|
|
94
144
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
-
agreed to in writing, Licensor provides the Work
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
104
191
|
|
|
105
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
193
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-10-04T09:45:27.540Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-code-sandbox-e2b
|
|
@@ -376,6 +376,21 @@ interface E2BVolumeLike {
|
|
|
376
376
|
}
|
|
377
377
|
```
|
|
378
378
|
|
|
379
|
+
#### `EgressProbeCodes`
|
|
380
|
+
|
|
381
|
+
The three curl `%{http_code}` outputs an egress probe observes.
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
interface EgressProbeCodes {
|
|
385
|
+
/** The allow-listed control host — must answer for the probe to mean anything. */
|
|
386
|
+
allowed: string
|
|
387
|
+
/** A non-allow-listed hostname. */
|
|
388
|
+
deniedHost: string
|
|
389
|
+
/** A raw IP outside the allowlist. */
|
|
390
|
+
deniedIp: string
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
379
394
|
### Classes
|
|
380
395
|
|
|
381
396
|
#### `E2BSandboxProvider`
|
|
@@ -391,6 +406,27 @@ in prod, which is the correct safe default until egress observation is proven
|
|
|
391
406
|
|
|
392
407
|
### Functions
|
|
393
408
|
|
|
409
|
+
#### `classifyEgressProbe(codes)`
|
|
410
|
+
|
|
411
|
+
Turn the probe's curl codes into a verdict.
|
|
412
|
+
|
|
413
|
+
- `open` only when a denied probe answered a real HTTP status — reachable
|
|
414
|
+
egress was OBSERVED;
|
|
415
|
+
- `inconclusive` whenever the allow-listed control host did not answer — a
|
|
416
|
+
probe sandbox with no network at all blocks everything, which says nothing
|
|
417
|
+
about the policy (2026-10-04: `host=000, rawIP=000, allowed=000` was read
|
|
418
|
+
as open and production refused to boot);
|
|
419
|
+
- `filtered` only when the control host answered AND both denied probes were
|
|
420
|
+
blocked (`000` / empty).
|
|
421
|
+
|
|
422
|
+
```typescript
|
|
423
|
+
function classifyEgressProbe(codes: EgressProbeCodes): EgressVerdict
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
- `codes` — The observed curl codes.
|
|
427
|
+
|
|
428
|
+
**Returns:** The verdict.
|
|
429
|
+
|
|
394
430
|
#### `createProvider(config, clientOverride)`
|
|
395
431
|
|
|
396
432
|
Create an E2B provider with the given configuration.
|
|
@@ -470,6 +506,12 @@ failure to run that probe is `inconclusive` — never `filtered`, because "I
|
|
|
470
506
|
could not look" must not reach a control plane as "I looked, and it is safe"
|
|
471
507
|
(Rule 18: never trade cost for security).
|
|
472
508
|
|
|
509
|
+
**A probe that sees NO network is `inconclusive`, not `open`.** When the
|
|
510
|
+
allow-listed control host does not answer either, the probe sandbox itself has
|
|
511
|
+
no network and observed nothing about the policy. `open` requires a denied
|
|
512
|
+
probe to answer a real HTTP status. (A no-network probe once read as open and
|
|
513
|
+
kept a control plane from booting.)
|
|
514
|
+
|
|
473
515
|
**E2B pauses, it does not stop.** `sleep()`/`stop()` both map to E2B pause
|
|
474
516
|
(FS + memory snapshot); `wake()`/`start()` reconnect by id. `hibernate()`/
|
|
475
517
|
`resume()` report `processesPreserved: true` because the memory snapshot
|
|
@@ -561,5 +603,12 @@ default is `onTimeout: 'kill'`, so a sandbox nothing touched for its lifetime
|
|
|
561
603
|
would be destroyed with its files. This bond creates every sandbox with
|
|
562
604
|
`lifecycle: { onTimeout: { action: 'pause', keepMemory: true } }`; the memory
|
|
563
605
|
snapshot is what lets `resume()` truthfully report `processesPreserved: true`.
|
|
606
|
+
The one exception is the throwaway `verifyEgress()` probe, created with
|
|
607
|
+
`lifecycle: { onTimeout: 'kill' }`: a pause writes a full snapshot to the
|
|
608
|
+
host's disk, and nobody resumes a probe. Every pause and every
|
|
609
|
+
`commitTemplate()` is a new snapshot build on a self-hosted box's disk, so
|
|
610
|
+
a pause-on-timeout sandbox you do not need back is disk you pay for — keep a
|
|
611
|
+
sandbox you intend to keep warm alive with `keepAlive(ms)`, and destroy one
|
|
612
|
+
you are done with rather than letting it time out.
|
|
564
613
|
Extending the deadline is `keepAlive(ms)` — call it from a real activity
|
|
565
614
|
signal (an open editor's heartbeat), never as a side effect of polling.
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
* could not look" must not reach a control plane as "I looked, and it is safe"
|
|
48
48
|
* (Rule 18: never trade cost for security).
|
|
49
49
|
*
|
|
50
|
+
* **A probe that sees NO network is `inconclusive`, not `open`.** When the
|
|
51
|
+
* allow-listed control host does not answer either, the probe sandbox itself has
|
|
52
|
+
* no network and observed nothing about the policy. `open` requires a denied
|
|
53
|
+
* probe to answer a real HTTP status. (A no-network probe once read as open and
|
|
54
|
+
* kept a control plane from booting.)
|
|
55
|
+
*
|
|
50
56
|
* **E2B pauses, it does not stop.** `sleep()`/`stop()` both map to E2B pause
|
|
51
57
|
* (FS + memory snapshot); `wake()`/`start()` reconnect by id. `hibernate()`/
|
|
52
58
|
* `resume()` report `processesPreserved: true` because the memory snapshot
|
|
@@ -138,6 +144,13 @@
|
|
|
138
144
|
* would be destroyed with its files. This bond creates every sandbox with
|
|
139
145
|
* `lifecycle: { onTimeout: { action: 'pause', keepMemory: true } }`; the memory
|
|
140
146
|
* snapshot is what lets `resume()` truthfully report `processesPreserved: true`.
|
|
147
|
+
* The one exception is the throwaway `verifyEgress()` probe, created with
|
|
148
|
+
* `lifecycle: { onTimeout: 'kill' }`: a pause writes a full snapshot to the
|
|
149
|
+
* host's disk, and nobody resumes a probe. Every pause and every
|
|
150
|
+
* `commitTemplate()` is a new snapshot build on a self-hosted box's disk, so
|
|
151
|
+
* a pause-on-timeout sandbox you do not need back is disk you pay for — keep a
|
|
152
|
+
* sandbox you intend to keep warm alive with `keepAlive(ms)`, and destroy one
|
|
153
|
+
* you are done with rather than letting it time out.
|
|
141
154
|
* Extending the deadline is `keepAlive(ms)` — call it from a real activity
|
|
142
155
|
* signal (an open editor's heartbeat), never as a side effect of polling.
|
|
143
156
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6JG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,12 @@
|
|
|
47
47
|
* could not look" must not reach a control plane as "I looked, and it is safe"
|
|
48
48
|
* (Rule 18: never trade cost for security).
|
|
49
49
|
*
|
|
50
|
+
* **A probe that sees NO network is `inconclusive`, not `open`.** When the
|
|
51
|
+
* allow-listed control host does not answer either, the probe sandbox itself has
|
|
52
|
+
* no network and observed nothing about the policy. `open` requires a denied
|
|
53
|
+
* probe to answer a real HTTP status. (A no-network probe once read as open and
|
|
54
|
+
* kept a control plane from booting.)
|
|
55
|
+
*
|
|
50
56
|
* **E2B pauses, it does not stop.** `sleep()`/`stop()` both map to E2B pause
|
|
51
57
|
* (FS + memory snapshot); `wake()`/`start()` reconnect by id. `hibernate()`/
|
|
52
58
|
* `resume()` report `processesPreserved: true` because the memory snapshot
|
|
@@ -138,6 +144,13 @@
|
|
|
138
144
|
* would be destroyed with its files. This bond creates every sandbox with
|
|
139
145
|
* `lifecycle: { onTimeout: { action: 'pause', keepMemory: true } }`; the memory
|
|
140
146
|
* snapshot is what lets `resume()` truthfully report `processesPreserved: true`.
|
|
147
|
+
* The one exception is the throwaway `verifyEgress()` probe, created with
|
|
148
|
+
* `lifecycle: { onTimeout: 'kill' }`: a pause writes a full snapshot to the
|
|
149
|
+
* host's disk, and nobody resumes a probe. Every pause and every
|
|
150
|
+
* `commitTemplate()` is a new snapshot build on a self-hosted box's disk, so
|
|
151
|
+
* a pause-on-timeout sandbox you do not need back is disk you pay for — keep a
|
|
152
|
+
* sandbox you intend to keep warm alive with `keepAlive(ms)`, and destroy one
|
|
153
|
+
* you are done with rather than letting it time out.
|
|
141
154
|
* Extending the deadline is `keepAlive(ms)` — call it from a real activity
|
|
142
155
|
* signal (an open editor's heartbeat), never as a side effect of polling.
|
|
143
156
|
*
|
package/dist/provider.d.ts
CHANGED
|
@@ -64,6 +64,22 @@ export declare class E2BSandboxProvider implements SandboxProvider {
|
|
|
64
64
|
* @returns A live sandbox handle.
|
|
65
65
|
*/
|
|
66
66
|
create(config: SandboxConfig): Promise<Sandbox>;
|
|
67
|
+
/**
|
|
68
|
+
* {@link create} with the sandbox's timeout action chosen by the caller.
|
|
69
|
+
*
|
|
70
|
+
* `'pause'` is E2B's `lifecycle: { onTimeout: { action: 'pause', keepMemory:
|
|
71
|
+
* true } }` — the data-safe default for anything that may hold a project
|
|
72
|
+
* (see {@link create}). `'kill'` is `lifecycle: { onTimeout: 'kill' }` — for a
|
|
73
|
+
* THROWAWAY sandbox this bond destroys itself (the egress probe): pausing one
|
|
74
|
+
* at its deadline would write a full memory + filesystem snapshot to the
|
|
75
|
+
* host's disk for a sandbox nobody will ever resume. E2B cannot change a
|
|
76
|
+
* sandbox's `onTimeout` after create, so the choice is made here, once.
|
|
77
|
+
*
|
|
78
|
+
* @param config - As for {@link create}.
|
|
79
|
+
* @param onTimeout - What E2B does at the sandbox's deadline.
|
|
80
|
+
* @returns A live sandbox handle.
|
|
81
|
+
*/
|
|
82
|
+
private createSandbox;
|
|
67
83
|
/**
|
|
68
84
|
* Resolve an existing sandbox by id.
|
|
69
85
|
*
|
|
@@ -252,6 +268,31 @@ export declare class E2BSandboxProvider implements SandboxProvider {
|
|
|
252
268
|
*/
|
|
253
269
|
private probeEgress;
|
|
254
270
|
}
|
|
271
|
+
/** The three curl `%{http_code}` outputs an egress probe observes. */
|
|
272
|
+
export interface EgressProbeCodes {
|
|
273
|
+
/** The allow-listed control host — must answer for the probe to mean anything. */
|
|
274
|
+
allowed: string;
|
|
275
|
+
/** A non-allow-listed hostname. */
|
|
276
|
+
deniedHost: string;
|
|
277
|
+
/** A raw IP outside the allowlist. */
|
|
278
|
+
deniedIp: string;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Turn the probe's curl codes into a verdict.
|
|
282
|
+
*
|
|
283
|
+
* - `open` only when a denied probe answered a real HTTP status — reachable
|
|
284
|
+
* egress was OBSERVED;
|
|
285
|
+
* - `inconclusive` whenever the allow-listed control host did not answer — a
|
|
286
|
+
* probe sandbox with no network at all blocks everything, which says nothing
|
|
287
|
+
* about the policy (2026-10-04: `host=000, rawIP=000, allowed=000` was read
|
|
288
|
+
* as open and production refused to boot);
|
|
289
|
+
* - `filtered` only when the control host answered AND both denied probes were
|
|
290
|
+
* blocked (`000` / empty).
|
|
291
|
+
*
|
|
292
|
+
* @param codes - The observed curl codes.
|
|
293
|
+
* @returns The verdict.
|
|
294
|
+
*/
|
|
295
|
+
export declare function classifyEgressProbe(codes: EgressProbeCodes): EgressVerdict;
|
|
255
296
|
/**
|
|
256
297
|
* Create an E2B provider with the given configuration.
|
|
257
298
|
*
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,qBAAqB,EAErB,aAAa,EAKb,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EAGf,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAGV,SAAS,EACT,oBAAoB,EAMrB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"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"}
|
package/dist/provider.js
CHANGED
|
@@ -551,6 +551,25 @@ class E2BSandbox {
|
|
|
551
551
|
async writeFile(path, content) {
|
|
552
552
|
await this.sbx.files.write(path, content);
|
|
553
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Read a file's exact bytes through envd's file API (never command stdout,
|
|
556
|
+
* which envd truncates for large outputs).
|
|
557
|
+
*
|
|
558
|
+
* @param path - Absolute path inside the sandbox.
|
|
559
|
+
* @returns The file's bytes.
|
|
560
|
+
*/
|
|
561
|
+
async readFileBytes(path) {
|
|
562
|
+
return this.sbx.files.read(path, { format: 'bytes' });
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Write exact bytes to a file through envd's file API, replacing it.
|
|
566
|
+
*
|
|
567
|
+
* @param path - Absolute path inside the sandbox.
|
|
568
|
+
* @param data - The bytes to write.
|
|
569
|
+
*/
|
|
570
|
+
async writeFileBytes(path, data) {
|
|
571
|
+
await this.sbx.files.write(path, data);
|
|
572
|
+
}
|
|
554
573
|
/**
|
|
555
574
|
* List a directory. Throws when the path does not exist (an empty array
|
|
556
575
|
* means "exists and is empty", never "missing").
|
|
@@ -777,6 +796,24 @@ export class E2BSandboxProvider {
|
|
|
777
796
|
* @returns A live sandbox handle.
|
|
778
797
|
*/
|
|
779
798
|
async create(config) {
|
|
799
|
+
return this.createSandbox(config, 'pause');
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* {@link create} with the sandbox's timeout action chosen by the caller.
|
|
803
|
+
*
|
|
804
|
+
* `'pause'` is E2B's `lifecycle: { onTimeout: { action: 'pause', keepMemory:
|
|
805
|
+
* true } }` — the data-safe default for anything that may hold a project
|
|
806
|
+
* (see {@link create}). `'kill'` is `lifecycle: { onTimeout: 'kill' }` — for a
|
|
807
|
+
* THROWAWAY sandbox this bond destroys itself (the egress probe): pausing one
|
|
808
|
+
* at its deadline would write a full memory + filesystem snapshot to the
|
|
809
|
+
* host's disk for a sandbox nobody will ever resume. E2B cannot change a
|
|
810
|
+
* sandbox's `onTimeout` after create, so the choice is made here, once.
|
|
811
|
+
*
|
|
812
|
+
* @param config - As for {@link create}.
|
|
813
|
+
* @param onTimeout - What E2B does at the sandbox's deadline.
|
|
814
|
+
* @returns A live sandbox handle.
|
|
815
|
+
*/
|
|
816
|
+
async createSandbox(config, onTimeout) {
|
|
780
817
|
const client = await this.client();
|
|
781
818
|
const templateId = config.templateId ?? this.config.templateId;
|
|
782
819
|
if (config.volumeName && !config.volumeMountPath) {
|
|
@@ -789,7 +826,9 @@ export class E2BSandboxProvider {
|
|
|
789
826
|
timeoutMs: this.config.defaultTimeoutMs,
|
|
790
827
|
envs: config.env ?? {},
|
|
791
828
|
metadata: { projectId: config.projectId, ...(config.labels ?? {}) },
|
|
792
|
-
lifecycle:
|
|
829
|
+
lifecycle: onTimeout === 'kill'
|
|
830
|
+
? { onTimeout: 'kill' }
|
|
831
|
+
: { onTimeout: { action: 'pause', keepMemory: true } },
|
|
793
832
|
...(config.volumeName
|
|
794
833
|
? { volumeMounts: { [config.volumeMountPath]: config.volumeName } }
|
|
795
834
|
: {}),
|
|
@@ -1193,7 +1232,9 @@ export class E2BSandboxProvider {
|
|
|
1193
1232
|
async verifyEgress() {
|
|
1194
1233
|
let handle;
|
|
1195
1234
|
try {
|
|
1196
|
-
|
|
1235
|
+
// Kill, not pause, at its deadline: a leaked probe must not leave a
|
|
1236
|
+
// snapshot on the host's disk (see createSandbox).
|
|
1237
|
+
handle = await this.createSandbox({ projectId: `egress-probe-${Date.now()}`, env: {} }, 'kill');
|
|
1197
1238
|
}
|
|
1198
1239
|
catch (error) {
|
|
1199
1240
|
return {
|
|
@@ -1205,8 +1246,7 @@ export class E2BSandboxProvider {
|
|
|
1205
1246
|
const verdict = await this.probeEgress(handle);
|
|
1206
1247
|
// The probe sandbox is destroyed on EVERY path. A failed destroy is retried,
|
|
1207
1248
|
// and one that still fails is reported in the verdict's detail: the sandbox
|
|
1208
|
-
//
|
|
1209
|
-
// storage forever.
|
|
1249
|
+
// is killed at its own deadline, but until then it runs metered.
|
|
1210
1250
|
const leaked = await this.destroyProbe(handle.id);
|
|
1211
1251
|
return leaked ? { ...verdict, detail: `${verdict.detail} ${leaked}` } : verdict;
|
|
1212
1252
|
}
|
|
@@ -1242,24 +1282,17 @@ export class E2BSandboxProvider {
|
|
|
1242
1282
|
EGRESS_PROBE_ALLOW,
|
|
1243
1283
|
`*.${EGRESS_PROBE_ALLOW.split('.').slice(-2).join('.')}`,
|
|
1244
1284
|
]);
|
|
1245
|
-
const code = async (host) => (await handle.exec(
|
|
1285
|
+
const code = async (host) => (await handle.exec(
|
|
1286
|
+
// No `|| echo 000`: exec RETURNS a non-zero exit as data, and curl
|
|
1287
|
+
// already prints `000` for "no response" — the fallback appended a
|
|
1288
|
+
// second one (`000000`).
|
|
1289
|
+
`curl -s -o /dev/null -m 8 -w '%{http_code}' https://${host}/`)).stdout.trim();
|
|
1246
1290
|
const [allowed, deniedHost, deniedIp] = await Promise.all([
|
|
1247
1291
|
code(EGRESS_PROBE_ALLOW),
|
|
1248
1292
|
code(EGRESS_PROBE_DENY),
|
|
1249
1293
|
code('1.1.1.1'),
|
|
1250
1294
|
]);
|
|
1251
|
-
|
|
1252
|
-
if (blocked(deniedHost) && blocked(deniedIp) && !blocked(allowed)) {
|
|
1253
|
-
return {
|
|
1254
|
-
state: 'filtered',
|
|
1255
|
-
detail: `deny-by-default verified: ${EGRESS_PROBE_ALLOW}=${allowed} reachable; ${EGRESS_PROBE_DENY}=${deniedHost} and raw IP=${deniedIp} blocked.`,
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
return {
|
|
1259
|
-
state: 'open',
|
|
1260
|
-
detail: `Non-allow-listed egress was reachable (host=${deniedHost}, rawIP=${deniedIp}, allowed=${allowed}).`,
|
|
1261
|
-
remediation: 'Ensure updateNetwork applies allowOut + denyOut:[0.0.0.0/0]; check the E2B account supports network policy.',
|
|
1262
|
-
};
|
|
1295
|
+
return classifyEgressProbe({ allowed, deniedHost, deniedIp });
|
|
1263
1296
|
}
|
|
1264
1297
|
catch (error) {
|
|
1265
1298
|
return {
|
|
@@ -1269,6 +1302,50 @@ export class E2BSandboxProvider {
|
|
|
1269
1302
|
}
|
|
1270
1303
|
}
|
|
1271
1304
|
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Turn the probe's curl codes into a verdict.
|
|
1307
|
+
*
|
|
1308
|
+
* - `open` only when a denied probe answered a real HTTP status — reachable
|
|
1309
|
+
* egress was OBSERVED;
|
|
1310
|
+
* - `inconclusive` whenever the allow-listed control host did not answer — a
|
|
1311
|
+
* probe sandbox with no network at all blocks everything, which says nothing
|
|
1312
|
+
* about the policy (2026-10-04: `host=000, rawIP=000, allowed=000` was read
|
|
1313
|
+
* as open and production refused to boot);
|
|
1314
|
+
* - `filtered` only when the control host answered AND both denied probes were
|
|
1315
|
+
* blocked (`000` / empty).
|
|
1316
|
+
*
|
|
1317
|
+
* @param codes - The observed curl codes.
|
|
1318
|
+
* @returns The verdict.
|
|
1319
|
+
*/
|
|
1320
|
+
export function classifyEgressProbe(codes) {
|
|
1321
|
+
const { allowed, deniedHost, deniedIp } = codes;
|
|
1322
|
+
const answered = (c) => /^[1-5]\d\d$/.test(c);
|
|
1323
|
+
const blocked = (c) => c === '' || /^0+$/.test(c);
|
|
1324
|
+
if (answered(deniedHost) || answered(deniedIp)) {
|
|
1325
|
+
return {
|
|
1326
|
+
state: 'open',
|
|
1327
|
+
detail: `Non-allow-listed egress was reachable (host=${deniedHost}, rawIP=${deniedIp}, allowed=${allowed}).`,
|
|
1328
|
+
remediation: 'Ensure updateNetwork applies allowOut + denyOut:[0.0.0.0/0]; check the E2B account supports network policy.',
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
if (!answered(allowed)) {
|
|
1332
|
+
return {
|
|
1333
|
+
state: 'inconclusive',
|
|
1334
|
+
detail: `probe sandbox had no network (allowed=${allowed}; host=${deniedHost}, rawIP=${deniedIp}).`,
|
|
1335
|
+
remediation: 'The allow-listed control host did not answer, so the probe observed nothing. Check the sandbox template / E2B networking.',
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
if (blocked(deniedHost) && blocked(deniedIp)) {
|
|
1339
|
+
return {
|
|
1340
|
+
state: 'filtered',
|
|
1341
|
+
detail: `deny-by-default verified: ${EGRESS_PROBE_ALLOW}=${allowed} reachable; ${EGRESS_PROBE_DENY}=${deniedHost} and raw IP=${deniedIp} blocked.`,
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
return {
|
|
1345
|
+
state: 'inconclusive',
|
|
1346
|
+
detail: `Egress probe output was unreadable (host=${deniedHost}, rawIP=${deniedIp}, allowed=${allowed}).`,
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1272
1349
|
/**
|
|
1273
1350
|
* Create an E2B provider with the given configuration.
|
|
1274
1351
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-code-sandbox-e2b",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "E2B (e2b.dev) code sandbox provider — Firecracker microVMs with golden templates, fork, and pause/resume",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@molecule/api-bond": "1.0.2",
|
|
33
|
-
"@molecule/api-code-sandbox": "1.
|
|
33
|
+
"@molecule/api-code-sandbox": "1.3.0",
|
|
34
34
|
"@types/node": "26.1.2",
|
|
35
35
|
"typescript": "6.0.3",
|
|
36
36
|
"vitest": "4.1.11"
|