@evolvingmachines/e2b 0.0.59-train-2026-09-16-fs.20260917.41a409fa → 0.0.60
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/dist/index.cjs +5 -5
- package/dist/index.d.cts +13 -91
- package/dist/index.d.ts +13 -91
- package/dist/index.js +5 -5
- package/package.json +3 -4
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use strict';var codeInterpreter=require('@e2b/code-interpreter')
|
|
1
|
+
'use strict';var codeInterpreter=require('@e2b/code-interpreter');function b(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 k=100,I=100;function u(s){return s instanceof Date?s.toISOString():String(s)}function U(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="2.25.0",g=class extends Error{constructor(e){super(e),this.name="E2BNetworkUpdateUnsupportedError";}};function x(s){if(s?.outbound==="open"&&s.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");let e=s?.allowedDestinations??[],t=s?.outbound==="blocked"&&e.length>0;return {allowInternetAccess:s?.outbound!=="blocked"||t,network:t?{denyOut:["0.0.0.0/0"],allowOut:e}:void 0}}var h=class extends Error{constructor(){super("E2B takes no create-time boot command: the sandbox boots its template's own init, and a start command is a template-BUILD field (Template startCmd) this provider never sets. The boot is already inert \u2014 run the process by exec after create, or bake it into the template the `image` names."),this.name="E2BBootCommandError";}},y=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";}},w=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(b(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(b(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(b(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))}},S=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,U(t),{requestTimeoutMs:3e5,user:this.defaultUser});}async writeBatch(e){let t=e.map(r=>({path:r.path,data:U(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:d}=await import('crypto'),a=n(t).size,p=`----evolve${d(16).toString("hex")}`,v=Buffer.from(`--${p}\r
|
|
2
2
|
Content-Disposition: form-data; name="file"; filename="blob"\r
|
|
3
3
|
Content-Type: application/octet-stream\r
|
|
4
4
|
\r
|
|
5
|
-
`),
|
|
6
|
-
--${
|
|
7
|
-
`);async function*
|
|
8
|
-
exports.E2BBootCommandError=
|
|
5
|
+
`),A=Buffer.from(`\r
|
|
6
|
+
--${p}--\r
|
|
7
|
+
`);async function*C(){yield v;for await(let o of r(t))yield o;yield A;}try{let o=await this.uploadUrl(e),m=await fetch(o,{method:"POST",body:i.toWeb(i.from(C())),headers:{"Content-Type":`multipart/form-data; boundary=${p}`,"Content-Length":String(v.length+a+A.length)},duplex:"half"});if(!m.ok)throw new Error(`streamed upload to ${e} failed (HTTP ${m.status})`)}catch(o){console.warn(`[e2b] streamed upload of ${t} failed, falling back to a buffered write:`,o instanceof Error?o.message:o);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 w(e,n),this.files=new S(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 updateNetwork(e){let t=x(e),r=this.sandbox;if(typeof r.updateNetwork!="function")throw new g(`The installed e2b client cannot change a running sandbox's network policy: Sandbox.updateNetwork requires e2b >= ${B}. Upgrade the e2b dependency (it is pulled in by @e2b/code-interpreter), or create the sandbox with the policy it needs for its whole lifetime.`);await r.updateNetwork({allowInternetAccess:t.allowInternetAccess,...t.network??{}});}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});}},P=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.bootCommand!==void 0)throw new h;if(e.idleTimeoutMs!==void 0)throw new y;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";for(let d of e.phaseNetworkPolicies??[])x(d);let n=x(e.network),i=await codeInterpreter.Sandbox.create(r,{apiKey:this.apiKey,apiUrl:this.apiUrl,envs:e.envs,metadata:e.metadata,timeoutMs:t,...n});return e.workingDirectory&&await i.files.makeDir(e.workingDirectory,{user:e.user}),e.user&&this.sandboxUsers.set(i.sandboxId,e.user),new c(i,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 E(codeInterpreter.Sandbox.list({apiKey:this.apiKey,apiUrl:this.apiUrl,query:{state:e?.state,metadata:e?.metadata},limit:t===void 0?k:Math.min(t,k)}),t)}};async function E(s,e){let t=[],r=0,n=new Set;for(;s.hasNext;){if(r>=I)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list exceeded ${I} 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 d;try{d=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 d){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 T=E;function M(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 P({...s,apiKey:e})}
|
|
8
|
+
exports.E2BBootCommandError=h;exports.E2BCommands=w;exports.E2BFiles=S;exports.E2BIdleTimeoutError=y;exports.E2BNetworkUpdateUnsupportedError=g;exports.E2BProvider=P;exports.E2BResourcesError=l;exports.E2B_MAX_LIST_PAGES=I;exports.E2B_MAX_PAGE_SIZE=k;exports.E2B_MIN_UPDATE_NETWORK_VERSION=B;exports._testCollectSandboxPages=T;exports.createE2BProvider=M;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
import { Sandbox } from '@e2b/code-interpreter';
|
|
2
2
|
|
|
3
|
-
/** A capability this provider lacks: `feature` in dotted form (`files.watchDir`), `provider` type, optional `reason`. */
|
|
4
|
-
declare class SandboxFeatureUnsupportedError extends Error {
|
|
5
|
-
readonly feature: string;
|
|
6
|
-
readonly provider: string;
|
|
7
|
-
readonly reason?: string;
|
|
8
|
-
constructor(feature: string, provider: string, reason?: string);
|
|
9
|
-
}
|
|
10
|
-
/** A path the sandbox does not have — never an empty success. */
|
|
11
|
-
declare class SandboxPathNotFoundError extends Error {
|
|
12
|
-
readonly path: string;
|
|
13
|
-
readonly provider: string;
|
|
14
|
-
constructor(path: string, provider: string);
|
|
15
|
-
}
|
|
16
|
-
/** An inspect refused because the sandbox is not running; `state` is the provider's own word (`paused`, `exited with code 137`). */
|
|
17
|
-
declare class SandboxNotRunningError extends Error {
|
|
18
|
-
readonly sandboxId: string;
|
|
19
|
-
readonly provider: string;
|
|
20
|
-
readonly state: string;
|
|
21
|
-
constructor(sandboxId: string, provider: string, state: string);
|
|
22
|
-
}
|
|
23
|
-
/** True for a SandboxFeatureUnsupportedError from ANY package's copy. */
|
|
24
|
-
declare function isSandboxFeatureUnsupportedError(err: unknown): err is SandboxFeatureUnsupportedError;
|
|
25
|
-
/** True for a SandboxPathNotFoundError from ANY package's copy. */
|
|
26
|
-
declare function isSandboxPathNotFoundError(err: unknown): err is SandboxPathNotFoundError;
|
|
27
|
-
/** True for a SandboxNotRunningError from ANY package's copy. */
|
|
28
|
-
declare function isSandboxNotRunningError(err: unknown): err is SandboxNotRunningError;
|
|
29
|
-
|
|
30
3
|
/**
|
|
31
4
|
* E2B Sandbox Provider - Clean Architecture
|
|
32
5
|
*
|
|
33
|
-
* @requires @e2b/code-interpreter >=
|
|
34
|
-
* in e2b 2.10.3, the version the dashboard resolves (typings 2.10.3…2.39.0 unpacked and checked 2026-09-16)
|
|
6
|
+
* @requires @e2b/code-interpreter >= 1.0.0 or e2b >= 1.0.0
|
|
35
7
|
* @requires Node.js >= 18 (for ReadableStream support)
|
|
36
8
|
*
|
|
37
9
|
* Design principles:
|
|
@@ -138,27 +110,18 @@ interface SandboxInfo {
|
|
|
138
110
|
/** End time (undefined for running sandboxes) */
|
|
139
111
|
endAt?: string;
|
|
140
112
|
}
|
|
141
|
-
/**
|
|
113
|
+
/** File or directory entry info */
|
|
142
114
|
interface FileInfo {
|
|
143
115
|
name: string;
|
|
144
116
|
path: string;
|
|
145
|
-
type: "file" | "dir"
|
|
146
|
-
size: number;
|
|
147
|
-
mtime: string;
|
|
148
|
-
mode: string;
|
|
149
|
-
owner: string;
|
|
150
|
-
group: string;
|
|
151
|
-
target?: string;
|
|
152
|
-
}
|
|
153
|
-
/** A byte range of a file (the SDK contract's FileRange). */
|
|
154
|
-
interface FileRange {
|
|
155
|
-
offset: number;
|
|
156
|
-
length: number;
|
|
117
|
+
type: "file" | "dir";
|
|
157
118
|
}
|
|
158
|
-
/**
|
|
119
|
+
/** Filesystem event from watchDir */
|
|
159
120
|
interface FilesystemEvent {
|
|
160
|
-
path
|
|
161
|
-
|
|
121
|
+
/** Relative path to the changed file/directory */
|
|
122
|
+
name: string;
|
|
123
|
+
/** Type of filesystem operation */
|
|
124
|
+
type: "create" | "remove" | "rename" | "chmod" | "write";
|
|
162
125
|
}
|
|
163
126
|
/** Handle to stop watching a directory */
|
|
164
127
|
interface WatchHandle {
|
|
@@ -166,21 +129,9 @@ interface WatchHandle {
|
|
|
166
129
|
}
|
|
167
130
|
/** Options for watching a directory */
|
|
168
131
|
interface WatchOptions {
|
|
169
|
-
/** Also report changes in every subdirectory. Default false. */
|
|
170
132
|
recursive?: boolean;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
interface SandboxMetrics {
|
|
174
|
-
cpuPct: number;
|
|
175
|
-
memUsedMb: number;
|
|
176
|
-
memTotalMb: number;
|
|
177
|
-
diskUsedMb?: number;
|
|
178
|
-
sampledAt: string;
|
|
179
|
-
source: string;
|
|
180
|
-
}
|
|
181
|
-
/** Options for an inspect-only attach (the SDK contract's SandboxInspectOptions). */
|
|
182
|
-
interface SandboxInspectOptions {
|
|
183
|
-
user?: string;
|
|
133
|
+
timeoutMs?: number;
|
|
134
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
184
135
|
}
|
|
185
136
|
/** Options for blocking sandbox command execution */
|
|
186
137
|
interface SandboxRunOptions {
|
|
@@ -334,10 +285,6 @@ interface SandboxFiles {
|
|
|
334
285
|
remove(path: string): Promise<void>;
|
|
335
286
|
/** Rename or move file/directory */
|
|
336
287
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
337
|
-
/** The entry at `path` itself; a symlink is never followed */
|
|
338
|
-
stat(path: string): Promise<FileInfo>;
|
|
339
|
-
/** Exactly the requested bytes, without moving the whole file when the range is small */
|
|
340
|
-
readRange(path: string, range: FileRange): Promise<Uint8Array>;
|
|
341
288
|
/** Watch directory for changes */
|
|
342
289
|
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, options?: WatchOptions): Promise<WatchHandle>;
|
|
343
290
|
}
|
|
@@ -352,8 +299,6 @@ interface SandboxInstance {
|
|
|
352
299
|
isRunning(): Promise<boolean>;
|
|
353
300
|
/** Get sandbox metadata and timing */
|
|
354
301
|
getInfo(): Promise<SandboxInfo>;
|
|
355
|
-
/** The newest resource-usage sample, or null while there is none yet */
|
|
356
|
-
metrics(): Promise<SandboxMetrics | null>;
|
|
357
302
|
/** Terminate sandbox */
|
|
358
303
|
kill(): Promise<void>;
|
|
359
304
|
/** Pause sandbox (preserves state) */
|
|
@@ -371,8 +316,6 @@ interface SandboxProvider {
|
|
|
371
316
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
372
317
|
/** Connect to existing sandbox */
|
|
373
318
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
374
|
-
/** Attach to a RUNNING sandbox for reads; never resumes it, never touches its lifetime */
|
|
375
|
-
inspect(sandboxId: string, options?: SandboxInspectOptions): Promise<SandboxInstance>;
|
|
376
319
|
/** List sandboxes, paginating to exhaustion. `limit` bounds items returned. */
|
|
377
320
|
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
378
321
|
/** The same enumeration for fleet bookkeeping: never throws, reports completeness. */
|
|
@@ -408,10 +351,7 @@ declare class E2BCommands implements SandboxCommands {
|
|
|
408
351
|
declare class E2BFiles implements SandboxFiles {
|
|
409
352
|
private sandbox;
|
|
410
353
|
private defaultUser?;
|
|
411
|
-
|
|
412
|
-
/** inspect() passes the record's envd version; a created or connected sandbox reads its record once. */
|
|
413
|
-
constructor(sandbox: Sandbox, defaultUser?: string | undefined, envdVersion?: string | undefined);
|
|
414
|
-
private assertEntryInfo;
|
|
354
|
+
constructor(sandbox: Sandbox, defaultUser?: string | undefined);
|
|
415
355
|
read(path: string): Promise<string | Uint8Array>;
|
|
416
356
|
write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
|
|
417
357
|
writeBatch(files: Array<{
|
|
@@ -423,8 +363,6 @@ declare class E2BFiles implements SandboxFiles {
|
|
|
423
363
|
downloadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
424
364
|
exists(path: string): Promise<boolean>;
|
|
425
365
|
list(path: string): Promise<FileInfo[]>;
|
|
426
|
-
stat(path: string): Promise<FileInfo>;
|
|
427
|
-
readRange(path: string, range: FileRange): Promise<Uint8Array>;
|
|
428
366
|
remove(path: string): Promise<void>;
|
|
429
367
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
430
368
|
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
@@ -460,11 +398,8 @@ declare class E2BSandboxImpl implements SandboxInstance {
|
|
|
460
398
|
private apiUrl?;
|
|
461
399
|
readonly commands: SandboxCommands;
|
|
462
400
|
readonly files: SandboxFiles;
|
|
463
|
-
|
|
464
|
-
private lastMetricsAt?;
|
|
465
|
-
constructor(sandbox: Sandbox, apiKey: string, apiUrl?: string | undefined, defaultUser?: string, envdVersion?: string);
|
|
401
|
+
constructor(sandbox: Sandbox, apiKey: string, apiUrl?: string | undefined, defaultUser?: string);
|
|
466
402
|
get sandboxId(): string;
|
|
467
|
-
metrics(): Promise<SandboxMetrics | null>;
|
|
468
403
|
getHost(port: number): Promise<string>;
|
|
469
404
|
isRunning(): Promise<boolean>;
|
|
470
405
|
getInfo(): Promise<SandboxInfo>;
|
|
@@ -509,8 +444,6 @@ declare class E2BProvider implements SandboxProvider {
|
|
|
509
444
|
constructor(config: ResolvedE2BConfig);
|
|
510
445
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
511
446
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
512
|
-
inspect(sandboxId: string, options?: SandboxInspectOptions): Promise<SandboxInstance>;
|
|
513
|
-
protected fetchSandboxDetail(sandboxId: string): Promise<E2BSandboxDetail>;
|
|
514
447
|
/**
|
|
515
448
|
* List sandboxes, walking every page.
|
|
516
449
|
*
|
|
@@ -567,15 +500,6 @@ declare function collectSandboxPages(paginator: E2BSandboxPaginator, wanted?: nu
|
|
|
567
500
|
stoppedAtLimit: boolean;
|
|
568
501
|
}>;
|
|
569
502
|
declare const _testCollectSandboxPages: typeof collectSandboxPages;
|
|
570
|
-
/** The fields of E2B's SandboxDetail record that inspect() reads. */
|
|
571
|
-
interface E2BSandboxDetail {
|
|
572
|
-
sandboxID: string;
|
|
573
|
-
state: string;
|
|
574
|
-
envdVersion: string;
|
|
575
|
-
domain?: string | null;
|
|
576
|
-
envdAccessToken?: string;
|
|
577
|
-
trafficAccessToken?: string | null;
|
|
578
|
-
}
|
|
579
503
|
/**
|
|
580
504
|
* Create E2B sandbox provider.
|
|
581
505
|
*
|
|
@@ -591,7 +515,5 @@ declare function createE2BProvider(config?: E2BConfig): SandboxProvider;
|
|
|
591
515
|
* the type (never the constructor) gives the seam the real methods to pin.
|
|
592
516
|
*/
|
|
593
517
|
type _testE2BSandboxImpl = E2BSandboxImpl;
|
|
594
|
-
/** The constructor, for the metrics unit test (a vendor sandbox double goes in). */
|
|
595
|
-
declare const _testE2BSandboxImplCtor: typeof E2BSandboxImpl;
|
|
596
518
|
|
|
597
|
-
export { E2BBootCommandError, E2BCommands, type E2BConfig, E2BFiles, E2BIdleTimeoutError, E2BNetworkUpdateUnsupportedError, E2BProvider, E2BResourcesError, type E2BSandboxPaginator, E2B_MAX_LIST_PAGES, E2B_MAX_PAGE_SIZE, E2B_MIN_UPDATE_NETWORK_VERSION, type FileInfo, type
|
|
519
|
+
export { E2BBootCommandError, E2BCommands, type E2BConfig, E2BFiles, E2BIdleTimeoutError, E2BNetworkUpdateUnsupportedError, E2BProvider, E2BResourcesError, type E2BSandboxPaginator, E2B_MAX_LIST_PAGES, E2B_MAX_PAGE_SIZE, E2B_MIN_UPDATE_NETWORK_VERSION, 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, type _testE2BSandboxImpl, createE2BProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
import { Sandbox } from '@e2b/code-interpreter';
|
|
2
2
|
|
|
3
|
-
/** A capability this provider lacks: `feature` in dotted form (`files.watchDir`), `provider` type, optional `reason`. */
|
|
4
|
-
declare class SandboxFeatureUnsupportedError extends Error {
|
|
5
|
-
readonly feature: string;
|
|
6
|
-
readonly provider: string;
|
|
7
|
-
readonly reason?: string;
|
|
8
|
-
constructor(feature: string, provider: string, reason?: string);
|
|
9
|
-
}
|
|
10
|
-
/** A path the sandbox does not have — never an empty success. */
|
|
11
|
-
declare class SandboxPathNotFoundError extends Error {
|
|
12
|
-
readonly path: string;
|
|
13
|
-
readonly provider: string;
|
|
14
|
-
constructor(path: string, provider: string);
|
|
15
|
-
}
|
|
16
|
-
/** An inspect refused because the sandbox is not running; `state` is the provider's own word (`paused`, `exited with code 137`). */
|
|
17
|
-
declare class SandboxNotRunningError extends Error {
|
|
18
|
-
readonly sandboxId: string;
|
|
19
|
-
readonly provider: string;
|
|
20
|
-
readonly state: string;
|
|
21
|
-
constructor(sandboxId: string, provider: string, state: string);
|
|
22
|
-
}
|
|
23
|
-
/** True for a SandboxFeatureUnsupportedError from ANY package's copy. */
|
|
24
|
-
declare function isSandboxFeatureUnsupportedError(err: unknown): err is SandboxFeatureUnsupportedError;
|
|
25
|
-
/** True for a SandboxPathNotFoundError from ANY package's copy. */
|
|
26
|
-
declare function isSandboxPathNotFoundError(err: unknown): err is SandboxPathNotFoundError;
|
|
27
|
-
/** True for a SandboxNotRunningError from ANY package's copy. */
|
|
28
|
-
declare function isSandboxNotRunningError(err: unknown): err is SandboxNotRunningError;
|
|
29
|
-
|
|
30
3
|
/**
|
|
31
4
|
* E2B Sandbox Provider - Clean Architecture
|
|
32
5
|
*
|
|
33
|
-
* @requires @e2b/code-interpreter >=
|
|
34
|
-
* in e2b 2.10.3, the version the dashboard resolves (typings 2.10.3…2.39.0 unpacked and checked 2026-09-16)
|
|
6
|
+
* @requires @e2b/code-interpreter >= 1.0.0 or e2b >= 1.0.0
|
|
35
7
|
* @requires Node.js >= 18 (for ReadableStream support)
|
|
36
8
|
*
|
|
37
9
|
* Design principles:
|
|
@@ -138,27 +110,18 @@ interface SandboxInfo {
|
|
|
138
110
|
/** End time (undefined for running sandboxes) */
|
|
139
111
|
endAt?: string;
|
|
140
112
|
}
|
|
141
|
-
/**
|
|
113
|
+
/** File or directory entry info */
|
|
142
114
|
interface FileInfo {
|
|
143
115
|
name: string;
|
|
144
116
|
path: string;
|
|
145
|
-
type: "file" | "dir"
|
|
146
|
-
size: number;
|
|
147
|
-
mtime: string;
|
|
148
|
-
mode: string;
|
|
149
|
-
owner: string;
|
|
150
|
-
group: string;
|
|
151
|
-
target?: string;
|
|
152
|
-
}
|
|
153
|
-
/** A byte range of a file (the SDK contract's FileRange). */
|
|
154
|
-
interface FileRange {
|
|
155
|
-
offset: number;
|
|
156
|
-
length: number;
|
|
117
|
+
type: "file" | "dir";
|
|
157
118
|
}
|
|
158
|
-
/**
|
|
119
|
+
/** Filesystem event from watchDir */
|
|
159
120
|
interface FilesystemEvent {
|
|
160
|
-
path
|
|
161
|
-
|
|
121
|
+
/** Relative path to the changed file/directory */
|
|
122
|
+
name: string;
|
|
123
|
+
/** Type of filesystem operation */
|
|
124
|
+
type: "create" | "remove" | "rename" | "chmod" | "write";
|
|
162
125
|
}
|
|
163
126
|
/** Handle to stop watching a directory */
|
|
164
127
|
interface WatchHandle {
|
|
@@ -166,21 +129,9 @@ interface WatchHandle {
|
|
|
166
129
|
}
|
|
167
130
|
/** Options for watching a directory */
|
|
168
131
|
interface WatchOptions {
|
|
169
|
-
/** Also report changes in every subdirectory. Default false. */
|
|
170
132
|
recursive?: boolean;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
interface SandboxMetrics {
|
|
174
|
-
cpuPct: number;
|
|
175
|
-
memUsedMb: number;
|
|
176
|
-
memTotalMb: number;
|
|
177
|
-
diskUsedMb?: number;
|
|
178
|
-
sampledAt: string;
|
|
179
|
-
source: string;
|
|
180
|
-
}
|
|
181
|
-
/** Options for an inspect-only attach (the SDK contract's SandboxInspectOptions). */
|
|
182
|
-
interface SandboxInspectOptions {
|
|
183
|
-
user?: string;
|
|
133
|
+
timeoutMs?: number;
|
|
134
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
184
135
|
}
|
|
185
136
|
/** Options for blocking sandbox command execution */
|
|
186
137
|
interface SandboxRunOptions {
|
|
@@ -334,10 +285,6 @@ interface SandboxFiles {
|
|
|
334
285
|
remove(path: string): Promise<void>;
|
|
335
286
|
/** Rename or move file/directory */
|
|
336
287
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
337
|
-
/** The entry at `path` itself; a symlink is never followed */
|
|
338
|
-
stat(path: string): Promise<FileInfo>;
|
|
339
|
-
/** Exactly the requested bytes, without moving the whole file when the range is small */
|
|
340
|
-
readRange(path: string, range: FileRange): Promise<Uint8Array>;
|
|
341
288
|
/** Watch directory for changes */
|
|
342
289
|
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, options?: WatchOptions): Promise<WatchHandle>;
|
|
343
290
|
}
|
|
@@ -352,8 +299,6 @@ interface SandboxInstance {
|
|
|
352
299
|
isRunning(): Promise<boolean>;
|
|
353
300
|
/** Get sandbox metadata and timing */
|
|
354
301
|
getInfo(): Promise<SandboxInfo>;
|
|
355
|
-
/** The newest resource-usage sample, or null while there is none yet */
|
|
356
|
-
metrics(): Promise<SandboxMetrics | null>;
|
|
357
302
|
/** Terminate sandbox */
|
|
358
303
|
kill(): Promise<void>;
|
|
359
304
|
/** Pause sandbox (preserves state) */
|
|
@@ -371,8 +316,6 @@ interface SandboxProvider {
|
|
|
371
316
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
372
317
|
/** Connect to existing sandbox */
|
|
373
318
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
374
|
-
/** Attach to a RUNNING sandbox for reads; never resumes it, never touches its lifetime */
|
|
375
|
-
inspect(sandboxId: string, options?: SandboxInspectOptions): Promise<SandboxInstance>;
|
|
376
319
|
/** List sandboxes, paginating to exhaustion. `limit` bounds items returned. */
|
|
377
320
|
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
378
321
|
/** The same enumeration for fleet bookkeeping: never throws, reports completeness. */
|
|
@@ -408,10 +351,7 @@ declare class E2BCommands implements SandboxCommands {
|
|
|
408
351
|
declare class E2BFiles implements SandboxFiles {
|
|
409
352
|
private sandbox;
|
|
410
353
|
private defaultUser?;
|
|
411
|
-
|
|
412
|
-
/** inspect() passes the record's envd version; a created or connected sandbox reads its record once. */
|
|
413
|
-
constructor(sandbox: Sandbox, defaultUser?: string | undefined, envdVersion?: string | undefined);
|
|
414
|
-
private assertEntryInfo;
|
|
354
|
+
constructor(sandbox: Sandbox, defaultUser?: string | undefined);
|
|
415
355
|
read(path: string): Promise<string | Uint8Array>;
|
|
416
356
|
write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
|
|
417
357
|
writeBatch(files: Array<{
|
|
@@ -423,8 +363,6 @@ declare class E2BFiles implements SandboxFiles {
|
|
|
423
363
|
downloadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
424
364
|
exists(path: string): Promise<boolean>;
|
|
425
365
|
list(path: string): Promise<FileInfo[]>;
|
|
426
|
-
stat(path: string): Promise<FileInfo>;
|
|
427
|
-
readRange(path: string, range: FileRange): Promise<Uint8Array>;
|
|
428
366
|
remove(path: string): Promise<void>;
|
|
429
367
|
rename(oldPath: string, newPath: string): Promise<void>;
|
|
430
368
|
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
@@ -460,11 +398,8 @@ declare class E2BSandboxImpl implements SandboxInstance {
|
|
|
460
398
|
private apiUrl?;
|
|
461
399
|
readonly commands: SandboxCommands;
|
|
462
400
|
readonly files: SandboxFiles;
|
|
463
|
-
|
|
464
|
-
private lastMetricsAt?;
|
|
465
|
-
constructor(sandbox: Sandbox, apiKey: string, apiUrl?: string | undefined, defaultUser?: string, envdVersion?: string);
|
|
401
|
+
constructor(sandbox: Sandbox, apiKey: string, apiUrl?: string | undefined, defaultUser?: string);
|
|
466
402
|
get sandboxId(): string;
|
|
467
|
-
metrics(): Promise<SandboxMetrics | null>;
|
|
468
403
|
getHost(port: number): Promise<string>;
|
|
469
404
|
isRunning(): Promise<boolean>;
|
|
470
405
|
getInfo(): Promise<SandboxInfo>;
|
|
@@ -509,8 +444,6 @@ declare class E2BProvider implements SandboxProvider {
|
|
|
509
444
|
constructor(config: ResolvedE2BConfig);
|
|
510
445
|
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
511
446
|
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
512
|
-
inspect(sandboxId: string, options?: SandboxInspectOptions): Promise<SandboxInstance>;
|
|
513
|
-
protected fetchSandboxDetail(sandboxId: string): Promise<E2BSandboxDetail>;
|
|
514
447
|
/**
|
|
515
448
|
* List sandboxes, walking every page.
|
|
516
449
|
*
|
|
@@ -567,15 +500,6 @@ declare function collectSandboxPages(paginator: E2BSandboxPaginator, wanted?: nu
|
|
|
567
500
|
stoppedAtLimit: boolean;
|
|
568
501
|
}>;
|
|
569
502
|
declare const _testCollectSandboxPages: typeof collectSandboxPages;
|
|
570
|
-
/** The fields of E2B's SandboxDetail record that inspect() reads. */
|
|
571
|
-
interface E2BSandboxDetail {
|
|
572
|
-
sandboxID: string;
|
|
573
|
-
state: string;
|
|
574
|
-
envdVersion: string;
|
|
575
|
-
domain?: string | null;
|
|
576
|
-
envdAccessToken?: string;
|
|
577
|
-
trafficAccessToken?: string | null;
|
|
578
|
-
}
|
|
579
503
|
/**
|
|
580
504
|
* Create E2B sandbox provider.
|
|
581
505
|
*
|
|
@@ -591,7 +515,5 @@ declare function createE2BProvider(config?: E2BConfig): SandboxProvider;
|
|
|
591
515
|
* the type (never the constructor) gives the seam the real methods to pin.
|
|
592
516
|
*/
|
|
593
517
|
type _testE2BSandboxImpl = E2BSandboxImpl;
|
|
594
|
-
/** The constructor, for the metrics unit test (a vendor sandbox double goes in). */
|
|
595
|
-
declare const _testE2BSandboxImplCtor: typeof E2BSandboxImpl;
|
|
596
518
|
|
|
597
|
-
export { E2BBootCommandError, E2BCommands, type E2BConfig, E2BFiles, E2BIdleTimeoutError, E2BNetworkUpdateUnsupportedError, E2BProvider, E2BResourcesError, type E2BSandboxPaginator, E2B_MAX_LIST_PAGES, E2B_MAX_PAGE_SIZE, E2B_MIN_UPDATE_NETWORK_VERSION, type FileInfo, type
|
|
519
|
+
export { E2BBootCommandError, E2BCommands, type E2BConfig, E2BFiles, E2BIdleTimeoutError, E2BNetworkUpdateUnsupportedError, E2BProvider, E2BResourcesError, type E2BSandboxPaginator, E2B_MAX_LIST_PAGES, E2B_MAX_PAGE_SIZE, E2B_MIN_UPDATE_NETWORK_VERSION, 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, type _testE2BSandboxImpl, createE2BProvider };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {Sandbox
|
|
1
|
+
import {Sandbox}from'@e2b/code-interpreter';function b(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 k=100,I=100;function u(s){return s instanceof Date?s.toISOString():String(s)}function U(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="2.25.0",g=class extends Error{constructor(e){super(e),this.name="E2BNetworkUpdateUnsupportedError";}};function x(s){if(s?.outbound==="open"&&s.allowedDestinations?.length)throw new Error("network.allowedDestinations is only valid when outbound is blocked");let e=s?.allowedDestinations??[],t=s?.outbound==="blocked"&&e.length>0;return {allowInternetAccess:s?.outbound!=="blocked"||t,network:t?{denyOut:["0.0.0.0/0"],allowOut:e}:void 0}}var h=class extends Error{constructor(){super("E2B takes no create-time boot command: the sandbox boots its template's own init, and a start command is a template-BUILD field (Template startCmd) this provider never sets. The boot is already inert \u2014 run the process by exec after create, or bake it into the template the `image` names."),this.name="E2BBootCommandError";}},y=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";}},w=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(b(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(b(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(b(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))}},S=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,U(t),{requestTimeoutMs:3e5,user:this.defaultUser});}async writeBatch(e){let t=e.map(r=>({path:r.path,data:U(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:d}=await import('crypto'),a=n(t).size,p=`----evolve${d(16).toString("hex")}`,v=Buffer.from(`--${p}\r
|
|
2
2
|
Content-Disposition: form-data; name="file"; filename="blob"\r
|
|
3
3
|
Content-Type: application/octet-stream\r
|
|
4
4
|
\r
|
|
5
|
-
`),
|
|
6
|
-
--${
|
|
7
|
-
`);async function*
|
|
8
|
-
export{
|
|
5
|
+
`),A=Buffer.from(`\r
|
|
6
|
+
--${p}--\r
|
|
7
|
+
`);async function*C(){yield v;for await(let o of r(t))yield o;yield A;}try{let o=await this.uploadUrl(e),m=await fetch(o,{method:"POST",body:i.toWeb(i.from(C())),headers:{"Content-Type":`multipart/form-data; boundary=${p}`,"Content-Length":String(v.length+a+A.length)},duplex:"half"});if(!m.ok)throw new Error(`streamed upload to ${e} failed (HTTP ${m.status})`)}catch(o){console.warn(`[e2b] streamed upload of ${t} failed, falling back to a buffered write:`,o instanceof Error?o.message:o);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 w(e,n),this.files=new S(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 updateNetwork(e){let t=x(e),r=this.sandbox;if(typeof r.updateNetwork!="function")throw new g(`The installed e2b client cannot change a running sandbox's network policy: Sandbox.updateNetwork requires e2b >= ${B}. Upgrade the e2b dependency (it is pulled in by @e2b/code-interpreter), or create the sandbox with the policy it needs for its whole lifetime.`);await r.updateNetwork({allowInternetAccess:t.allowInternetAccess,...t.network??{}});}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});}},P=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.bootCommand!==void 0)throw new h;if(e.idleTimeoutMs!==void 0)throw new y;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";for(let d of e.phaseNetworkPolicies??[])x(d);let n=x(e.network),i=await Sandbox.create(r,{apiKey:this.apiKey,apiUrl:this.apiUrl,envs:e.envs,metadata:e.metadata,timeoutMs:t,...n});return e.workingDirectory&&await i.files.makeDir(e.workingDirectory,{user:e.user}),e.user&&this.sandboxUsers.set(i.sandboxId,e.user),new c(i,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 E(Sandbox.list({apiKey:this.apiKey,apiUrl:this.apiUrl,query:{state:e?.state,metadata:e?.metadata},limit:t===void 0?k:Math.min(t,k)}),t)}};async function E(s,e){let t=[],r=0,n=new Set;for(;s.hasNext;){if(r>=I)return {sandboxes:t,complete:false,pagesFetched:r,stoppedAtLimit:false,error:`sandbox list exceeded ${I} 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 d;try{d=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 d){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 T=E;function M(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 P({...s,apiKey:e})}
|
|
8
|
+
export{h as E2BBootCommandError,w as E2BCommands,S as E2BFiles,y as E2BIdleTimeoutError,g as E2BNetworkUpdateUnsupportedError,P as E2BProvider,l as E2BResourcesError,I as E2B_MAX_LIST_PAGES,k as E2B_MAX_PAGE_SIZE,B as E2B_MIN_UPDATE_NETWORK_VERSION,T as _testCollectSandboxPages,M 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.60",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"ai",
|
|
6
6
|
"agents",
|
|
@@ -33,11 +33,10 @@
|
|
|
33
33
|
"build": "tsup --minify",
|
|
34
34
|
"dev": "tsup --watch",
|
|
35
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 && tsx tests/unit/e2b-boot-command-rejection.test.ts && tsx tests/unit/e2b-template-refresh.test.ts
|
|
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 && tsx tests/unit/e2b-boot-command-rejection.test.ts && tsx tests/unit/e2b-template-refresh.test.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@e2b/code-interpreter": "^2.7.1"
|
|
40
|
-
"compare-versions": "^6.1.0"
|
|
39
|
+
"@e2b/code-interpreter": "^2.7.1"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@types/node": "^22.15.18",
|