@evolvingmachines/e2b 0.0.51 → 0.0.52-berth-day-one.20260814.110f525
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 +9 -1
- package/dist/index.cjs +8 -2
- package/dist/index.d.cts +212 -3
- package/dist/index.d.ts +212 -3
- package/dist/index.js +8 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
<br><br>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/evolving-machines-lab/evolve/main/logo/evolving-machines-ink.png" alt="Evolving Machines" width="380">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<br><br>
|
|
8
|
+
|
|
9
|
+
# Evolving Machines — Evolve E2B Provider
|
|
2
10
|
|
|
3
11
|
E2B sandbox provider for [Evolve SDK](https://www.npmjs.com/package/@evolvingmachines/sdk).
|
|
4
12
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
'use strict';var codeInterpreter=require('@e2b/code-interpreter');
|
|
2
|
-
|
|
1
|
+
'use strict';var codeInterpreter=require('@e2b/code-interpreter');function g(s){if(!s||typeof s!="object")return false;if(s.name==="TimeoutError")return true;let e=s.message;return typeof e=="string"&&/timed?\s*out/i.test(e)}var P=100,v=100;function u(s){return s instanceof Date?s.toISOString():String(s)}function A(s){if(typeof s=="string"||s instanceof ArrayBuffer)return s;if(s instanceof Buffer)return new Uint8Array(s).buffer;if(s instanceof Uint8Array)return new Uint8Array(s).buffer;throw new Error(`Unsupported data type for file upload: ${typeof s}. Expected string, Buffer, ArrayBuffer, or Uint8Array.`)}var l=class extends Error{constructor(e){super(e),this.name="E2BResourcesError";}},b=class extends Error{constructor(){super("E2B has no idle timeout: its sandbox timeout is an ABSOLUTE lifetime that in-sandbox activity never extends. Use `timeoutMs` for the lifetime, and call setTimeout() to extend a sandbox you know is still working."),this.name="E2BIdleTimeoutError";}},x=class{constructor(e,t){this.sandbox=e;this.defaultUser=t;}async run(e,t){try{let r=await this.sandbox.commands.run(e,{timeoutMs:t?.timeoutMs,envs:t?.envs,cwd:t?.cwd,user:this.defaultUser,onStdout:t?.onStdout,onStderr:t?.onStderr});return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let n=r;return {exitCode:n.exitCode,stdout:n.stdout??"",stderr:n.stderr??""}}if(g(r))return {exitCode:124,stdout:"",stderr:r instanceof Error?r.message:"command timed out"};throw r}}async spawn(e,t){let r=await this.sandbox.commands.run(e,{background:true,stdin:t?.stdin??true,timeoutMs:t?.timeoutMs,envs:t?.envs,cwd:t?.cwd,user:this.defaultUser,onStdout:t?.onStdout,onStderr:t?.onStderr});return {processId:String(r.pid),wait:async()=>{try{let n=await r.wait();return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let i=n;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}if(g(n))return {exitCode:124,stdout:"",stderr:n instanceof Error?n.message:"command timed out"};throw n}},kill:()=>this.sandbox.commands.kill(r.pid)}}async list(){return (await this.sandbox.commands.list()).map(t=>({...t,processId:String(t.pid)}))}async connect(e,t){let r=await this.sandbox.commands.connect(Number(e),{onStdout:t?.onStdout,onStderr:t?.onStderr,timeoutMs:t?.timeoutMs});return {processId:String(r.pid),wait:async()=>{try{let n=await r.wait();return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let i=n;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}if(g(n))return {exitCode:124,stdout:"",stderr:n instanceof Error?n.message:"command timed out"};throw n}},kill:()=>this.sandbox.commands.kill(r.pid)}}async sendStdin(e,t){await this.sandbox.commands.sendStdin(Number(e),t);}async kill(e){return this.sandbox.commands.kill(Number(e))}},h=class{constructor(e,t){this.sandbox=e;this.defaultUser=t;}async read(e){let t=await this.sandbox.files.read(e,{format:"bytes",requestTimeoutMs:3e5,user:this.defaultUser});if(!t.includes(0))try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(t)}catch{}return t}async write(e,t){await this.sandbox.files.write(e,A(t),{requestTimeoutMs:3e5,user:this.defaultUser});}async writeBatch(e){let t=e.map(r=>({path:r.path,data:A(r.data)}));await this.sandbox.files.write(t,{requestTimeoutMs:3e5,user:this.defaultUser});}async makeDir(e){await this.sandbox.files.makeDir(e,{user:this.defaultUser});}async uploadUrl(e,t){return this.sandbox.uploadUrl(e,{user:this.defaultUser,...t?{useSignatureExpiration:t}:{}})}async downloadUrl(e,t){return this.sandbox.downloadUrl(e,{user:this.defaultUser,...t?{useSignatureExpiration:t}:{}})}async exists(e){return this.sandbox.files.exists(e,{user:this.defaultUser})}async list(e){return (await this.sandbox.files.list(e,{user:this.defaultUser})).map(r=>({name:r.name,path:r.path,type:r.type==="dir"?"dir":"file"}))}async remove(e){await this.sandbox.files.remove(e,{user:this.defaultUser});}async rename(e,t){await this.sandbox.files.rename(e,t,{user:this.defaultUser});}async readStream(e){return this.sandbox.files.read(e,{format:"stream",user:this.defaultUser})}async writeStream(e,t){await this.sandbox.files.write(e,t,{user:this.defaultUser});}async writeFromPath(e,t){let{createReadStream:r,statSync:n}=await import('fs'),{Readable:i}=await import('stream'),{randomBytes:o}=await import('crypto'),a=n(t).size,f=`----evolve${o(16).toString("hex")}`,w=Buffer.from(`--${f}\r
|
|
2
|
+
Content-Disposition: form-data; name="file"; filename="blob"\r
|
|
3
|
+
Content-Type: application/octet-stream\r
|
|
4
|
+
\r
|
|
5
|
+
`),S=Buffer.from(`\r
|
|
6
|
+
--${f}--\r
|
|
7
|
+
`);async function*I(){yield w;for await(let d of r(t))yield d;yield S;}try{let d=await this.uploadUrl(e),m=await fetch(d,{method:"POST",body:i.toWeb(i.from(I())),headers:{"Content-Type":`multipart/form-data; boundary=${f}`,"Content-Length":String(w.length+a+S.length)},duplex:"half"});if(!m.ok)throw new Error(`streamed upload to ${e} failed (HTTP ${m.status})`)}catch(d){console.warn(`[e2b] streamed upload of ${t} failed, falling back to a buffered write:`,d instanceof Error?d.message:d);let m=i.toWeb(r(t));await this.writeStream(e,m);}}async watchDir(e,t,r){let n=await this.sandbox.files.watchDir(e,t,{recursive:r?.recursive,timeoutMs:r?.timeoutMs,user:this.defaultUser,onExit:r?.onExit});return {stop:()=>n.stop()}}},c=class{constructor(e,t,r,n){this.sandbox=e;this.apiKey=t;this.apiUrl=r;this.commands=new x(e,n),this.files=new h(e,n);}commands;files;get sandboxId(){return this.sandbox.sandboxId}getHost(e){return Promise.resolve(this.sandbox.getHost(e))}async isRunning(){return this.sandbox.isRunning()}async getInfo(){let e=await this.sandbox.getInfo();return {sandboxId:e.sandboxId,image:e.templateId,name:e.name,metadata:e.metadata??{},startedAt:u(e.startedAt),endAt:e.endAt?u(e.endAt):void 0}}async kill(){try{await this.sandbox.kill();}catch{await new Promise(e=>setTimeout(e,500)),await this.sandbox.kill();}}async pause(){await this.sandbox.betaPause({apiKey:this.apiKey,apiUrl:this.apiUrl});}},y=class{providerType="e2b";name="E2B";apiKey;apiUrl;defaultTimeoutMs;templateId;sandboxUsers=new Map;constructor(e){this.apiKey=e.apiKey,this.apiUrl=e.apiUrl,this.defaultTimeoutMs=e.defaultTimeoutMs??36e5,this.templateId=e.templateId;}async create(e){if(e.idleTimeoutMs!==void 0)throw new b;if(e.resources?.gpu!==void 0||e.resources?.gpuTypes!==void 0)throw new l("E2B offers no GPU allocation at any tier \u2014 a `resources.gpu` request cannot be enforced. Run GPU workloads on a provider that reserves GPUs (modal).");if(e.resources&&(e.resources.cpu!==void 0||e.resources.memory!==void 0||e.resources.disk!==void 0))throw new l("E2B cannot size a sandbox at create time: sizing is fixed by the template (Template.build cpuCount/memoryMB; disk is plan-fixed). Build a template with the desired resources and pass it as `image` instead of `resources`.");let t=e.timeoutMs??this.defaultTimeoutMs,r=e.image??this.templateId??"evolve-all";if(e.network?.outbound==="open"&&e.network.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");let n=e.network?.allowedDestinations??[],i=e.network?.outbound==="blocked"&&n.length>0,o=await codeInterpreter.Sandbox.create(r,{apiKey:this.apiKey,apiUrl:this.apiUrl,envs:e.envs,metadata:e.metadata,timeoutMs:t,allowInternetAccess:e.network?.outbound!=="blocked"||i,network:i?{denyOut:["0.0.0.0/0"],allowOut:n}:void 0});return e.workingDirectory&&await o.files.makeDir(e.workingDirectory,{user:e.user}),e.user&&this.sandboxUsers.set(o.sandboxId,e.user),new c(o,this.apiKey,this.apiUrl,e.user)}async connect(e,t){let r=await codeInterpreter.Sandbox.connect(e,{apiKey:this.apiKey,apiUrl:this.apiUrl,timeoutMs:t??this.defaultTimeoutMs});return new c(r,this.apiKey,this.apiUrl,this.sandboxUsers.get(e))}async list(e){let t=await this.paginate(e);if(t.error&&!t.stoppedAtLimit)throw new Error(t.error);return t.sandboxes}async listAll(e){let{stoppedAtLimit:t,...r}=await this.paginate(e);return r}async paginate(e){let t=e?.limit;return U(codeInterpreter.Sandbox.list({apiKey:this.apiKey,apiUrl:this.apiUrl,query:{state:e?.state,metadata:e?.metadata},limit:t===void 0?P:Math.min(t,P)}),t)}};async function U(s,e){let t=[],r=0,n=new Set;for(;s.hasNext;){if(r>=v)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list exceeded ${v} pages`};let i=s.nextToken;if(i!==void 0){if(n.has(i))return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:"pagination token repeated"};n.add(i);}let o;try{o=await s.nextItems();}catch(a){return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list failed: ${a instanceof Error?a.message:String(a)}`}}r+=1;for(let a of o){if(e!==void 0&&t.length>=e)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:true,error:`stopped at the requested limit of ${e} with more sandboxes available`};t.push({sandboxId:a.sandboxId,image:a.templateId,name:a.name,metadata:a.metadata??{},startedAt:u(a.startedAt),endAt:a.endAt?u(a.endAt):void 0});}if(e!==void 0&&t.length>=e&&s.hasNext)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:true,error:`stopped at the requested limit of ${e} with more sandboxes available`};if(e!==void 0&&t.length>=e)break}return {sandboxes:t,complete:true,pagesFetched:r,stoppedAtLimit:false}}var E=U;function C(s={}){let e=s.apiKey??process.env.E2B_API_KEY;if(!e)throw new Error("E2B API key required. Set E2B_API_KEY environment variable or pass apiKey in config. Get your key at https://e2b.dev/sign-in");return new y({...s,apiKey:e})}
|
|
8
|
+
exports.E2BCommands=x;exports.E2BFiles=h;exports.E2BIdleTimeoutError=b;exports.E2BProvider=y;exports.E2BResourcesError=l;exports.E2B_MAX_LIST_PAGES=v;exports.E2B_MAX_PAGE_SIZE=P;exports._testCollectSandboxPages=E;exports.createE2BProvider=C;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Sandbox } from '@e2b/code-interpreter';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* E2B Sandbox Provider - Clean Architecture
|
|
3
5
|
*
|
|
@@ -11,6 +13,40 @@
|
|
|
11
13
|
* - Configuration externalized (no hardcoded mappings)
|
|
12
14
|
* - Clear naming (run = blocking, spawn = background)
|
|
13
15
|
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Largest page E2B will serve. Not a taste choice — a larger `limit` is refused
|
|
19
|
+
* outright: `400 validation error: parameter "limit" in query has an error:
|
|
20
|
+
* number must be at most 100`.
|
|
21
|
+
*/
|
|
22
|
+
declare const E2B_MAX_PAGE_SIZE = 100;
|
|
23
|
+
/**
|
|
24
|
+
* Page ceiling for one enumeration — 10,000 sandboxes at the maximum page size.
|
|
25
|
+
* A walk that reaches it stops and reports itself INCOMPLETE, because the one
|
|
26
|
+
* thing a fleet enumeration may never do is return a short list that reads like
|
|
27
|
+
* a whole one.
|
|
28
|
+
*/
|
|
29
|
+
declare const E2B_MAX_LIST_PAGES = 100;
|
|
30
|
+
/**
|
|
31
|
+
* Typed error for create-time sizing requests E2B cannot enforce.
|
|
32
|
+
* E2B sandboxes inherit cpu/memory from their TEMPLATE (Template.build
|
|
33
|
+
* cpuCount/memoryMB; disk is plan-fixed) — Sandbox.create has no sizing
|
|
34
|
+
* parameters, so a `resources` request would be silently ignored. Per the
|
|
35
|
+
* provider law (reject what you cannot enforce) it is refused loudly here.
|
|
36
|
+
*/
|
|
37
|
+
declare class E2BResourcesError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Typed error for an idle timeout E2B cannot enforce. E2B has exactly one
|
|
42
|
+
* clock and it is absolute: the sandbox is killed when its timeout expires,
|
|
43
|
+
* and only explicit client calls (create, connect, setTimeout) move that
|
|
44
|
+
* deadline — never what the sandbox is or is not doing. An `idleTimeoutMs`
|
|
45
|
+
* would therefore be silently ignored, so it is refused instead.
|
|
46
|
+
*/
|
|
47
|
+
declare class E2BIdleTimeoutError extends Error {
|
|
48
|
+
constructor();
|
|
49
|
+
}
|
|
14
50
|
/** Result of a completed sandbox command */
|
|
15
51
|
interface SandboxCommandResult {
|
|
16
52
|
exitCode: number;
|
|
@@ -85,11 +121,47 @@ interface SandboxConnectOptions {
|
|
|
85
121
|
}
|
|
86
122
|
/** Options for creating a sandbox */
|
|
87
123
|
interface SandboxCreateOptions {
|
|
88
|
-
|
|
124
|
+
/**
|
|
125
|
+
* E2B template ID. OPTIONAL: create() falls back to the provider's
|
|
126
|
+
* configured `templateId`, then to "evolve-all" — declaring it required
|
|
127
|
+
* contradicted that implementation and only went unnoticed because TS
|
|
128
|
+
* method parameters are bivariant, so the SDK could already call
|
|
129
|
+
* create({}) through the shared contract.
|
|
130
|
+
*/
|
|
131
|
+
image?: string;
|
|
89
132
|
envs?: Record<string, string>;
|
|
90
133
|
metadata?: Record<string, string>;
|
|
91
134
|
timeoutMs?: number;
|
|
135
|
+
/**
|
|
136
|
+
* REJECTED with E2BIdleTimeoutError. E2B's timeout is an ABSOLUTE lifetime
|
|
137
|
+
* that in-sandbox activity never extends, so there is no inactivity clock to
|
|
138
|
+
* map this onto and honouring it would be a lie.
|
|
139
|
+
*/
|
|
140
|
+
idleTimeoutMs?: number;
|
|
92
141
|
workingDirectory?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Per-sandbox compute sizing (cpu cores, memory GiB, disk GiB). E2B sizes
|
|
144
|
+
* sandboxes at TEMPLATE BUILD time only (Template.build cpuCount/memoryMB;
|
|
145
|
+
* disk is plan-fixed) — create-time sizing cannot be enforced, so any value
|
|
146
|
+
* here is REJECTED with E2BResourcesError rather than silently ignored.
|
|
147
|
+
* Bake sizing into the template the `image` names instead. `gpu`/`gpuTypes`
|
|
148
|
+
* are rejected the same way: e2b offers no GPU allocation at any tier.
|
|
149
|
+
*/
|
|
150
|
+
resources?: {
|
|
151
|
+
cpu?: number;
|
|
152
|
+
memory?: number;
|
|
153
|
+
disk?: number;
|
|
154
|
+
gpu?: number;
|
|
155
|
+
gpuTypes?: string[];
|
|
156
|
+
};
|
|
157
|
+
network?: {
|
|
158
|
+
outbound: "open" | "blocked";
|
|
159
|
+
allowedDestinations?: string[];
|
|
160
|
+
};
|
|
161
|
+
/** Run all commands and file operations as this user (passed on every E2B operation that supports it). */
|
|
162
|
+
user?: string;
|
|
163
|
+
/** Home directory used by the SDK for agent config paths; not consumed by the provider. */
|
|
164
|
+
homeDir?: string;
|
|
93
165
|
}
|
|
94
166
|
/** Options for listing sandboxes */
|
|
95
167
|
interface SandboxListOptions {
|
|
@@ -97,6 +169,20 @@ interface SandboxListOptions {
|
|
|
97
169
|
metadata?: Record<string, string>;
|
|
98
170
|
limit?: number;
|
|
99
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* A COMPLETE (or admittedly incomplete) enumeration of the project's fleet.
|
|
174
|
+
*
|
|
175
|
+
* `complete` is the load-bearing field. Callers that need a whole fleet —
|
|
176
|
+
* orphan sweeps, lifecycle reconciliation — read a sandbox's ABSENCE from the
|
|
177
|
+
* list as evidence it is gone, so a truncated page and a small fleet must never
|
|
178
|
+
* be the same answer. `complete: false` means leave every row alone.
|
|
179
|
+
*/
|
|
180
|
+
interface SandboxListPage {
|
|
181
|
+
sandboxes: SandboxInfo[];
|
|
182
|
+
complete: boolean;
|
|
183
|
+
pagesFetched: number;
|
|
184
|
+
error?: string;
|
|
185
|
+
}
|
|
100
186
|
/** Command execution capabilities */
|
|
101
187
|
interface SandboxCommands {
|
|
102
188
|
/** Run command and wait for completion */
|
|
@@ -127,6 +213,8 @@ interface SandboxFiles {
|
|
|
127
213
|
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
128
214
|
/** Write from stream */
|
|
129
215
|
writeStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
216
|
+
/** Upload a local file by path, streamed off disk (never buffered whole) */
|
|
217
|
+
writeFromPath(sandboxPath: string, localPath: string): Promise<void>;
|
|
130
218
|
/** Get pre-signed upload URL for large files (expiration in seconds) */
|
|
131
219
|
uploadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
132
220
|
/** Get pre-signed download URL for large files (expiration in seconds) */
|
|
@@ -164,12 +252,16 @@ interface SandboxInstance {
|
|
|
164
252
|
interface SandboxProvider {
|
|
165
253
|
/** Provider type identifier */
|
|
166
254
|
readonly providerType: string;
|
|
255
|
+
/** Human-readable provider name for logging */
|
|
256
|
+
readonly name?: string;
|
|
167
257
|
/** Create new sandbox */
|
|
168
258
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
169
259
|
/** Connect to existing sandbox */
|
|
170
260
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
171
|
-
/** List sandboxes
|
|
261
|
+
/** List sandboxes, paginating to exhaustion. `limit` bounds items returned. */
|
|
172
262
|
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
263
|
+
/** The same enumeration for fleet bookkeeping: never throws, reports completeness. */
|
|
264
|
+
listAll(options?: SandboxListOptions): Promise<SandboxListPage>;
|
|
173
265
|
}
|
|
174
266
|
interface E2BConfig {
|
|
175
267
|
/** E2B API key. Default: reads from E2B_API_KEY env var */
|
|
@@ -187,17 +279,134 @@ interface ResolvedE2BConfig {
|
|
|
187
279
|
defaultTimeoutMs?: number;
|
|
188
280
|
templateId?: string;
|
|
189
281
|
}
|
|
282
|
+
declare class E2BCommands implements SandboxCommands {
|
|
283
|
+
private sandbox;
|
|
284
|
+
private defaultUser?;
|
|
285
|
+
constructor(sandbox: Sandbox, defaultUser?: string | undefined);
|
|
286
|
+
run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
|
|
287
|
+
spawn(command: string, options?: SandboxSpawnOptions): Promise<SandboxCommandHandle>;
|
|
288
|
+
list(): Promise<ProcessInfo[]>;
|
|
289
|
+
connect(processId: string, options?: SandboxConnectOptions): Promise<SandboxCommandHandle>;
|
|
290
|
+
sendStdin(processId: string, data: string): Promise<void>;
|
|
291
|
+
kill(processId: string): Promise<boolean>;
|
|
292
|
+
}
|
|
293
|
+
declare class E2BFiles implements SandboxFiles {
|
|
294
|
+
private sandbox;
|
|
295
|
+
private defaultUser?;
|
|
296
|
+
constructor(sandbox: Sandbox, defaultUser?: string | undefined);
|
|
297
|
+
read(path: string): Promise<string | Uint8Array>;
|
|
298
|
+
write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
|
|
299
|
+
writeBatch(files: Array<{
|
|
300
|
+
path: string;
|
|
301
|
+
data: string | Buffer | ArrayBuffer | Uint8Array;
|
|
302
|
+
}>): Promise<void>;
|
|
303
|
+
makeDir(path: string): Promise<void>;
|
|
304
|
+
uploadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
305
|
+
downloadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
306
|
+
exists(path: string): Promise<boolean>;
|
|
307
|
+
list(path: string): Promise<FileInfo[]>;
|
|
308
|
+
remove(path: string): Promise<void>;
|
|
309
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
310
|
+
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
311
|
+
writeStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Upload a local file by PATH, streamed off disk with real backpressure.
|
|
314
|
+
*
|
|
315
|
+
* Why this does NOT go through files.write(): that method calls
|
|
316
|
+
* `new Response(data).blob()` on whatever it is given, which MATERIALIZES the
|
|
317
|
+
* body — measured at +463 MB RSS for a 200 MB source, whether the input is a
|
|
318
|
+
* stream, a Buffer, or even a file-backed Blob. So handing it a stream looks
|
|
319
|
+
* like streaming and is not, which is precisely the trap this method exists to
|
|
320
|
+
* avoid: a caller uploading a large artifact once per concurrent task would
|
|
321
|
+
* still pay the full size every time.
|
|
322
|
+
*
|
|
323
|
+
* Instead the multipart body is assembled as a ReadableStream and POSTed to
|
|
324
|
+
* the signed upload URL with `duplex: "half"` — the same shape E2B's own
|
|
325
|
+
* template-context upload uses. Verified to hold backpressure: against a
|
|
326
|
+
* deliberately slow sink the producer had read 7 MB of a 200 MB file after
|
|
327
|
+
* four seconds, rather than racing to the end.
|
|
328
|
+
*
|
|
329
|
+
* The wire format mirrors files.write()'s single-file case exactly: the
|
|
330
|
+
* destination is the `path` query parameter of the signed URL, and the body is
|
|
331
|
+
* one `file` part. If E2B ever changes that, the POST fails and we fall back to
|
|
332
|
+
* the SDK's own (buffering) path — a correct upload beats a cheap one.
|
|
333
|
+
*/
|
|
334
|
+
writeFromPath(sandboxPath: string, localPath: string): Promise<void>;
|
|
335
|
+
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, options?: WatchOptions): Promise<WatchHandle>;
|
|
336
|
+
}
|
|
190
337
|
declare class E2BProvider implements SandboxProvider {
|
|
191
338
|
readonly providerType: "e2b";
|
|
339
|
+
readonly name = "E2B";
|
|
192
340
|
private readonly apiKey;
|
|
193
341
|
private readonly apiUrl?;
|
|
194
342
|
private readonly defaultTimeoutMs;
|
|
195
343
|
private readonly templateId?;
|
|
344
|
+
/**
|
|
345
|
+
* Sandbox user configured at create time, reapplied on connect() (e.g., resume).
|
|
346
|
+
* In-memory only: a connect() from a fresh process runs as the template default
|
|
347
|
+
* user — callers reconnecting across processes must recreate the provider config
|
|
348
|
+
* with the same user, or operations on user-owned files fail loudly.
|
|
349
|
+
*/
|
|
350
|
+
private readonly sandboxUsers;
|
|
196
351
|
constructor(config: ResolvedE2BConfig);
|
|
197
352
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
198
353
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
354
|
+
/**
|
|
355
|
+
* List sandboxes, walking every page.
|
|
356
|
+
*
|
|
357
|
+
* This used to call `nextItems()` exactly once and return whatever the first
|
|
358
|
+
* page held — an account with more than E2B_MAX_PAGE_SIZE sandboxes was
|
|
359
|
+
* silently truncated, and nothing in the return value said so. That is a
|
|
360
|
+
* correctness bug rather than a performance one for any caller that reads
|
|
361
|
+
* absence from the list as "this sandbox is gone".
|
|
362
|
+
*
|
|
363
|
+
* `limit` still means what a caller expects: stop after this many ITEMS, so
|
|
364
|
+
* an explicit limit remains a cost bound. The per-request page size is capped
|
|
365
|
+
* separately at E2B_MAX_PAGE_SIZE because E2B rejects anything larger
|
|
366
|
+
* outright (`400 validation error: parameter "limit" ... must be at most
|
|
367
|
+
* 100`), so a caller asking for 500 gets five requests, not one refusal.
|
|
368
|
+
*/
|
|
199
369
|
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
370
|
+
/**
|
|
371
|
+
* The fleet-bookkeeping enumeration: same walk, never throws.
|
|
372
|
+
*
|
|
373
|
+
* The distinction from `list()` is what a failure MEANS to the caller. An
|
|
374
|
+
* orphan sweep treats a missing sandbox as a terminated one, so it must be
|
|
375
|
+
* able to tell "the project has no sandboxes" from "the enumeration stopped
|
|
376
|
+
* early" — and an exception it catches and turns into an empty array erases
|
|
377
|
+
* exactly that difference.
|
|
378
|
+
*/
|
|
379
|
+
listAll(options?: SandboxListOptions): Promise<SandboxListPage>;
|
|
380
|
+
private paginate;
|
|
200
381
|
}
|
|
382
|
+
/** The paginator surface this walk needs — E2B's SandboxPaginator satisfies it. */
|
|
383
|
+
interface E2BSandboxPaginator {
|
|
384
|
+
readonly hasNext: boolean;
|
|
385
|
+
readonly nextToken?: string;
|
|
386
|
+
nextItems(): Promise<Array<{
|
|
387
|
+
sandboxId: string;
|
|
388
|
+
templateId: string;
|
|
389
|
+
name?: string;
|
|
390
|
+
metadata?: Record<string, string>;
|
|
391
|
+
startedAt: unknown;
|
|
392
|
+
endAt?: unknown;
|
|
393
|
+
}>>;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Drain a paginator into one answer, with an honest completeness verdict.
|
|
397
|
+
*
|
|
398
|
+
* Separate from the provider because everything worth getting wrong lives here
|
|
399
|
+
* and none of it needs a network: the two ways a walk can fail to terminate,
|
|
400
|
+
* the difference between "the caller asked for ten" and "the provider ran out",
|
|
401
|
+
* and the rule that a failure mid-walk yields the sandboxes seen so far marked
|
|
402
|
+
* INCOMPLETE rather than either an exception or a short complete list.
|
|
403
|
+
*
|
|
404
|
+
* Exported for its test (`_testCollectSandboxPages`).
|
|
405
|
+
*/
|
|
406
|
+
declare function collectSandboxPages(paginator: E2BSandboxPaginator, wanted?: number): Promise<SandboxListPage & {
|
|
407
|
+
stoppedAtLimit: boolean;
|
|
408
|
+
}>;
|
|
409
|
+
declare const _testCollectSandboxPages: typeof collectSandboxPages;
|
|
201
410
|
/**
|
|
202
411
|
* Create E2B sandbox provider.
|
|
203
412
|
*
|
|
@@ -206,4 +415,4 @@ declare class E2BProvider implements SandboxProvider {
|
|
|
206
415
|
*/
|
|
207
416
|
declare function createE2BProvider(config?: E2BConfig): SandboxProvider;
|
|
208
417
|
|
|
209
|
-
export { type E2BConfig, E2BProvider, type FileInfo, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxConnectOptions, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxProvider, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, createE2BProvider };
|
|
418
|
+
export { E2BCommands, type E2BConfig, E2BFiles, E2BIdleTimeoutError, E2BProvider, E2BResourcesError, type E2BSandboxPaginator, E2B_MAX_LIST_PAGES, E2B_MAX_PAGE_SIZE, type FileInfo, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxConnectOptions, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxListPage, type SandboxProvider, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, _testCollectSandboxPages, createE2BProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Sandbox } from '@e2b/code-interpreter';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* E2B Sandbox Provider - Clean Architecture
|
|
3
5
|
*
|
|
@@ -11,6 +13,40 @@
|
|
|
11
13
|
* - Configuration externalized (no hardcoded mappings)
|
|
12
14
|
* - Clear naming (run = blocking, spawn = background)
|
|
13
15
|
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Largest page E2B will serve. Not a taste choice — a larger `limit` is refused
|
|
19
|
+
* outright: `400 validation error: parameter "limit" in query has an error:
|
|
20
|
+
* number must be at most 100`.
|
|
21
|
+
*/
|
|
22
|
+
declare const E2B_MAX_PAGE_SIZE = 100;
|
|
23
|
+
/**
|
|
24
|
+
* Page ceiling for one enumeration — 10,000 sandboxes at the maximum page size.
|
|
25
|
+
* A walk that reaches it stops and reports itself INCOMPLETE, because the one
|
|
26
|
+
* thing a fleet enumeration may never do is return a short list that reads like
|
|
27
|
+
* a whole one.
|
|
28
|
+
*/
|
|
29
|
+
declare const E2B_MAX_LIST_PAGES = 100;
|
|
30
|
+
/**
|
|
31
|
+
* Typed error for create-time sizing requests E2B cannot enforce.
|
|
32
|
+
* E2B sandboxes inherit cpu/memory from their TEMPLATE (Template.build
|
|
33
|
+
* cpuCount/memoryMB; disk is plan-fixed) — Sandbox.create has no sizing
|
|
34
|
+
* parameters, so a `resources` request would be silently ignored. Per the
|
|
35
|
+
* provider law (reject what you cannot enforce) it is refused loudly here.
|
|
36
|
+
*/
|
|
37
|
+
declare class E2BResourcesError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Typed error for an idle timeout E2B cannot enforce. E2B has exactly one
|
|
42
|
+
* clock and it is absolute: the sandbox is killed when its timeout expires,
|
|
43
|
+
* and only explicit client calls (create, connect, setTimeout) move that
|
|
44
|
+
* deadline — never what the sandbox is or is not doing. An `idleTimeoutMs`
|
|
45
|
+
* would therefore be silently ignored, so it is refused instead.
|
|
46
|
+
*/
|
|
47
|
+
declare class E2BIdleTimeoutError extends Error {
|
|
48
|
+
constructor();
|
|
49
|
+
}
|
|
14
50
|
/** Result of a completed sandbox command */
|
|
15
51
|
interface SandboxCommandResult {
|
|
16
52
|
exitCode: number;
|
|
@@ -85,11 +121,47 @@ interface SandboxConnectOptions {
|
|
|
85
121
|
}
|
|
86
122
|
/** Options for creating a sandbox */
|
|
87
123
|
interface SandboxCreateOptions {
|
|
88
|
-
|
|
124
|
+
/**
|
|
125
|
+
* E2B template ID. OPTIONAL: create() falls back to the provider's
|
|
126
|
+
* configured `templateId`, then to "evolve-all" — declaring it required
|
|
127
|
+
* contradicted that implementation and only went unnoticed because TS
|
|
128
|
+
* method parameters are bivariant, so the SDK could already call
|
|
129
|
+
* create({}) through the shared contract.
|
|
130
|
+
*/
|
|
131
|
+
image?: string;
|
|
89
132
|
envs?: Record<string, string>;
|
|
90
133
|
metadata?: Record<string, string>;
|
|
91
134
|
timeoutMs?: number;
|
|
135
|
+
/**
|
|
136
|
+
* REJECTED with E2BIdleTimeoutError. E2B's timeout is an ABSOLUTE lifetime
|
|
137
|
+
* that in-sandbox activity never extends, so there is no inactivity clock to
|
|
138
|
+
* map this onto and honouring it would be a lie.
|
|
139
|
+
*/
|
|
140
|
+
idleTimeoutMs?: number;
|
|
92
141
|
workingDirectory?: string;
|
|
142
|
+
/**
|
|
143
|
+
* Per-sandbox compute sizing (cpu cores, memory GiB, disk GiB). E2B sizes
|
|
144
|
+
* sandboxes at TEMPLATE BUILD time only (Template.build cpuCount/memoryMB;
|
|
145
|
+
* disk is plan-fixed) — create-time sizing cannot be enforced, so any value
|
|
146
|
+
* here is REJECTED with E2BResourcesError rather than silently ignored.
|
|
147
|
+
* Bake sizing into the template the `image` names instead. `gpu`/`gpuTypes`
|
|
148
|
+
* are rejected the same way: e2b offers no GPU allocation at any tier.
|
|
149
|
+
*/
|
|
150
|
+
resources?: {
|
|
151
|
+
cpu?: number;
|
|
152
|
+
memory?: number;
|
|
153
|
+
disk?: number;
|
|
154
|
+
gpu?: number;
|
|
155
|
+
gpuTypes?: string[];
|
|
156
|
+
};
|
|
157
|
+
network?: {
|
|
158
|
+
outbound: "open" | "blocked";
|
|
159
|
+
allowedDestinations?: string[];
|
|
160
|
+
};
|
|
161
|
+
/** Run all commands and file operations as this user (passed on every E2B operation that supports it). */
|
|
162
|
+
user?: string;
|
|
163
|
+
/** Home directory used by the SDK for agent config paths; not consumed by the provider. */
|
|
164
|
+
homeDir?: string;
|
|
93
165
|
}
|
|
94
166
|
/** Options for listing sandboxes */
|
|
95
167
|
interface SandboxListOptions {
|
|
@@ -97,6 +169,20 @@ interface SandboxListOptions {
|
|
|
97
169
|
metadata?: Record<string, string>;
|
|
98
170
|
limit?: number;
|
|
99
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* A COMPLETE (or admittedly incomplete) enumeration of the project's fleet.
|
|
174
|
+
*
|
|
175
|
+
* `complete` is the load-bearing field. Callers that need a whole fleet —
|
|
176
|
+
* orphan sweeps, lifecycle reconciliation — read a sandbox's ABSENCE from the
|
|
177
|
+
* list as evidence it is gone, so a truncated page and a small fleet must never
|
|
178
|
+
* be the same answer. `complete: false` means leave every row alone.
|
|
179
|
+
*/
|
|
180
|
+
interface SandboxListPage {
|
|
181
|
+
sandboxes: SandboxInfo[];
|
|
182
|
+
complete: boolean;
|
|
183
|
+
pagesFetched: number;
|
|
184
|
+
error?: string;
|
|
185
|
+
}
|
|
100
186
|
/** Command execution capabilities */
|
|
101
187
|
interface SandboxCommands {
|
|
102
188
|
/** Run command and wait for completion */
|
|
@@ -127,6 +213,8 @@ interface SandboxFiles {
|
|
|
127
213
|
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
128
214
|
/** Write from stream */
|
|
129
215
|
writeStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
216
|
+
/** Upload a local file by path, streamed off disk (never buffered whole) */
|
|
217
|
+
writeFromPath(sandboxPath: string, localPath: string): Promise<void>;
|
|
130
218
|
/** Get pre-signed upload URL for large files (expiration in seconds) */
|
|
131
219
|
uploadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
132
220
|
/** Get pre-signed download URL for large files (expiration in seconds) */
|
|
@@ -164,12 +252,16 @@ interface SandboxInstance {
|
|
|
164
252
|
interface SandboxProvider {
|
|
165
253
|
/** Provider type identifier */
|
|
166
254
|
readonly providerType: string;
|
|
255
|
+
/** Human-readable provider name for logging */
|
|
256
|
+
readonly name?: string;
|
|
167
257
|
/** Create new sandbox */
|
|
168
258
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
169
259
|
/** Connect to existing sandbox */
|
|
170
260
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
171
|
-
/** List sandboxes
|
|
261
|
+
/** List sandboxes, paginating to exhaustion. `limit` bounds items returned. */
|
|
172
262
|
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
263
|
+
/** The same enumeration for fleet bookkeeping: never throws, reports completeness. */
|
|
264
|
+
listAll(options?: SandboxListOptions): Promise<SandboxListPage>;
|
|
173
265
|
}
|
|
174
266
|
interface E2BConfig {
|
|
175
267
|
/** E2B API key. Default: reads from E2B_API_KEY env var */
|
|
@@ -187,17 +279,134 @@ interface ResolvedE2BConfig {
|
|
|
187
279
|
defaultTimeoutMs?: number;
|
|
188
280
|
templateId?: string;
|
|
189
281
|
}
|
|
282
|
+
declare class E2BCommands implements SandboxCommands {
|
|
283
|
+
private sandbox;
|
|
284
|
+
private defaultUser?;
|
|
285
|
+
constructor(sandbox: Sandbox, defaultUser?: string | undefined);
|
|
286
|
+
run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
|
|
287
|
+
spawn(command: string, options?: SandboxSpawnOptions): Promise<SandboxCommandHandle>;
|
|
288
|
+
list(): Promise<ProcessInfo[]>;
|
|
289
|
+
connect(processId: string, options?: SandboxConnectOptions): Promise<SandboxCommandHandle>;
|
|
290
|
+
sendStdin(processId: string, data: string): Promise<void>;
|
|
291
|
+
kill(processId: string): Promise<boolean>;
|
|
292
|
+
}
|
|
293
|
+
declare class E2BFiles implements SandboxFiles {
|
|
294
|
+
private sandbox;
|
|
295
|
+
private defaultUser?;
|
|
296
|
+
constructor(sandbox: Sandbox, defaultUser?: string | undefined);
|
|
297
|
+
read(path: string): Promise<string | Uint8Array>;
|
|
298
|
+
write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
|
|
299
|
+
writeBatch(files: Array<{
|
|
300
|
+
path: string;
|
|
301
|
+
data: string | Buffer | ArrayBuffer | Uint8Array;
|
|
302
|
+
}>): Promise<void>;
|
|
303
|
+
makeDir(path: string): Promise<void>;
|
|
304
|
+
uploadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
305
|
+
downloadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
306
|
+
exists(path: string): Promise<boolean>;
|
|
307
|
+
list(path: string): Promise<FileInfo[]>;
|
|
308
|
+
remove(path: string): Promise<void>;
|
|
309
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
310
|
+
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
311
|
+
writeStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Upload a local file by PATH, streamed off disk with real backpressure.
|
|
314
|
+
*
|
|
315
|
+
* Why this does NOT go through files.write(): that method calls
|
|
316
|
+
* `new Response(data).blob()` on whatever it is given, which MATERIALIZES the
|
|
317
|
+
* body — measured at +463 MB RSS for a 200 MB source, whether the input is a
|
|
318
|
+
* stream, a Buffer, or even a file-backed Blob. So handing it a stream looks
|
|
319
|
+
* like streaming and is not, which is precisely the trap this method exists to
|
|
320
|
+
* avoid: a caller uploading a large artifact once per concurrent task would
|
|
321
|
+
* still pay the full size every time.
|
|
322
|
+
*
|
|
323
|
+
* Instead the multipart body is assembled as a ReadableStream and POSTed to
|
|
324
|
+
* the signed upload URL with `duplex: "half"` — the same shape E2B's own
|
|
325
|
+
* template-context upload uses. Verified to hold backpressure: against a
|
|
326
|
+
* deliberately slow sink the producer had read 7 MB of a 200 MB file after
|
|
327
|
+
* four seconds, rather than racing to the end.
|
|
328
|
+
*
|
|
329
|
+
* The wire format mirrors files.write()'s single-file case exactly: the
|
|
330
|
+
* destination is the `path` query parameter of the signed URL, and the body is
|
|
331
|
+
* one `file` part. If E2B ever changes that, the POST fails and we fall back to
|
|
332
|
+
* the SDK's own (buffering) path — a correct upload beats a cheap one.
|
|
333
|
+
*/
|
|
334
|
+
writeFromPath(sandboxPath: string, localPath: string): Promise<void>;
|
|
335
|
+
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, options?: WatchOptions): Promise<WatchHandle>;
|
|
336
|
+
}
|
|
190
337
|
declare class E2BProvider implements SandboxProvider {
|
|
191
338
|
readonly providerType: "e2b";
|
|
339
|
+
readonly name = "E2B";
|
|
192
340
|
private readonly apiKey;
|
|
193
341
|
private readonly apiUrl?;
|
|
194
342
|
private readonly defaultTimeoutMs;
|
|
195
343
|
private readonly templateId?;
|
|
344
|
+
/**
|
|
345
|
+
* Sandbox user configured at create time, reapplied on connect() (e.g., resume).
|
|
346
|
+
* In-memory only: a connect() from a fresh process runs as the template default
|
|
347
|
+
* user — callers reconnecting across processes must recreate the provider config
|
|
348
|
+
* with the same user, or operations on user-owned files fail loudly.
|
|
349
|
+
*/
|
|
350
|
+
private readonly sandboxUsers;
|
|
196
351
|
constructor(config: ResolvedE2BConfig);
|
|
197
352
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
198
353
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
354
|
+
/**
|
|
355
|
+
* List sandboxes, walking every page.
|
|
356
|
+
*
|
|
357
|
+
* This used to call `nextItems()` exactly once and return whatever the first
|
|
358
|
+
* page held — an account with more than E2B_MAX_PAGE_SIZE sandboxes was
|
|
359
|
+
* silently truncated, and nothing in the return value said so. That is a
|
|
360
|
+
* correctness bug rather than a performance one for any caller that reads
|
|
361
|
+
* absence from the list as "this sandbox is gone".
|
|
362
|
+
*
|
|
363
|
+
* `limit` still means what a caller expects: stop after this many ITEMS, so
|
|
364
|
+
* an explicit limit remains a cost bound. The per-request page size is capped
|
|
365
|
+
* separately at E2B_MAX_PAGE_SIZE because E2B rejects anything larger
|
|
366
|
+
* outright (`400 validation error: parameter "limit" ... must be at most
|
|
367
|
+
* 100`), so a caller asking for 500 gets five requests, not one refusal.
|
|
368
|
+
*/
|
|
199
369
|
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
370
|
+
/**
|
|
371
|
+
* The fleet-bookkeeping enumeration: same walk, never throws.
|
|
372
|
+
*
|
|
373
|
+
* The distinction from `list()` is what a failure MEANS to the caller. An
|
|
374
|
+
* orphan sweep treats a missing sandbox as a terminated one, so it must be
|
|
375
|
+
* able to tell "the project has no sandboxes" from "the enumeration stopped
|
|
376
|
+
* early" — and an exception it catches and turns into an empty array erases
|
|
377
|
+
* exactly that difference.
|
|
378
|
+
*/
|
|
379
|
+
listAll(options?: SandboxListOptions): Promise<SandboxListPage>;
|
|
380
|
+
private paginate;
|
|
200
381
|
}
|
|
382
|
+
/** The paginator surface this walk needs — E2B's SandboxPaginator satisfies it. */
|
|
383
|
+
interface E2BSandboxPaginator {
|
|
384
|
+
readonly hasNext: boolean;
|
|
385
|
+
readonly nextToken?: string;
|
|
386
|
+
nextItems(): Promise<Array<{
|
|
387
|
+
sandboxId: string;
|
|
388
|
+
templateId: string;
|
|
389
|
+
name?: string;
|
|
390
|
+
metadata?: Record<string, string>;
|
|
391
|
+
startedAt: unknown;
|
|
392
|
+
endAt?: unknown;
|
|
393
|
+
}>>;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Drain a paginator into one answer, with an honest completeness verdict.
|
|
397
|
+
*
|
|
398
|
+
* Separate from the provider because everything worth getting wrong lives here
|
|
399
|
+
* and none of it needs a network: the two ways a walk can fail to terminate,
|
|
400
|
+
* the difference between "the caller asked for ten" and "the provider ran out",
|
|
401
|
+
* and the rule that a failure mid-walk yields the sandboxes seen so far marked
|
|
402
|
+
* INCOMPLETE rather than either an exception or a short complete list.
|
|
403
|
+
*
|
|
404
|
+
* Exported for its test (`_testCollectSandboxPages`).
|
|
405
|
+
*/
|
|
406
|
+
declare function collectSandboxPages(paginator: E2BSandboxPaginator, wanted?: number): Promise<SandboxListPage & {
|
|
407
|
+
stoppedAtLimit: boolean;
|
|
408
|
+
}>;
|
|
409
|
+
declare const _testCollectSandboxPages: typeof collectSandboxPages;
|
|
201
410
|
/**
|
|
202
411
|
* Create E2B sandbox provider.
|
|
203
412
|
*
|
|
@@ -206,4 +415,4 @@ declare class E2BProvider implements SandboxProvider {
|
|
|
206
415
|
*/
|
|
207
416
|
declare function createE2BProvider(config?: E2BConfig): SandboxProvider;
|
|
208
417
|
|
|
209
|
-
export { type E2BConfig, E2BProvider, type FileInfo, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxConnectOptions, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxProvider, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, createE2BProvider };
|
|
418
|
+
export { E2BCommands, type E2BConfig, E2BFiles, E2BIdleTimeoutError, E2BProvider, E2BResourcesError, type E2BSandboxPaginator, E2B_MAX_LIST_PAGES, E2B_MAX_PAGE_SIZE, type FileInfo, type FilesystemEvent, type ProcessInfo, type SandboxCommandHandle, type SandboxCommandResult, type SandboxCommands, type SandboxConnectOptions, type SandboxCreateOptions, type SandboxFiles, type SandboxInfo, type SandboxInstance, type SandboxListOptions, type SandboxListPage, type SandboxProvider, type SandboxRunOptions, type SandboxSpawnOptions, type WatchHandle, type WatchOptions, _testCollectSandboxPages, createE2BProvider };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import {Sandbox}from'@e2b/code-interpreter';
|
|
2
|
-
|
|
1
|
+
import {Sandbox}from'@e2b/code-interpreter';function g(s){if(!s||typeof s!="object")return false;if(s.name==="TimeoutError")return true;let e=s.message;return typeof e=="string"&&/timed?\s*out/i.test(e)}var P=100,v=100;function u(s){return s instanceof Date?s.toISOString():String(s)}function A(s){if(typeof s=="string"||s instanceof ArrayBuffer)return s;if(s instanceof Buffer)return new Uint8Array(s).buffer;if(s instanceof Uint8Array)return new Uint8Array(s).buffer;throw new Error(`Unsupported data type for file upload: ${typeof s}. Expected string, Buffer, ArrayBuffer, or Uint8Array.`)}var l=class extends Error{constructor(e){super(e),this.name="E2BResourcesError";}},b=class extends Error{constructor(){super("E2B has no idle timeout: its sandbox timeout is an ABSOLUTE lifetime that in-sandbox activity never extends. Use `timeoutMs` for the lifetime, and call setTimeout() to extend a sandbox you know is still working."),this.name="E2BIdleTimeoutError";}},x=class{constructor(e,t){this.sandbox=e;this.defaultUser=t;}async run(e,t){try{let r=await this.sandbox.commands.run(e,{timeoutMs:t?.timeoutMs,envs:t?.envs,cwd:t?.cwd,user:this.defaultUser,onStdout:t?.onStdout,onStderr:t?.onStderr});return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let n=r;return {exitCode:n.exitCode,stdout:n.stdout??"",stderr:n.stderr??""}}if(g(r))return {exitCode:124,stdout:"",stderr:r instanceof Error?r.message:"command timed out"};throw r}}async spawn(e,t){let r=await this.sandbox.commands.run(e,{background:true,stdin:t?.stdin??true,timeoutMs:t?.timeoutMs,envs:t?.envs,cwd:t?.cwd,user:this.defaultUser,onStdout:t?.onStdout,onStderr:t?.onStderr});return {processId:String(r.pid),wait:async()=>{try{let n=await r.wait();return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let i=n;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}if(g(n))return {exitCode:124,stdout:"",stderr:n instanceof Error?n.message:"command timed out"};throw n}},kill:()=>this.sandbox.commands.kill(r.pid)}}async list(){return (await this.sandbox.commands.list()).map(t=>({...t,processId:String(t.pid)}))}async connect(e,t){let r=await this.sandbox.commands.connect(Number(e),{onStdout:t?.onStdout,onStderr:t?.onStderr,timeoutMs:t?.timeoutMs});return {processId:String(r.pid),wait:async()=>{try{let n=await r.wait();return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let i=n;return {exitCode:i.exitCode,stdout:i.stdout??"",stderr:i.stderr??""}}if(g(n))return {exitCode:124,stdout:"",stderr:n instanceof Error?n.message:"command timed out"};throw n}},kill:()=>this.sandbox.commands.kill(r.pid)}}async sendStdin(e,t){await this.sandbox.commands.sendStdin(Number(e),t);}async kill(e){return this.sandbox.commands.kill(Number(e))}},h=class{constructor(e,t){this.sandbox=e;this.defaultUser=t;}async read(e){let t=await this.sandbox.files.read(e,{format:"bytes",requestTimeoutMs:3e5,user:this.defaultUser});if(!t.includes(0))try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(t)}catch{}return t}async write(e,t){await this.sandbox.files.write(e,A(t),{requestTimeoutMs:3e5,user:this.defaultUser});}async writeBatch(e){let t=e.map(r=>({path:r.path,data:A(r.data)}));await this.sandbox.files.write(t,{requestTimeoutMs:3e5,user:this.defaultUser});}async makeDir(e){await this.sandbox.files.makeDir(e,{user:this.defaultUser});}async uploadUrl(e,t){return this.sandbox.uploadUrl(e,{user:this.defaultUser,...t?{useSignatureExpiration:t}:{}})}async downloadUrl(e,t){return this.sandbox.downloadUrl(e,{user:this.defaultUser,...t?{useSignatureExpiration:t}:{}})}async exists(e){return this.sandbox.files.exists(e,{user:this.defaultUser})}async list(e){return (await this.sandbox.files.list(e,{user:this.defaultUser})).map(r=>({name:r.name,path:r.path,type:r.type==="dir"?"dir":"file"}))}async remove(e){await this.sandbox.files.remove(e,{user:this.defaultUser});}async rename(e,t){await this.sandbox.files.rename(e,t,{user:this.defaultUser});}async readStream(e){return this.sandbox.files.read(e,{format:"stream",user:this.defaultUser})}async writeStream(e,t){await this.sandbox.files.write(e,t,{user:this.defaultUser});}async writeFromPath(e,t){let{createReadStream:r,statSync:n}=await import('fs'),{Readable:i}=await import('stream'),{randomBytes:o}=await import('crypto'),a=n(t).size,f=`----evolve${o(16).toString("hex")}`,w=Buffer.from(`--${f}\r
|
|
2
|
+
Content-Disposition: form-data; name="file"; filename="blob"\r
|
|
3
|
+
Content-Type: application/octet-stream\r
|
|
4
|
+
\r
|
|
5
|
+
`),S=Buffer.from(`\r
|
|
6
|
+
--${f}--\r
|
|
7
|
+
`);async function*I(){yield w;for await(let d of r(t))yield d;yield S;}try{let d=await this.uploadUrl(e),m=await fetch(d,{method:"POST",body:i.toWeb(i.from(I())),headers:{"Content-Type":`multipart/form-data; boundary=${f}`,"Content-Length":String(w.length+a+S.length)},duplex:"half"});if(!m.ok)throw new Error(`streamed upload to ${e} failed (HTTP ${m.status})`)}catch(d){console.warn(`[e2b] streamed upload of ${t} failed, falling back to a buffered write:`,d instanceof Error?d.message:d);let m=i.toWeb(r(t));await this.writeStream(e,m);}}async watchDir(e,t,r){let n=await this.sandbox.files.watchDir(e,t,{recursive:r?.recursive,timeoutMs:r?.timeoutMs,user:this.defaultUser,onExit:r?.onExit});return {stop:()=>n.stop()}}},c=class{constructor(e,t,r,n){this.sandbox=e;this.apiKey=t;this.apiUrl=r;this.commands=new x(e,n),this.files=new h(e,n);}commands;files;get sandboxId(){return this.sandbox.sandboxId}getHost(e){return Promise.resolve(this.sandbox.getHost(e))}async isRunning(){return this.sandbox.isRunning()}async getInfo(){let e=await this.sandbox.getInfo();return {sandboxId:e.sandboxId,image:e.templateId,name:e.name,metadata:e.metadata??{},startedAt:u(e.startedAt),endAt:e.endAt?u(e.endAt):void 0}}async kill(){try{await this.sandbox.kill();}catch{await new Promise(e=>setTimeout(e,500)),await this.sandbox.kill();}}async pause(){await this.sandbox.betaPause({apiKey:this.apiKey,apiUrl:this.apiUrl});}},y=class{providerType="e2b";name="E2B";apiKey;apiUrl;defaultTimeoutMs;templateId;sandboxUsers=new Map;constructor(e){this.apiKey=e.apiKey,this.apiUrl=e.apiUrl,this.defaultTimeoutMs=e.defaultTimeoutMs??36e5,this.templateId=e.templateId;}async create(e){if(e.idleTimeoutMs!==void 0)throw new b;if(e.resources?.gpu!==void 0||e.resources?.gpuTypes!==void 0)throw new l("E2B offers no GPU allocation at any tier \u2014 a `resources.gpu` request cannot be enforced. Run GPU workloads on a provider that reserves GPUs (modal).");if(e.resources&&(e.resources.cpu!==void 0||e.resources.memory!==void 0||e.resources.disk!==void 0))throw new l("E2B cannot size a sandbox at create time: sizing is fixed by the template (Template.build cpuCount/memoryMB; disk is plan-fixed). Build a template with the desired resources and pass it as `image` instead of `resources`.");let t=e.timeoutMs??this.defaultTimeoutMs,r=e.image??this.templateId??"evolve-all";if(e.network?.outbound==="open"&&e.network.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");let n=e.network?.allowedDestinations??[],i=e.network?.outbound==="blocked"&&n.length>0,o=await Sandbox.create(r,{apiKey:this.apiKey,apiUrl:this.apiUrl,envs:e.envs,metadata:e.metadata,timeoutMs:t,allowInternetAccess:e.network?.outbound!=="blocked"||i,network:i?{denyOut:["0.0.0.0/0"],allowOut:n}:void 0});return e.workingDirectory&&await o.files.makeDir(e.workingDirectory,{user:e.user}),e.user&&this.sandboxUsers.set(o.sandboxId,e.user),new c(o,this.apiKey,this.apiUrl,e.user)}async connect(e,t){let r=await Sandbox.connect(e,{apiKey:this.apiKey,apiUrl:this.apiUrl,timeoutMs:t??this.defaultTimeoutMs});return new c(r,this.apiKey,this.apiUrl,this.sandboxUsers.get(e))}async list(e){let t=await this.paginate(e);if(t.error&&!t.stoppedAtLimit)throw new Error(t.error);return t.sandboxes}async listAll(e){let{stoppedAtLimit:t,...r}=await this.paginate(e);return r}async paginate(e){let t=e?.limit;return U(Sandbox.list({apiKey:this.apiKey,apiUrl:this.apiUrl,query:{state:e?.state,metadata:e?.metadata},limit:t===void 0?P:Math.min(t,P)}),t)}};async function U(s,e){let t=[],r=0,n=new Set;for(;s.hasNext;){if(r>=v)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list exceeded ${v} pages`};let i=s.nextToken;if(i!==void 0){if(n.has(i))return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:"pagination token repeated"};n.add(i);}let o;try{o=await s.nextItems();}catch(a){return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list failed: ${a instanceof Error?a.message:String(a)}`}}r+=1;for(let a of o){if(e!==void 0&&t.length>=e)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:true,error:`stopped at the requested limit of ${e} with more sandboxes available`};t.push({sandboxId:a.sandboxId,image:a.templateId,name:a.name,metadata:a.metadata??{},startedAt:u(a.startedAt),endAt:a.endAt?u(a.endAt):void 0});}if(e!==void 0&&t.length>=e&&s.hasNext)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:true,error:`stopped at the requested limit of ${e} with more sandboxes available`};if(e!==void 0&&t.length>=e)break}return {sandboxes:t,complete:true,pagesFetched:r,stoppedAtLimit:false}}var E=U;function C(s={}){let e=s.apiKey??process.env.E2B_API_KEY;if(!e)throw new Error("E2B API key required. Set E2B_API_KEY environment variable or pass apiKey in config. Get your key at https://e2b.dev/sign-in");return new y({...s,apiKey:e})}
|
|
8
|
+
export{x as E2BCommands,h as E2BFiles,b as E2BIdleTimeoutError,y as E2BProvider,l as E2BResourcesError,v as E2B_MAX_LIST_PAGES,P as E2B_MAX_PAGE_SIZE,E as _testCollectSandboxPages,C as createE2BProvider};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evolvingmachines/e2b",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.52-berth-day-one.20260814.110f525",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ai",
|
|
6
6
|
"agents",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup --minify",
|
|
34
34
|
"dev": "tsup --watch",
|
|
35
|
-
"type-check": "tsc --noEmit"
|
|
35
|
+
"type-check": "tsc --noEmit",
|
|
36
|
+
"test:unit": "tsx tests/unit/e2b-list-pagination.test.ts && tsx tests/unit/e2b-files-read.test.ts && tsx tests/unit/e2b-gpu-rejection.test.ts"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"@e2b/code-interpreter": "^2.0.1"
|