@molecule/api-code-sandbox-e2b 1.1.0 → 1.2.0
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 +232 -22
- package/dist/index.d.ts +72 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +72 -5
- package/dist/provider.d.ts +135 -2
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +550 -25
- package/dist/types.d.ts +143 -15
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/provider.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
|
-
import type { EgressVerdict, Sandbox, SandboxConfig, SandboxDescriptor, SandboxProvider } from '@molecule/api-code-sandbox';
|
|
11
|
+
import type { CommitTemplateOptions, EgressVerdict, ListTemplatesOptions, ListVolumesOptions, Sandbox, SandboxConfig, SandboxDescriptor, SandboxProvider, SandboxTemplate, VolumeInfo } from '@molecule/api-code-sandbox';
|
|
12
12
|
import type { E2BConfig, E2BSandboxClientLike } from './types.js';
|
|
13
13
|
/**
|
|
14
14
|
* E2B implementation of {@link SandboxProvider}.
|
|
@@ -50,7 +50,17 @@ export declare class E2BSandboxProvider implements SandboxProvider {
|
|
|
50
50
|
* `processesPreserved: true`. A filesystem-only snapshot would cold-boot
|
|
51
51
|
* instead, leaving a sandbox that is running with every dev server dead.
|
|
52
52
|
*
|
|
53
|
-
*
|
|
53
|
+
* `config.volumeName` mounts a persistent volume, which E2B can only attach at
|
|
54
|
+
* CREATE time — there is no attach-to-a-running-sandbox call — so a sandbox
|
|
55
|
+
* claimed from a pre-warmed pool can never be given one afterwards. A mount
|
|
56
|
+
* path is REQUIRED alongside it: E2B mounts shadow whatever the image had at
|
|
57
|
+
* that path, and this bond's superset template keeps a 2.4 GB
|
|
58
|
+
* `/workspace/node_modules` there, so defaulting to the workspace root would
|
|
59
|
+
* hide the entire dependency fleet behind an empty volume and boot a project
|
|
60
|
+
* that cannot resolve a single import.
|
|
61
|
+
*
|
|
62
|
+
* @param config - Project id, env, optional per-boot templateId + labels, and
|
|
63
|
+
* an optional `volumeName` + `volumeMountPath` pair.
|
|
54
64
|
* @returns A live sandbox handle.
|
|
55
65
|
*/
|
|
56
66
|
create(config: SandboxConfig): Promise<Sandbox>;
|
|
@@ -91,6 +101,129 @@ export declare class E2BSandboxProvider implements SandboxProvider {
|
|
|
91
101
|
* @param id - The sandbox id.
|
|
92
102
|
*/
|
|
93
103
|
destroy(id: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Every sandbox that currently EXISTS, running or paused.
|
|
106
|
+
*
|
|
107
|
+
* The basis for both "is this volume attached?" and "is this snapshot in use?".
|
|
108
|
+
* Paused sandboxes are included deliberately — a paused sandbox still owns its
|
|
109
|
+
* volume and still boots from its template, and treating it as absent is how a
|
|
110
|
+
* reclamation sweep deletes the storage under a hibernated project.
|
|
111
|
+
*
|
|
112
|
+
* @returns The raw listing rows.
|
|
113
|
+
*/
|
|
114
|
+
private liveSandboxes;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve a volume by the caller's name.
|
|
117
|
+
*
|
|
118
|
+
* @param name - The volume name.
|
|
119
|
+
* @returns The volume, or `null` when the account has no volume by that name.
|
|
120
|
+
*/
|
|
121
|
+
private findVolume;
|
|
122
|
+
/**
|
|
123
|
+
* Create a named volume, idempotently.
|
|
124
|
+
*
|
|
125
|
+
* Callers create the volume on EVERY boot (they cannot know whether a previous
|
|
126
|
+
* sandbox already made it), so an existing volume is a success and must not be
|
|
127
|
+
* re-created — re-creating would either fail the boot or, worse, hand back an
|
|
128
|
+
* empty volume in place of the user's files.
|
|
129
|
+
*
|
|
130
|
+
* Volumes are a private beta on E2B: an account without them answers
|
|
131
|
+
* `403 use of volumes is not enabled`, which surfaces here as a throw rather
|
|
132
|
+
* than a silent no-op, because a caller that believes it has a durable volume
|
|
133
|
+
* and does not is exactly the failure this method exists to prevent.
|
|
134
|
+
*
|
|
135
|
+
* @param name - The volume name.
|
|
136
|
+
*/
|
|
137
|
+
createVolume(name: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Remove a named volume. Removing one that does not exist is a success.
|
|
140
|
+
*
|
|
141
|
+
* @param name - The volume name.
|
|
142
|
+
*/
|
|
143
|
+
removeVolume(name: string): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Whether a named volume exists.
|
|
146
|
+
*
|
|
147
|
+
* THROWS when it cannot look. A control plane asks this to decide whether a
|
|
148
|
+
* project's files survived losing its sandbox, and answering `false` for a
|
|
149
|
+
* failed lookup tells it the user's work is gone — the same "could not look
|
|
150
|
+
* delivered as looked-and-empty" confusion that `get()` returning `null` used
|
|
151
|
+
* to be.
|
|
152
|
+
*
|
|
153
|
+
* @param name - The volume name.
|
|
154
|
+
* @returns `true` when the account has a volume by that name.
|
|
155
|
+
*/
|
|
156
|
+
volumeExists(name: string): Promise<boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* Enumerate volumes, reporting which ones a sandbox currently holds.
|
|
159
|
+
*
|
|
160
|
+
* `attached` is OBSERVED from the sandbox listing (running and paused alike),
|
|
161
|
+
* not assumed, because the only reason to enumerate volumes is to delete the
|
|
162
|
+
* unattached ones. E2B reports neither a creation time nor a size for a volume,
|
|
163
|
+
* so both are `null` rather than invented.
|
|
164
|
+
*
|
|
165
|
+
* @param options - Narrowing by name prefix and attachment.
|
|
166
|
+
* @returns Every matching volume.
|
|
167
|
+
*/
|
|
168
|
+
listVolumes(options?: ListVolumesOptions): Promise<VolumeInfo[]>;
|
|
169
|
+
/**
|
|
170
|
+
* Capture a sandbox as a reusable template, using E2B snapshots.
|
|
171
|
+
*
|
|
172
|
+
* A snapshot is a persistent image of the sandbox's filesystem AND memory that
|
|
173
|
+
* outlives the sandbox itself — verified against production: a sandbox was
|
|
174
|
+
* killed and a new one created from its snapshot came up with the same files.
|
|
175
|
+
* Re-committing the same `templateId` assigns a new build to the same snapshot
|
|
176
|
+
* rather than accumulating a second one, so a per-project restore point stays
|
|
177
|
+
* one resource no matter how often it is refreshed.
|
|
178
|
+
*
|
|
179
|
+
* Snapshotting BRIEFLY PAUSES the sandbox and drops its open connections
|
|
180
|
+
* (PTYs, command streams, websockets). Take one when the project is going
|
|
181
|
+
* quiet, not underneath a user's terminal.
|
|
182
|
+
*
|
|
183
|
+
* `capturePaths` inside a MOUNTED VOLUME are refused rather than silently
|
|
184
|
+
* omitted: E2B's snapshot images the sandbox's own disk, and a volume is
|
|
185
|
+
* storage attached from outside it. Committing anyway would produce a template
|
|
186
|
+
* that boots perfectly into a workspace missing exactly the files it was asked
|
|
187
|
+
* to preserve.
|
|
188
|
+
*
|
|
189
|
+
* @param options - The sandbox, the caller's template id, optional capture paths and label.
|
|
190
|
+
* @returns The template as it now exists.
|
|
191
|
+
*/
|
|
192
|
+
commitTemplate(options: CommitTemplateOptions): Promise<SandboxTemplate>;
|
|
193
|
+
/**
|
|
194
|
+
* Look up one template by the caller's identifier.
|
|
195
|
+
*
|
|
196
|
+
* `null` means E2B has no snapshot by that name. A failed lookup throws: a
|
|
197
|
+
* caller reads `null` as "there is no restore point" and scaffolds a fresh
|
|
198
|
+
* project over the user's, so a transient API error must never wear that shape.
|
|
199
|
+
*
|
|
200
|
+
* @param templateId - The caller's identifier.
|
|
201
|
+
* @returns The template, or `null` when it does not exist.
|
|
202
|
+
*/
|
|
203
|
+
getTemplate(templateId: string): Promise<SandboxTemplate | null>;
|
|
204
|
+
/**
|
|
205
|
+
* Enumerate templates so a caller can enforce its retention policy.
|
|
206
|
+
*
|
|
207
|
+
* Throws rather than answering `[]` when it cannot enumerate — an eviction
|
|
208
|
+
* loop that reads "nothing exists" from a failed listing stops evicting, and a
|
|
209
|
+
* reconciler that reads it stops reconciling.
|
|
210
|
+
*
|
|
211
|
+
* @param options - Narrowing by id prefix.
|
|
212
|
+
* @returns Every matching template.
|
|
213
|
+
*/
|
|
214
|
+
listTemplates(options?: ListTemplatesOptions): Promise<SandboxTemplate[]>;
|
|
215
|
+
/**
|
|
216
|
+
* Delete a template. Deleting one that does not exist is a success.
|
|
217
|
+
*
|
|
218
|
+
* Refuses when a sandbox still boots from it, by CHECKING the sandbox listing
|
|
219
|
+
* rather than trusting the caller. E2B enforces the same rule server-side (a
|
|
220
|
+
* `400` naming the template), which is left to surface as a throw — two
|
|
221
|
+
* independent refusals for an operation whose failure mode is destroying a
|
|
222
|
+
* running project.
|
|
223
|
+
*
|
|
224
|
+
* @param templateId - The caller's identifier.
|
|
225
|
+
*/
|
|
226
|
+
removeTemplate(templateId: string): Promise<void>;
|
|
94
227
|
/**
|
|
95
228
|
* PROVE egress is deny-by-default by OBSERVING it on a throwaway sandbox.
|
|
96
229
|
*
|
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,
|
|
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;AAkvBnB;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,IAAI,SAAQ;IAErB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0D;IACjF,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAsB;IAEtD;;;;;OAKG;gBACS,MAAM,GAAE,SAAc,EAAE,cAAc,CAAC,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