@meistrari/sandbox-sdk 1.8.0 → 1.9.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 +24 -10
- package/dist/index.cjs +5 -1
- package/dist/index.d.cts +39 -13
- package/dist/index.d.mts +39 -13
- package/dist/index.d.ts +39 -13
- package/dist/index.mjs +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -216,7 +216,7 @@ await sandbox.kill()
|
|
|
216
216
|
### Selecting a Backend
|
|
217
217
|
|
|
218
218
|
```typescript
|
|
219
|
-
// `agent-sandbox`, `lambda-microvm` or `
|
|
219
|
+
// `agent-sandbox`, `lambda-microvm`, `e2b`, `e2b-cluster` or `cube`; omitting it uses the
|
|
220
220
|
// deployment's default. Naming one is a promise: the request is served by
|
|
221
221
|
// that backend or it fails.
|
|
222
222
|
const run = await client.createRunAndWait({
|
|
@@ -256,7 +256,7 @@ await sandbox.runCode('console.log("I am back!")')
|
|
|
256
256
|
|
|
257
257
|
### Direct Access
|
|
258
258
|
|
|
259
|
-
On a backend with direct access (`e2b`
|
|
259
|
+
On a backend with direct access (`e2b`, `e2b-cluster` and `cube`), the caller that created a
|
|
260
260
|
sandbox can talk to it without going through this API: commands, files, PTY
|
|
261
261
|
and WebSocket go straight to the backend's sandbox proxy. Creation, listing,
|
|
262
262
|
suspend, extend and delete still go through the API.
|
|
@@ -283,7 +283,7 @@ await sandbox.resume()
|
|
|
283
283
|
sandbox.access // filled in again, including tokens the backend only returns at creation
|
|
284
284
|
```
|
|
285
285
|
|
|
286
|
-
- **
|
|
286
|
+
- **The tokens are credentials.** Whoever holds them and reaches the proxy
|
|
287
287
|
drives the sandbox. Keep them out of logs, traces and error messages. The
|
|
288
288
|
`Sandbox` object keeps them in a private field, so `JSON.stringify(sandbox)`
|
|
289
289
|
and `console.log(sandbox)` do not print them; `sandbox.access` and the raw
|
|
@@ -291,13 +291,27 @@ sandbox.access // filled in again, including tokens the backend only returns at
|
|
|
291
291
|
- `sandbox.access` follows create, `getInfo()` and `resume()`. `extend()` and
|
|
292
292
|
`suspend()` answer no access and do not erase it. `listSandboxes()` never
|
|
293
293
|
carries it.
|
|
294
|
-
-
|
|
295
|
-
ports answer anyone who reaches the proxy.
|
|
294
|
+
- On `e2b`, without `privateTraffic` there is no `trafficAccessToken` and the
|
|
295
|
+
sandbox's ports answer anyone who reaches the proxy.
|
|
296
296
|
- `lambda-microvm` and `agent-sandbox` have no direct access: `access` is
|
|
297
297
|
`undefined`, and `privateTraffic: true` is refused with 409.
|
|
298
|
-
-
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
- `e2b-cluster` (the E2B runtime in our cluster) seals every sandbox:
|
|
299
|
+
`privateTraffic` is not needed, `privateTraffic: false` is ignored, and
|
|
300
|
+
`access` always carries both tokens and the proxy's `sandboxUrl`.
|
|
301
|
+
- `cube` (CubeSandbox) seals every sandbox too, with one token: there is no
|
|
302
|
+
`envdAccessToken`, and `trafficAccessToken` goes on every request, the ones
|
|
303
|
+
to the in-sandbox agent included. The address is always `sandboxUrl`.
|
|
304
|
+
- On `cube`, `sandboxTtlSeconds` and `extend()` count idleness, not lifetime:
|
|
305
|
+
every request the sandbox receives starts the count again and `expiresAt`
|
|
306
|
+
moves with it. `suspend()` takes the deadline away: the sandbox has no
|
|
307
|
+
`expiresAt`, `extend()` gives it none, and once it runs again it counts the
|
|
308
|
+
backend's default idle timeout (15 minutes unless the deployment sets
|
|
309
|
+
`CUBE_DEFAULT_TIMEOUT_SECONDS`), not what `sandboxTtlSeconds` or `extend()`
|
|
310
|
+
said.
|
|
311
|
+
- A backend that creates a sandbox that has to be sealed (asked for with
|
|
312
|
+
`privateTraffic`, or on `e2b-cluster` and `cube`) without a token that seals
|
|
313
|
+
it is a 502, and the sandbox is torn down: a sealed create never returns an
|
|
314
|
+
open sandbox. Do not retry it.
|
|
301
315
|
|
|
302
316
|
## API Reference
|
|
303
317
|
|
|
@@ -367,7 +381,7 @@ const client = sandbox({
|
|
|
367
381
|
```typescript
|
|
368
382
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled'
|
|
369
383
|
|
|
370
|
-
type SandboxRuntime = 'lambda-microvm'
|
|
384
|
+
type SandboxRuntime = 'lambda-microvm' | 'agent-sandbox' | 'e2b' | 'e2b-cluster' | 'cube'
|
|
371
385
|
|
|
372
386
|
interface CreateRunRequest {
|
|
373
387
|
code: string
|
|
@@ -434,7 +448,7 @@ and deleting one. Commands, files, runs, snapshot recipes and the snapshot
|
|
|
434
448
|
listing through the API still need the data token of the workspace.
|
|
435
449
|
|
|
436
450
|
That does not keep a service from running code. On a backend with direct
|
|
437
|
-
access (`e2b`), create, `connectToSandbox` and resume give the service the
|
|
451
|
+
access (`e2b`, `e2b-cluster` and `cube`), create, `connectToSandbox` and resume give the service the
|
|
438
452
|
sandbox's `access`, as they give the owner, and with it the service runs
|
|
439
453
|
commands, files and traffic against the sandbox directly: that is how
|
|
440
454
|
agent-api drives the data plane. A service token can run code in every
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const node_buffer = require('node:buffer');
|
|
4
4
|
const eventsourceParser = require('eventsource-parser');
|
|
5
5
|
|
|
6
|
-
const SANDBOX_RUNTIMES = ["lambda-microvm", "agent-sandbox", "e2b"];
|
|
6
|
+
const SANDBOX_RUNTIMES = ["lambda-microvm", "agent-sandbox", "e2b", "e2b-cluster", "cube"];
|
|
7
7
|
|
|
8
8
|
class FetchError extends Error {
|
|
9
9
|
constructor(message, url, method, status, response) {
|
|
@@ -219,6 +219,10 @@ class Sandbox {
|
|
|
219
219
|
this.remember(info);
|
|
220
220
|
return info;
|
|
221
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Gives the sandbox `ttlSeconds` from now; on `cube`, `ttlSeconds` of
|
|
224
|
+
* idleness, and nothing while the sandbox is suspended.
|
|
225
|
+
*/
|
|
222
226
|
async extend(ttlSeconds) {
|
|
223
227
|
const info = await this.client.extendSandbox(this.sandboxId, ttlSeconds);
|
|
224
228
|
this.remember(info);
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ interface SandboxConfig {
|
|
|
6
6
|
interface AuthStrategy {
|
|
7
7
|
getHeaders: () => Headers;
|
|
8
8
|
}
|
|
9
|
-
declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm", "agent-sandbox", "e2b"];
|
|
9
|
+
declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm", "agent-sandbox", "e2b", "e2b-cluster", "cube"];
|
|
10
10
|
type SandboxRuntime = (typeof SANDBOX_RUNTIMES)[number];
|
|
11
11
|
type SandboxState = 'pending' | 'running' | 'suspended' | 'terminated' | 'failed';
|
|
12
12
|
type SandboxOnTimeout = 'suspend' | 'terminate';
|
|
@@ -17,16 +17,21 @@ type SandboxOnTimeout = 'suspend' | 'terminate';
|
|
|
17
17
|
* `envdAccessToken` and `trafficAccessToken` are **credentials**: whoever holds
|
|
18
18
|
* them drives the sandbox. Keep them out of logs, traces and error messages.
|
|
19
19
|
*
|
|
20
|
-
* Only a backend with direct access returns this (`e2b`
|
|
21
|
-
* `lambda-microvm` and `agent-sandbox` never do), and only on create,
|
|
22
|
-
* resume. Every field is optional because backends differ.
|
|
20
|
+
* Only a backend with direct access returns this (`e2b`, `e2b-cluster` and
|
|
21
|
+
* `cube`; `lambda-microvm` and `agent-sandbox` never do), and only on create,
|
|
22
|
+
* get and resume. Every field is optional because backends differ.
|
|
23
23
|
*/
|
|
24
24
|
interface SandboxAccess {
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Sent as `X-Access-Token` to the in-sandbox agent (envd). Never present
|
|
27
|
+
* on `cube`, where the agent asks for `trafficAccessToken` instead.
|
|
28
|
+
*/
|
|
26
29
|
envdAccessToken?: string;
|
|
27
30
|
/**
|
|
28
|
-
* Sent as `e2b-traffic-access-token` to every other port
|
|
29
|
-
*
|
|
31
|
+
* Sent as `e2b-traffic-access-token` to every other port; on `cube` to
|
|
32
|
+
* every port, the agent included. On `e2b` it exists only for a sandbox
|
|
33
|
+
* created with `privateTraffic`; on `e2b-cluster` and `cube` every sandbox
|
|
34
|
+
* has one.
|
|
30
35
|
*/
|
|
31
36
|
trafficAccessToken?: string;
|
|
32
37
|
/**
|
|
@@ -56,6 +61,11 @@ interface SandboxInfo {
|
|
|
56
61
|
persistent: boolean;
|
|
57
62
|
createdAt: string;
|
|
58
63
|
lastUsedAt: string;
|
|
64
|
+
/**
|
|
65
|
+
* When the sandbox times out. On `cube` it moves forward with every
|
|
66
|
+
* request the sandbox receives, and is absent once the sandbox was
|
|
67
|
+
* suspended through this API, until it runs again.
|
|
68
|
+
*/
|
|
59
69
|
expiresAt?: string;
|
|
60
70
|
errorMessage?: string;
|
|
61
71
|
/**
|
|
@@ -95,7 +105,7 @@ interface CreateRunRequest {
|
|
|
95
105
|
persistent?: boolean;
|
|
96
106
|
sandboxTtlSeconds?: number;
|
|
97
107
|
runtime?: SandboxRuntime;
|
|
98
|
-
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
|
|
108
|
+
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`, `e2b-cluster`, `cube`); the deployment's default when omitted. */
|
|
99
109
|
provider?: string;
|
|
100
110
|
/**
|
|
101
111
|
* Backend to try when `provider` does not deliver. Naming it is asking for
|
|
@@ -125,6 +135,14 @@ interface CreateSandboxRequest {
|
|
|
125
135
|
snapshotId?: string;
|
|
126
136
|
cpuSize?: number;
|
|
127
137
|
memSize?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Seconds until the sandbox times out and `onTimeout` applies. On `cube`
|
|
140
|
+
* they count idleness, not lifetime: every request the sandbox receives
|
|
141
|
+
* starts the count again, so a sandbox in use outlives them. And a `cube`
|
|
142
|
+
* sandbox that was suspended through the API and runs again counts the
|
|
143
|
+
* backend's default idle timeout (15 minutes unless the deployment sets
|
|
144
|
+
* `CUBE_DEFAULT_TIMEOUT_SECONDS`), not these.
|
|
145
|
+
*/
|
|
128
146
|
sandboxTtlSeconds?: number;
|
|
129
147
|
files?: FileInput[];
|
|
130
148
|
runtime?: SandboxRuntime;
|
|
@@ -135,11 +153,15 @@ interface CreateSandboxRequest {
|
|
|
135
153
|
/** Backend to host it; the deployment's default when omitted. */
|
|
136
154
|
provider?: string;
|
|
137
155
|
/**
|
|
138
|
-
* Seal the sandbox:
|
|
139
|
-
* `access
|
|
140
|
-
* `access.
|
|
141
|
-
*
|
|
142
|
-
*
|
|
156
|
+
* Seal the sandbox: no port answers a request without a token from
|
|
157
|
+
* `access`. On `e2b` and `e2b-cluster` the agent asks for
|
|
158
|
+
* `access.envdAccessToken` and every other port for
|
|
159
|
+
* `access.trafficAccessToken`; on `cube` there is no envd token and
|
|
160
|
+
* `access.trafficAccessToken` guards every port, the agent included. The
|
|
161
|
+
* API answers 409 on a backend that cannot (`lambda-microvm`,
|
|
162
|
+
* `agent-sandbox`), and 502 when the backend created the sandbox without
|
|
163
|
+
* a token that seals it (it is torn down). `e2b-cluster` and `cube` seal
|
|
164
|
+
* every sandbox whatever this says, `false` included.
|
|
143
165
|
*/
|
|
144
166
|
privateTraffic?: boolean;
|
|
145
167
|
}
|
|
@@ -296,6 +318,10 @@ declare class Sandbox {
|
|
|
296
318
|
kill(): Promise<void>;
|
|
297
319
|
/** Reads the sandbox again; the answer carries `access` where the backend has it. */
|
|
298
320
|
getInfo(): Promise<SandboxInfo>;
|
|
321
|
+
/**
|
|
322
|
+
* Gives the sandbox `ttlSeconds` from now; on `cube`, `ttlSeconds` of
|
|
323
|
+
* idleness, and nothing while the sandbox is suspended.
|
|
324
|
+
*/
|
|
299
325
|
extend(ttlSeconds: number): Promise<SandboxInfo>;
|
|
300
326
|
suspend(): Promise<SandboxInfo>;
|
|
301
327
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ interface SandboxConfig {
|
|
|
6
6
|
interface AuthStrategy {
|
|
7
7
|
getHeaders: () => Headers;
|
|
8
8
|
}
|
|
9
|
-
declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm", "agent-sandbox", "e2b"];
|
|
9
|
+
declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm", "agent-sandbox", "e2b", "e2b-cluster", "cube"];
|
|
10
10
|
type SandboxRuntime = (typeof SANDBOX_RUNTIMES)[number];
|
|
11
11
|
type SandboxState = 'pending' | 'running' | 'suspended' | 'terminated' | 'failed';
|
|
12
12
|
type SandboxOnTimeout = 'suspend' | 'terminate';
|
|
@@ -17,16 +17,21 @@ type SandboxOnTimeout = 'suspend' | 'terminate';
|
|
|
17
17
|
* `envdAccessToken` and `trafficAccessToken` are **credentials**: whoever holds
|
|
18
18
|
* them drives the sandbox. Keep them out of logs, traces and error messages.
|
|
19
19
|
*
|
|
20
|
-
* Only a backend with direct access returns this (`e2b`
|
|
21
|
-
* `lambda-microvm` and `agent-sandbox` never do), and only on create,
|
|
22
|
-
* resume. Every field is optional because backends differ.
|
|
20
|
+
* Only a backend with direct access returns this (`e2b`, `e2b-cluster` and
|
|
21
|
+
* `cube`; `lambda-microvm` and `agent-sandbox` never do), and only on create,
|
|
22
|
+
* get and resume. Every field is optional because backends differ.
|
|
23
23
|
*/
|
|
24
24
|
interface SandboxAccess {
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Sent as `X-Access-Token` to the in-sandbox agent (envd). Never present
|
|
27
|
+
* on `cube`, where the agent asks for `trafficAccessToken` instead.
|
|
28
|
+
*/
|
|
26
29
|
envdAccessToken?: string;
|
|
27
30
|
/**
|
|
28
|
-
* Sent as `e2b-traffic-access-token` to every other port
|
|
29
|
-
*
|
|
31
|
+
* Sent as `e2b-traffic-access-token` to every other port; on `cube` to
|
|
32
|
+
* every port, the agent included. On `e2b` it exists only for a sandbox
|
|
33
|
+
* created with `privateTraffic`; on `e2b-cluster` and `cube` every sandbox
|
|
34
|
+
* has one.
|
|
30
35
|
*/
|
|
31
36
|
trafficAccessToken?: string;
|
|
32
37
|
/**
|
|
@@ -56,6 +61,11 @@ interface SandboxInfo {
|
|
|
56
61
|
persistent: boolean;
|
|
57
62
|
createdAt: string;
|
|
58
63
|
lastUsedAt: string;
|
|
64
|
+
/**
|
|
65
|
+
* When the sandbox times out. On `cube` it moves forward with every
|
|
66
|
+
* request the sandbox receives, and is absent once the sandbox was
|
|
67
|
+
* suspended through this API, until it runs again.
|
|
68
|
+
*/
|
|
59
69
|
expiresAt?: string;
|
|
60
70
|
errorMessage?: string;
|
|
61
71
|
/**
|
|
@@ -95,7 +105,7 @@ interface CreateRunRequest {
|
|
|
95
105
|
persistent?: boolean;
|
|
96
106
|
sandboxTtlSeconds?: number;
|
|
97
107
|
runtime?: SandboxRuntime;
|
|
98
|
-
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
|
|
108
|
+
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`, `e2b-cluster`, `cube`); the deployment's default when omitted. */
|
|
99
109
|
provider?: string;
|
|
100
110
|
/**
|
|
101
111
|
* Backend to try when `provider` does not deliver. Naming it is asking for
|
|
@@ -125,6 +135,14 @@ interface CreateSandboxRequest {
|
|
|
125
135
|
snapshotId?: string;
|
|
126
136
|
cpuSize?: number;
|
|
127
137
|
memSize?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Seconds until the sandbox times out and `onTimeout` applies. On `cube`
|
|
140
|
+
* they count idleness, not lifetime: every request the sandbox receives
|
|
141
|
+
* starts the count again, so a sandbox in use outlives them. And a `cube`
|
|
142
|
+
* sandbox that was suspended through the API and runs again counts the
|
|
143
|
+
* backend's default idle timeout (15 minutes unless the deployment sets
|
|
144
|
+
* `CUBE_DEFAULT_TIMEOUT_SECONDS`), not these.
|
|
145
|
+
*/
|
|
128
146
|
sandboxTtlSeconds?: number;
|
|
129
147
|
files?: FileInput[];
|
|
130
148
|
runtime?: SandboxRuntime;
|
|
@@ -135,11 +153,15 @@ interface CreateSandboxRequest {
|
|
|
135
153
|
/** Backend to host it; the deployment's default when omitted. */
|
|
136
154
|
provider?: string;
|
|
137
155
|
/**
|
|
138
|
-
* Seal the sandbox:
|
|
139
|
-
* `access
|
|
140
|
-
* `access.
|
|
141
|
-
*
|
|
142
|
-
*
|
|
156
|
+
* Seal the sandbox: no port answers a request without a token from
|
|
157
|
+
* `access`. On `e2b` and `e2b-cluster` the agent asks for
|
|
158
|
+
* `access.envdAccessToken` and every other port for
|
|
159
|
+
* `access.trafficAccessToken`; on `cube` there is no envd token and
|
|
160
|
+
* `access.trafficAccessToken` guards every port, the agent included. The
|
|
161
|
+
* API answers 409 on a backend that cannot (`lambda-microvm`,
|
|
162
|
+
* `agent-sandbox`), and 502 when the backend created the sandbox without
|
|
163
|
+
* a token that seals it (it is torn down). `e2b-cluster` and `cube` seal
|
|
164
|
+
* every sandbox whatever this says, `false` included.
|
|
143
165
|
*/
|
|
144
166
|
privateTraffic?: boolean;
|
|
145
167
|
}
|
|
@@ -296,6 +318,10 @@ declare class Sandbox {
|
|
|
296
318
|
kill(): Promise<void>;
|
|
297
319
|
/** Reads the sandbox again; the answer carries `access` where the backend has it. */
|
|
298
320
|
getInfo(): Promise<SandboxInfo>;
|
|
321
|
+
/**
|
|
322
|
+
* Gives the sandbox `ttlSeconds` from now; on `cube`, `ttlSeconds` of
|
|
323
|
+
* idleness, and nothing while the sandbox is suspended.
|
|
324
|
+
*/
|
|
299
325
|
extend(ttlSeconds: number): Promise<SandboxInfo>;
|
|
300
326
|
suspend(): Promise<SandboxInfo>;
|
|
301
327
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface SandboxConfig {
|
|
|
6
6
|
interface AuthStrategy {
|
|
7
7
|
getHeaders: () => Headers;
|
|
8
8
|
}
|
|
9
|
-
declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm", "agent-sandbox", "e2b"];
|
|
9
|
+
declare const SANDBOX_RUNTIMES: readonly ["lambda-microvm", "agent-sandbox", "e2b", "e2b-cluster", "cube"];
|
|
10
10
|
type SandboxRuntime = (typeof SANDBOX_RUNTIMES)[number];
|
|
11
11
|
type SandboxState = 'pending' | 'running' | 'suspended' | 'terminated' | 'failed';
|
|
12
12
|
type SandboxOnTimeout = 'suspend' | 'terminate';
|
|
@@ -17,16 +17,21 @@ type SandboxOnTimeout = 'suspend' | 'terminate';
|
|
|
17
17
|
* `envdAccessToken` and `trafficAccessToken` are **credentials**: whoever holds
|
|
18
18
|
* them drives the sandbox. Keep them out of logs, traces and error messages.
|
|
19
19
|
*
|
|
20
|
-
* Only a backend with direct access returns this (`e2b`
|
|
21
|
-
* `lambda-microvm` and `agent-sandbox` never do), and only on create,
|
|
22
|
-
* resume. Every field is optional because backends differ.
|
|
20
|
+
* Only a backend with direct access returns this (`e2b`, `e2b-cluster` and
|
|
21
|
+
* `cube`; `lambda-microvm` and `agent-sandbox` never do), and only on create,
|
|
22
|
+
* get and resume. Every field is optional because backends differ.
|
|
23
23
|
*/
|
|
24
24
|
interface SandboxAccess {
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Sent as `X-Access-Token` to the in-sandbox agent (envd). Never present
|
|
27
|
+
* on `cube`, where the agent asks for `trafficAccessToken` instead.
|
|
28
|
+
*/
|
|
26
29
|
envdAccessToken?: string;
|
|
27
30
|
/**
|
|
28
|
-
* Sent as `e2b-traffic-access-token` to every other port
|
|
29
|
-
*
|
|
31
|
+
* Sent as `e2b-traffic-access-token` to every other port; on `cube` to
|
|
32
|
+
* every port, the agent included. On `e2b` it exists only for a sandbox
|
|
33
|
+
* created with `privateTraffic`; on `e2b-cluster` and `cube` every sandbox
|
|
34
|
+
* has one.
|
|
30
35
|
*/
|
|
31
36
|
trafficAccessToken?: string;
|
|
32
37
|
/**
|
|
@@ -56,6 +61,11 @@ interface SandboxInfo {
|
|
|
56
61
|
persistent: boolean;
|
|
57
62
|
createdAt: string;
|
|
58
63
|
lastUsedAt: string;
|
|
64
|
+
/**
|
|
65
|
+
* When the sandbox times out. On `cube` it moves forward with every
|
|
66
|
+
* request the sandbox receives, and is absent once the sandbox was
|
|
67
|
+
* suspended through this API, until it runs again.
|
|
68
|
+
*/
|
|
59
69
|
expiresAt?: string;
|
|
60
70
|
errorMessage?: string;
|
|
61
71
|
/**
|
|
@@ -95,7 +105,7 @@ interface CreateRunRequest {
|
|
|
95
105
|
persistent?: boolean;
|
|
96
106
|
sandboxTtlSeconds?: number;
|
|
97
107
|
runtime?: SandboxRuntime;
|
|
98
|
-
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
|
|
108
|
+
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`, `e2b-cluster`, `cube`); the deployment's default when omitted. */
|
|
99
109
|
provider?: string;
|
|
100
110
|
/**
|
|
101
111
|
* Backend to try when `provider` does not deliver. Naming it is asking for
|
|
@@ -125,6 +135,14 @@ interface CreateSandboxRequest {
|
|
|
125
135
|
snapshotId?: string;
|
|
126
136
|
cpuSize?: number;
|
|
127
137
|
memSize?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Seconds until the sandbox times out and `onTimeout` applies. On `cube`
|
|
140
|
+
* they count idleness, not lifetime: every request the sandbox receives
|
|
141
|
+
* starts the count again, so a sandbox in use outlives them. And a `cube`
|
|
142
|
+
* sandbox that was suspended through the API and runs again counts the
|
|
143
|
+
* backend's default idle timeout (15 minutes unless the deployment sets
|
|
144
|
+
* `CUBE_DEFAULT_TIMEOUT_SECONDS`), not these.
|
|
145
|
+
*/
|
|
128
146
|
sandboxTtlSeconds?: number;
|
|
129
147
|
files?: FileInput[];
|
|
130
148
|
runtime?: SandboxRuntime;
|
|
@@ -135,11 +153,15 @@ interface CreateSandboxRequest {
|
|
|
135
153
|
/** Backend to host it; the deployment's default when omitted. */
|
|
136
154
|
provider?: string;
|
|
137
155
|
/**
|
|
138
|
-
* Seal the sandbox:
|
|
139
|
-
* `access
|
|
140
|
-
* `access.
|
|
141
|
-
*
|
|
142
|
-
*
|
|
156
|
+
* Seal the sandbox: no port answers a request without a token from
|
|
157
|
+
* `access`. On `e2b` and `e2b-cluster` the agent asks for
|
|
158
|
+
* `access.envdAccessToken` and every other port for
|
|
159
|
+
* `access.trafficAccessToken`; on `cube` there is no envd token and
|
|
160
|
+
* `access.trafficAccessToken` guards every port, the agent included. The
|
|
161
|
+
* API answers 409 on a backend that cannot (`lambda-microvm`,
|
|
162
|
+
* `agent-sandbox`), and 502 when the backend created the sandbox without
|
|
163
|
+
* a token that seals it (it is torn down). `e2b-cluster` and `cube` seal
|
|
164
|
+
* every sandbox whatever this says, `false` included.
|
|
143
165
|
*/
|
|
144
166
|
privateTraffic?: boolean;
|
|
145
167
|
}
|
|
@@ -296,6 +318,10 @@ declare class Sandbox {
|
|
|
296
318
|
kill(): Promise<void>;
|
|
297
319
|
/** Reads the sandbox again; the answer carries `access` where the backend has it. */
|
|
298
320
|
getInfo(): Promise<SandboxInfo>;
|
|
321
|
+
/**
|
|
322
|
+
* Gives the sandbox `ttlSeconds` from now; on `cube`, `ttlSeconds` of
|
|
323
|
+
* idleness, and nothing while the sandbox is suspended.
|
|
324
|
+
*/
|
|
299
325
|
extend(ttlSeconds: number): Promise<SandboxInfo>;
|
|
300
326
|
suspend(): Promise<SandboxInfo>;
|
|
301
327
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { createParser } from 'eventsource-parser';
|
|
3
3
|
|
|
4
|
-
const SANDBOX_RUNTIMES = ["lambda-microvm", "agent-sandbox", "e2b"];
|
|
4
|
+
const SANDBOX_RUNTIMES = ["lambda-microvm", "agent-sandbox", "e2b", "e2b-cluster", "cube"];
|
|
5
5
|
|
|
6
6
|
class FetchError extends Error {
|
|
7
7
|
constructor(message, url, method, status, response) {
|
|
@@ -217,6 +217,10 @@ class Sandbox {
|
|
|
217
217
|
this.remember(info);
|
|
218
218
|
return info;
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Gives the sandbox `ttlSeconds` from now; on `cube`, `ttlSeconds` of
|
|
222
|
+
* idleness, and nothing while the sandbox is suspended.
|
|
223
|
+
*/
|
|
220
224
|
async extend(ttlSeconds) {
|
|
221
225
|
const info = await this.client.extendSandbox(this.sandboxId, ttlSeconds);
|
|
222
226
|
this.remember(info);
|