@evolvingmachines/e2b 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +19 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +2 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
EVOLVE SDK PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Swarmlink, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
BETA EVALUATION LICENSE
|
|
6
|
+
|
|
7
|
+
The Evolve SDK is provided for evaluation and beta testing purposes only.
|
|
8
|
+
|
|
9
|
+
PERMITTED:
|
|
10
|
+
- Install Evolve SDK via npm/PyPI for evaluation and development
|
|
11
|
+
- Build applications using the Evolve SDK during the beta period
|
|
12
|
+
- Deploy applications using the Evolve SDK to production
|
|
13
|
+
|
|
14
|
+
PROHIBITED:
|
|
15
|
+
- Redistribute the Evolve SDK itself
|
|
16
|
+
- Reverse engineer, decompile, or extract source code from the SDK
|
|
17
|
+
- Create derivative works of the Evolve SDK
|
|
18
|
+
- Use Evolve SDK in competing products or services
|
|
19
|
+
|
|
20
|
+
NO WARRANTY. THIS SOFTWARE IS PROVIDED "AS IS" FOR BETA EVALUATION.
|
|
21
|
+
|
|
22
|
+
This license may be revised upon general availability.
|
|
23
|
+
|
|
24
|
+
For licensing inquiries, contact: brandomagnani@evolvingmachines.ai
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Evolve SDK E2B Provider
|
|
2
|
+
|
|
3
|
+
E2B sandbox provider for [Evolve SDK](https://www.npmjs.com/package/@evolvingmachines/sdk).
|
|
4
|
+
|
|
5
|
+
**Note:** This package is automatically installed as a dependency of `@evolvingmachines/sdk`. You don't need to install it separately.
|
|
6
|
+
|
|
7
|
+
Check out the [official documentation](https://github.com/evolving-machines-lab/evolve/tree/main/docs) and [cookbooks](https://github.com/evolving-machines-lab/evolve/tree/main/cookbooks).
|
|
8
|
+
|
|
9
|
+
## Reporting Bugs
|
|
10
|
+
|
|
11
|
+
We welcome your feedback. File a [GitHub issue](https://github.com/evolving-machines-lab/evolve/issues) to report bugs or request features.
|
|
12
|
+
|
|
13
|
+
## Connect on Discord
|
|
14
|
+
|
|
15
|
+
Join the [Evolve SDK Developers Discord](https://discord.gg/Q36D8dGyNF) to connect with other developers using Evolve SDK. Get help, share feedback, and discuss your projects with the community.
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
See [LICENSE](https://github.com/evolving-machines-lab/evolve/blob/main/LICENSE) for details.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var codeInterpreter=require('@e2b/code-interpreter');var b=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".pdf",".zip",".tar",".gz",".7z",".rar",".png",".jpg",".jpeg",".gif",".webp",".ico",".bmp",".mp3",".wav",".ogg",".flac",".aac",".mp4",".avi",".mov",".mkv",".webm",".woff",".woff2",".ttf",".otf",".eot",".exe",".dll",".so",".dylib",".sqlite",".db",".pickle",".pkl",".parquet"]);function a(i){return i instanceof Date?i.toISOString():String(i)}function l(i){if(typeof i=="string"||i instanceof ArrayBuffer)return i;if(i instanceof Buffer)return new Uint8Array(i).buffer;if(i instanceof Uint8Array)return new Uint8Array(i).buffer;throw new Error(`Unsupported data type for file upload: ${typeof i}. Expected string, Buffer, ArrayBuffer, or Uint8Array.`)}function x(i){let t=i.substring(i.lastIndexOf(".")).toLowerCase();return b.has(t)}var m=class{constructor(t){this.sandbox=t;}async run(t,e){try{let n=await this.sandbox.commands.run(t,{timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let r=n;return {exitCode:r.exitCode,stdout:r.stdout??"",stderr:r.stderr??""}}throw n}}async spawn(t,e){let n=await this.sandbox.commands.run(t,{background:true,stdin:e?.stdin??true,timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {pid:n.pid,wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let s=r;return {exitCode:s.exitCode,stdout:s.stdout??"",stderr:s.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async list(){return this.sandbox.commands.list()}async connect(t,e){let n=await this.sandbox.commands.connect(t,{onStdout:e?.onStdout,onStderr:e?.onStderr,timeoutMs:e?.timeoutMs});return {pid:n.pid,wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let s=r;return {exitCode:s.exitCode,stdout:s.stdout??"",stderr:s.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async sendStdin(t,e){await this.sandbox.commands.sendStdin(t,e);}async kill(t){return this.sandbox.commands.kill(t)}},u=class{constructor(t){this.sandbox=t;}async read(t){return x(t)?this.sandbox.files.read(t,{format:"bytes",requestTimeoutMs:3e5}):this.sandbox.files.read(t,{format:"text",requestTimeoutMs:3e5})}async write(t,e){await this.sandbox.files.write(t,l(e),{requestTimeoutMs:3e5});}async writeBatch(t){let e=t.map(n=>({path:n.path,data:l(n.data)}));await this.sandbox.files.write(e,{requestTimeoutMs:3e5});}async makeDir(t){await this.sandbox.files.makeDir(t);}async uploadUrl(t,e){return this.sandbox.uploadUrl(t,e?{useSignatureExpiration:e}:void 0)}async downloadUrl(t,e){return this.sandbox.downloadUrl(t,e?{useSignatureExpiration:e}:void 0)}async exists(t){return this.sandbox.files.exists(t)}async list(t){return (await this.sandbox.files.list(t)).map(n=>({name:n.name,path:n.path,type:n.type==="dir"?"dir":"file"}))}async remove(t){await this.sandbox.files.remove(t);}async rename(t,e){await this.sandbox.files.rename(t,e);}async readStream(t){return this.sandbox.files.read(t,{format:"stream"})}async writeStream(t,e){await this.sandbox.files.write(t,e);}async watchDir(t,e,n){let r=await this.sandbox.files.watchDir(t,e,{recursive:n?.recursive,timeoutMs:n?.timeoutMs,onExit:n?.onExit});return {stop:()=>r.stop()}}},o=class{constructor(t){this.sandbox=t;this.commands=new m(t),this.files=new u(t);}commands;files;get sandboxId(){return this.sandbox.sandboxId}getHost(t){return this.sandbox.getHost(t)}async isRunning(){return this.sandbox.isRunning()}async getInfo(){let t=await this.sandbox.getInfo();return {sandboxId:t.sandboxId,templateId:t.templateId,name:t.name,metadata:t.metadata??{},startedAt:a(t.startedAt),endAt:t.endAt?a(t.endAt):void 0}}async kill(){try{await this.sandbox.kill();}catch{await new Promise(t=>setTimeout(t,500)),await this.sandbox.kill();}}async pause(){await this.sandbox.betaPause();}},c=class{providerType="e2b";apiKey;defaultTimeoutMs;constructor(t){this.apiKey=t.apiKey,this.defaultTimeoutMs=t.defaultTimeoutMs??36e5;}async create(t){let e=t.timeoutMs??this.defaultTimeoutMs,n=await codeInterpreter.Sandbox.create(t.templateId,{apiKey:this.apiKey,envs:t.envs,metadata:t.metadata,timeoutMs:e});return t.workingDirectory&&await n.files.makeDir(t.workingDirectory),new o(n)}async connect(t,e){let n=await codeInterpreter.Sandbox.connect(t,{apiKey:this.apiKey,timeoutMs:e??this.defaultTimeoutMs});return new o(n)}async list(t){return (await codeInterpreter.Sandbox.list({apiKey:this.apiKey,query:{state:t?.state,metadata:t?.metadata},limit:t?.limit??100}).nextItems()).map(r=>({sandboxId:r.sandboxId,templateId:r.templateId,name:r.name,metadata:r.metadata??{},startedAt:a(r.startedAt),endAt:r.endAt?a(r.endAt):void 0}))}};function g(i={}){let t=i.apiKey??process.env.E2B_API_KEY;if(!t)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 c({...i,apiKey:t})}
|
|
2
|
+
exports.E2BSandboxProvider=c;exports.createE2BProvider=g;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2B Sandbox Provider - Clean Architecture
|
|
3
|
+
*
|
|
4
|
+
* @requires @e2b/code-interpreter >= 1.0.0 or e2b >= 1.0.0
|
|
5
|
+
* @requires Node.js >= 18 (for ReadableStream support)
|
|
6
|
+
*
|
|
7
|
+
* Design principles:
|
|
8
|
+
* - Single way to do things (no dual methods)
|
|
9
|
+
* - Options objects only (no positional args)
|
|
10
|
+
* - All interface methods required (no optional ?)
|
|
11
|
+
* - Configuration externalized (no hardcoded mappings)
|
|
12
|
+
* - Clear naming (run = blocking, spawn = background)
|
|
13
|
+
*/
|
|
14
|
+
/** Result of a completed sandbox command */
|
|
15
|
+
interface SandboxCommandResult {
|
|
16
|
+
exitCode: number;
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
}
|
|
20
|
+
/** Handle to a running background process in sandbox */
|
|
21
|
+
interface SandboxCommandHandle {
|
|
22
|
+
readonly pid: number;
|
|
23
|
+
wait(): Promise<SandboxCommandResult>;
|
|
24
|
+
kill(): Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
/** Information about a running process */
|
|
27
|
+
interface ProcessInfo {
|
|
28
|
+
pid: number;
|
|
29
|
+
cmd: string;
|
|
30
|
+
args: string[];
|
|
31
|
+
envs: Record<string, string>;
|
|
32
|
+
cwd?: string;
|
|
33
|
+
tag?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Sandbox metadata and lifecycle info */
|
|
36
|
+
interface SandboxInfo {
|
|
37
|
+
sandboxId: string;
|
|
38
|
+
templateId: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
metadata: Record<string, string>;
|
|
41
|
+
startedAt: string;
|
|
42
|
+
/** End time (undefined for running sandboxes) */
|
|
43
|
+
endAt?: string;
|
|
44
|
+
}
|
|
45
|
+
/** File or directory entry info */
|
|
46
|
+
interface FileInfo {
|
|
47
|
+
name: string;
|
|
48
|
+
path: string;
|
|
49
|
+
type: "file" | "dir";
|
|
50
|
+
}
|
|
51
|
+
/** Filesystem event from watchDir */
|
|
52
|
+
interface FilesystemEvent {
|
|
53
|
+
/** Relative path to the changed file/directory */
|
|
54
|
+
name: string;
|
|
55
|
+
/** Type of filesystem operation */
|
|
56
|
+
type: "create" | "remove" | "rename" | "chmod" | "write";
|
|
57
|
+
}
|
|
58
|
+
/** Handle to stop watching a directory */
|
|
59
|
+
interface WatchHandle {
|
|
60
|
+
stop(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/** Options for watching a directory */
|
|
63
|
+
interface WatchOptions {
|
|
64
|
+
recursive?: boolean;
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/** Options for blocking sandbox command execution */
|
|
69
|
+
interface SandboxRunOptions {
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
envs?: Record<string, string>;
|
|
72
|
+
cwd?: string;
|
|
73
|
+
onStdout?: (data: string) => void;
|
|
74
|
+
onStderr?: (data: string) => void;
|
|
75
|
+
}
|
|
76
|
+
/** Options for spawning background sandbox processes */
|
|
77
|
+
interface SandboxSpawnOptions extends SandboxRunOptions {
|
|
78
|
+
stdin?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/** Options for connecting to a running process */
|
|
81
|
+
interface SandboxConnectOptions {
|
|
82
|
+
onStdout?: (data: string) => void;
|
|
83
|
+
onStderr?: (data: string) => void;
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
}
|
|
86
|
+
/** Options for creating a sandbox */
|
|
87
|
+
interface SandboxCreateOptions {
|
|
88
|
+
templateId: string;
|
|
89
|
+
envs?: Record<string, string>;
|
|
90
|
+
metadata?: Record<string, string>;
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
workingDirectory?: string;
|
|
93
|
+
}
|
|
94
|
+
/** Options for listing sandboxes */
|
|
95
|
+
interface SandboxListOptions {
|
|
96
|
+
state?: ("running" | "paused")[];
|
|
97
|
+
metadata?: Record<string, string>;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}
|
|
100
|
+
/** Command execution capabilities */
|
|
101
|
+
interface SandboxCommands {
|
|
102
|
+
/** Run command and wait for completion */
|
|
103
|
+
run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
|
|
104
|
+
/** Spawn background process, returns handle for control */
|
|
105
|
+
spawn(command: string, options?: SandboxSpawnOptions): Promise<SandboxCommandHandle>;
|
|
106
|
+
/** List running processes */
|
|
107
|
+
list(): Promise<ProcessInfo[]>;
|
|
108
|
+
/** Connect to existing process by PID */
|
|
109
|
+
connect(pid: number, options?: SandboxConnectOptions): Promise<SandboxCommandHandle>;
|
|
110
|
+
/** Send data to process stdin */
|
|
111
|
+
sendStdin(pid: number, data: string): Promise<void>;
|
|
112
|
+
/** Kill process by PID */
|
|
113
|
+
kill(pid: number): Promise<boolean>;
|
|
114
|
+
}
|
|
115
|
+
/** File system operations */
|
|
116
|
+
interface SandboxFiles {
|
|
117
|
+
/** Read file (auto-detects binary by extension) */
|
|
118
|
+
read(path: string): Promise<string | Uint8Array>;
|
|
119
|
+
/** Write single file */
|
|
120
|
+
write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
|
|
121
|
+
/** Write multiple files in batch */
|
|
122
|
+
writeBatch(files: Array<{
|
|
123
|
+
path: string;
|
|
124
|
+
data: string | Buffer | ArrayBuffer | Uint8Array;
|
|
125
|
+
}>): Promise<void>;
|
|
126
|
+
/** Read file as stream */
|
|
127
|
+
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
128
|
+
/** Write from stream */
|
|
129
|
+
writeStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
130
|
+
/** Get pre-signed upload URL for large files (expiration in seconds) */
|
|
131
|
+
uploadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
132
|
+
/** Get pre-signed download URL for large files (expiration in seconds) */
|
|
133
|
+
downloadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
134
|
+
/** Create directory (recursive) */
|
|
135
|
+
makeDir(path: string): Promise<void>;
|
|
136
|
+
/** Check if file or directory exists */
|
|
137
|
+
exists(path: string): Promise<boolean>;
|
|
138
|
+
/** List directory contents */
|
|
139
|
+
list(path: string): Promise<FileInfo[]>;
|
|
140
|
+
/** Delete file or directory */
|
|
141
|
+
remove(path: string): Promise<void>;
|
|
142
|
+
/** Rename or move file/directory */
|
|
143
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
144
|
+
/** Watch directory for changes */
|
|
145
|
+
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, options?: WatchOptions): Promise<WatchHandle>;
|
|
146
|
+
}
|
|
147
|
+
/** Sandbox instance with full capabilities */
|
|
148
|
+
interface SandboxInstance {
|
|
149
|
+
readonly sandboxId: string;
|
|
150
|
+
readonly commands: SandboxCommands;
|
|
151
|
+
readonly files: SandboxFiles;
|
|
152
|
+
/** Get public URL for port (sync) */
|
|
153
|
+
getHost(port: number): string;
|
|
154
|
+
/** Check if sandbox is running */
|
|
155
|
+
isRunning(): Promise<boolean>;
|
|
156
|
+
/** Get sandbox metadata and timing */
|
|
157
|
+
getInfo(): Promise<SandboxInfo>;
|
|
158
|
+
/** Terminate sandbox */
|
|
159
|
+
kill(): Promise<void>;
|
|
160
|
+
/** Pause sandbox (preserves state) */
|
|
161
|
+
pause(): Promise<void>;
|
|
162
|
+
}
|
|
163
|
+
/** Sandbox lifecycle management */
|
|
164
|
+
interface SandboxProvider {
|
|
165
|
+
/** Provider type identifier */
|
|
166
|
+
readonly providerType: string;
|
|
167
|
+
/** Create new sandbox */
|
|
168
|
+
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
169
|
+
/** Connect to existing sandbox */
|
|
170
|
+
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
171
|
+
/** List sandboxes (first page only, up to limit) */
|
|
172
|
+
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
173
|
+
}
|
|
174
|
+
interface E2BConfig {
|
|
175
|
+
/** E2B API key. Default: reads from E2B_API_KEY env var */
|
|
176
|
+
apiKey?: string;
|
|
177
|
+
defaultTimeoutMs?: number;
|
|
178
|
+
}
|
|
179
|
+
/** Internal resolved config with required apiKey */
|
|
180
|
+
interface ResolvedE2BConfig {
|
|
181
|
+
apiKey: string;
|
|
182
|
+
defaultTimeoutMs?: number;
|
|
183
|
+
}
|
|
184
|
+
declare class E2BSandboxProvider implements SandboxProvider {
|
|
185
|
+
readonly providerType: "e2b";
|
|
186
|
+
private readonly apiKey;
|
|
187
|
+
private readonly defaultTimeoutMs;
|
|
188
|
+
constructor(config: ResolvedE2BConfig);
|
|
189
|
+
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
190
|
+
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
191
|
+
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Create E2B sandbox provider.
|
|
195
|
+
*
|
|
196
|
+
* @param config - Optional configuration. If apiKey not provided, reads from E2B_API_KEY env var.
|
|
197
|
+
* @throws Error if apiKey cannot be resolved
|
|
198
|
+
*/
|
|
199
|
+
declare function createE2BProvider(config?: E2BConfig): SandboxProvider;
|
|
200
|
+
|
|
201
|
+
export { type E2BConfig, E2BSandboxProvider, 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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* E2B Sandbox Provider - Clean Architecture
|
|
3
|
+
*
|
|
4
|
+
* @requires @e2b/code-interpreter >= 1.0.0 or e2b >= 1.0.0
|
|
5
|
+
* @requires Node.js >= 18 (for ReadableStream support)
|
|
6
|
+
*
|
|
7
|
+
* Design principles:
|
|
8
|
+
* - Single way to do things (no dual methods)
|
|
9
|
+
* - Options objects only (no positional args)
|
|
10
|
+
* - All interface methods required (no optional ?)
|
|
11
|
+
* - Configuration externalized (no hardcoded mappings)
|
|
12
|
+
* - Clear naming (run = blocking, spawn = background)
|
|
13
|
+
*/
|
|
14
|
+
/** Result of a completed sandbox command */
|
|
15
|
+
interface SandboxCommandResult {
|
|
16
|
+
exitCode: number;
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
}
|
|
20
|
+
/** Handle to a running background process in sandbox */
|
|
21
|
+
interface SandboxCommandHandle {
|
|
22
|
+
readonly pid: number;
|
|
23
|
+
wait(): Promise<SandboxCommandResult>;
|
|
24
|
+
kill(): Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
/** Information about a running process */
|
|
27
|
+
interface ProcessInfo {
|
|
28
|
+
pid: number;
|
|
29
|
+
cmd: string;
|
|
30
|
+
args: string[];
|
|
31
|
+
envs: Record<string, string>;
|
|
32
|
+
cwd?: string;
|
|
33
|
+
tag?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Sandbox metadata and lifecycle info */
|
|
36
|
+
interface SandboxInfo {
|
|
37
|
+
sandboxId: string;
|
|
38
|
+
templateId: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
metadata: Record<string, string>;
|
|
41
|
+
startedAt: string;
|
|
42
|
+
/** End time (undefined for running sandboxes) */
|
|
43
|
+
endAt?: string;
|
|
44
|
+
}
|
|
45
|
+
/** File or directory entry info */
|
|
46
|
+
interface FileInfo {
|
|
47
|
+
name: string;
|
|
48
|
+
path: string;
|
|
49
|
+
type: "file" | "dir";
|
|
50
|
+
}
|
|
51
|
+
/** Filesystem event from watchDir */
|
|
52
|
+
interface FilesystemEvent {
|
|
53
|
+
/** Relative path to the changed file/directory */
|
|
54
|
+
name: string;
|
|
55
|
+
/** Type of filesystem operation */
|
|
56
|
+
type: "create" | "remove" | "rename" | "chmod" | "write";
|
|
57
|
+
}
|
|
58
|
+
/** Handle to stop watching a directory */
|
|
59
|
+
interface WatchHandle {
|
|
60
|
+
stop(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/** Options for watching a directory */
|
|
63
|
+
interface WatchOptions {
|
|
64
|
+
recursive?: boolean;
|
|
65
|
+
timeoutMs?: number;
|
|
66
|
+
onExit?: (err?: Error) => void | Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/** Options for blocking sandbox command execution */
|
|
69
|
+
interface SandboxRunOptions {
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
envs?: Record<string, string>;
|
|
72
|
+
cwd?: string;
|
|
73
|
+
onStdout?: (data: string) => void;
|
|
74
|
+
onStderr?: (data: string) => void;
|
|
75
|
+
}
|
|
76
|
+
/** Options for spawning background sandbox processes */
|
|
77
|
+
interface SandboxSpawnOptions extends SandboxRunOptions {
|
|
78
|
+
stdin?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/** Options for connecting to a running process */
|
|
81
|
+
interface SandboxConnectOptions {
|
|
82
|
+
onStdout?: (data: string) => void;
|
|
83
|
+
onStderr?: (data: string) => void;
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
}
|
|
86
|
+
/** Options for creating a sandbox */
|
|
87
|
+
interface SandboxCreateOptions {
|
|
88
|
+
templateId: string;
|
|
89
|
+
envs?: Record<string, string>;
|
|
90
|
+
metadata?: Record<string, string>;
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
workingDirectory?: string;
|
|
93
|
+
}
|
|
94
|
+
/** Options for listing sandboxes */
|
|
95
|
+
interface SandboxListOptions {
|
|
96
|
+
state?: ("running" | "paused")[];
|
|
97
|
+
metadata?: Record<string, string>;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}
|
|
100
|
+
/** Command execution capabilities */
|
|
101
|
+
interface SandboxCommands {
|
|
102
|
+
/** Run command and wait for completion */
|
|
103
|
+
run(command: string, options?: SandboxRunOptions): Promise<SandboxCommandResult>;
|
|
104
|
+
/** Spawn background process, returns handle for control */
|
|
105
|
+
spawn(command: string, options?: SandboxSpawnOptions): Promise<SandboxCommandHandle>;
|
|
106
|
+
/** List running processes */
|
|
107
|
+
list(): Promise<ProcessInfo[]>;
|
|
108
|
+
/** Connect to existing process by PID */
|
|
109
|
+
connect(pid: number, options?: SandboxConnectOptions): Promise<SandboxCommandHandle>;
|
|
110
|
+
/** Send data to process stdin */
|
|
111
|
+
sendStdin(pid: number, data: string): Promise<void>;
|
|
112
|
+
/** Kill process by PID */
|
|
113
|
+
kill(pid: number): Promise<boolean>;
|
|
114
|
+
}
|
|
115
|
+
/** File system operations */
|
|
116
|
+
interface SandboxFiles {
|
|
117
|
+
/** Read file (auto-detects binary by extension) */
|
|
118
|
+
read(path: string): Promise<string | Uint8Array>;
|
|
119
|
+
/** Write single file */
|
|
120
|
+
write(path: string, content: string | Buffer | ArrayBuffer | Uint8Array): Promise<void>;
|
|
121
|
+
/** Write multiple files in batch */
|
|
122
|
+
writeBatch(files: Array<{
|
|
123
|
+
path: string;
|
|
124
|
+
data: string | Buffer | ArrayBuffer | Uint8Array;
|
|
125
|
+
}>): Promise<void>;
|
|
126
|
+
/** Read file as stream */
|
|
127
|
+
readStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
128
|
+
/** Write from stream */
|
|
129
|
+
writeStream(path: string, stream: ReadableStream<Uint8Array>): Promise<void>;
|
|
130
|
+
/** Get pre-signed upload URL for large files (expiration in seconds) */
|
|
131
|
+
uploadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
132
|
+
/** Get pre-signed download URL for large files (expiration in seconds) */
|
|
133
|
+
downloadUrl(path: string, expiresInSeconds?: number): Promise<string>;
|
|
134
|
+
/** Create directory (recursive) */
|
|
135
|
+
makeDir(path: string): Promise<void>;
|
|
136
|
+
/** Check if file or directory exists */
|
|
137
|
+
exists(path: string): Promise<boolean>;
|
|
138
|
+
/** List directory contents */
|
|
139
|
+
list(path: string): Promise<FileInfo[]>;
|
|
140
|
+
/** Delete file or directory */
|
|
141
|
+
remove(path: string): Promise<void>;
|
|
142
|
+
/** Rename or move file/directory */
|
|
143
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
144
|
+
/** Watch directory for changes */
|
|
145
|
+
watchDir(path: string, onEvent: (event: FilesystemEvent) => void | Promise<void>, options?: WatchOptions): Promise<WatchHandle>;
|
|
146
|
+
}
|
|
147
|
+
/** Sandbox instance with full capabilities */
|
|
148
|
+
interface SandboxInstance {
|
|
149
|
+
readonly sandboxId: string;
|
|
150
|
+
readonly commands: SandboxCommands;
|
|
151
|
+
readonly files: SandboxFiles;
|
|
152
|
+
/** Get public URL for port (sync) */
|
|
153
|
+
getHost(port: number): string;
|
|
154
|
+
/** Check if sandbox is running */
|
|
155
|
+
isRunning(): Promise<boolean>;
|
|
156
|
+
/** Get sandbox metadata and timing */
|
|
157
|
+
getInfo(): Promise<SandboxInfo>;
|
|
158
|
+
/** Terminate sandbox */
|
|
159
|
+
kill(): Promise<void>;
|
|
160
|
+
/** Pause sandbox (preserves state) */
|
|
161
|
+
pause(): Promise<void>;
|
|
162
|
+
}
|
|
163
|
+
/** Sandbox lifecycle management */
|
|
164
|
+
interface SandboxProvider {
|
|
165
|
+
/** Provider type identifier */
|
|
166
|
+
readonly providerType: string;
|
|
167
|
+
/** Create new sandbox */
|
|
168
|
+
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
169
|
+
/** Connect to existing sandbox */
|
|
170
|
+
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
171
|
+
/** List sandboxes (first page only, up to limit) */
|
|
172
|
+
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
173
|
+
}
|
|
174
|
+
interface E2BConfig {
|
|
175
|
+
/** E2B API key. Default: reads from E2B_API_KEY env var */
|
|
176
|
+
apiKey?: string;
|
|
177
|
+
defaultTimeoutMs?: number;
|
|
178
|
+
}
|
|
179
|
+
/** Internal resolved config with required apiKey */
|
|
180
|
+
interface ResolvedE2BConfig {
|
|
181
|
+
apiKey: string;
|
|
182
|
+
defaultTimeoutMs?: number;
|
|
183
|
+
}
|
|
184
|
+
declare class E2BSandboxProvider implements SandboxProvider {
|
|
185
|
+
readonly providerType: "e2b";
|
|
186
|
+
private readonly apiKey;
|
|
187
|
+
private readonly defaultTimeoutMs;
|
|
188
|
+
constructor(config: ResolvedE2BConfig);
|
|
189
|
+
create(options: SandboxCreateOptions): Promise<SandboxInstance>;
|
|
190
|
+
connect(sandboxId: string, timeoutMs?: number): Promise<SandboxInstance>;
|
|
191
|
+
list(options?: SandboxListOptions): Promise<SandboxInfo[]>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Create E2B sandbox provider.
|
|
195
|
+
*
|
|
196
|
+
* @param config - Optional configuration. If apiKey not provided, reads from E2B_API_KEY env var.
|
|
197
|
+
* @throws Error if apiKey cannot be resolved
|
|
198
|
+
*/
|
|
199
|
+
declare function createE2BProvider(config?: E2BConfig): SandboxProvider;
|
|
200
|
+
|
|
201
|
+
export { type E2BConfig, E2BSandboxProvider, 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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {Sandbox}from'@e2b/code-interpreter';var b=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".pdf",".zip",".tar",".gz",".7z",".rar",".png",".jpg",".jpeg",".gif",".webp",".ico",".bmp",".mp3",".wav",".ogg",".flac",".aac",".mp4",".avi",".mov",".mkv",".webm",".woff",".woff2",".ttf",".otf",".eot",".exe",".dll",".so",".dylib",".sqlite",".db",".pickle",".pkl",".parquet"]);function a(i){return i instanceof Date?i.toISOString():String(i)}function l(i){if(typeof i=="string"||i instanceof ArrayBuffer)return i;if(i instanceof Buffer)return new Uint8Array(i).buffer;if(i instanceof Uint8Array)return new Uint8Array(i).buffer;throw new Error(`Unsupported data type for file upload: ${typeof i}. Expected string, Buffer, ArrayBuffer, or Uint8Array.`)}function x(i){let t=i.substring(i.lastIndexOf(".")).toLowerCase();return b.has(t)}var m=class{constructor(t){this.sandbox=t;}async run(t,e){try{let n=await this.sandbox.commands.run(t,{timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){if(n&&typeof n=="object"&&"exitCode"in n){let r=n;return {exitCode:r.exitCode,stdout:r.stdout??"",stderr:r.stderr??""}}throw n}}async spawn(t,e){let n=await this.sandbox.commands.run(t,{background:true,stdin:e?.stdin??true,timeoutMs:e?.timeoutMs,envs:e?.envs,cwd:e?.cwd,onStdout:e?.onStdout,onStderr:e?.onStderr});return {pid:n.pid,wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let s=r;return {exitCode:s.exitCode,stdout:s.stdout??"",stderr:s.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async list(){return this.sandbox.commands.list()}async connect(t,e){let n=await this.sandbox.commands.connect(t,{onStdout:e?.onStdout,onStderr:e?.onStderr,timeoutMs:e?.timeoutMs});return {pid:n.pid,wait:async()=>{try{let r=await n.wait();return {exitCode:r.exitCode,stdout:r.stdout,stderr:r.stderr}}catch(r){if(r&&typeof r=="object"&&"exitCode"in r){let s=r;return {exitCode:s.exitCode,stdout:s.stdout??"",stderr:s.stderr??""}}throw r}},kill:()=>this.sandbox.commands.kill(n.pid)}}async sendStdin(t,e){await this.sandbox.commands.sendStdin(t,e);}async kill(t){return this.sandbox.commands.kill(t)}},u=class{constructor(t){this.sandbox=t;}async read(t){return x(t)?this.sandbox.files.read(t,{format:"bytes",requestTimeoutMs:3e5}):this.sandbox.files.read(t,{format:"text",requestTimeoutMs:3e5})}async write(t,e){await this.sandbox.files.write(t,l(e),{requestTimeoutMs:3e5});}async writeBatch(t){let e=t.map(n=>({path:n.path,data:l(n.data)}));await this.sandbox.files.write(e,{requestTimeoutMs:3e5});}async makeDir(t){await this.sandbox.files.makeDir(t);}async uploadUrl(t,e){return this.sandbox.uploadUrl(t,e?{useSignatureExpiration:e}:void 0)}async downloadUrl(t,e){return this.sandbox.downloadUrl(t,e?{useSignatureExpiration:e}:void 0)}async exists(t){return this.sandbox.files.exists(t)}async list(t){return (await this.sandbox.files.list(t)).map(n=>({name:n.name,path:n.path,type:n.type==="dir"?"dir":"file"}))}async remove(t){await this.sandbox.files.remove(t);}async rename(t,e){await this.sandbox.files.rename(t,e);}async readStream(t){return this.sandbox.files.read(t,{format:"stream"})}async writeStream(t,e){await this.sandbox.files.write(t,e);}async watchDir(t,e,n){let r=await this.sandbox.files.watchDir(t,e,{recursive:n?.recursive,timeoutMs:n?.timeoutMs,onExit:n?.onExit});return {stop:()=>r.stop()}}},o=class{constructor(t){this.sandbox=t;this.commands=new m(t),this.files=new u(t);}commands;files;get sandboxId(){return this.sandbox.sandboxId}getHost(t){return this.sandbox.getHost(t)}async isRunning(){return this.sandbox.isRunning()}async getInfo(){let t=await this.sandbox.getInfo();return {sandboxId:t.sandboxId,templateId:t.templateId,name:t.name,metadata:t.metadata??{},startedAt:a(t.startedAt),endAt:t.endAt?a(t.endAt):void 0}}async kill(){try{await this.sandbox.kill();}catch{await new Promise(t=>setTimeout(t,500)),await this.sandbox.kill();}}async pause(){await this.sandbox.betaPause();}},c=class{providerType="e2b";apiKey;defaultTimeoutMs;constructor(t){this.apiKey=t.apiKey,this.defaultTimeoutMs=t.defaultTimeoutMs??36e5;}async create(t){let e=t.timeoutMs??this.defaultTimeoutMs,n=await Sandbox.create(t.templateId,{apiKey:this.apiKey,envs:t.envs,metadata:t.metadata,timeoutMs:e});return t.workingDirectory&&await n.files.makeDir(t.workingDirectory),new o(n)}async connect(t,e){let n=await Sandbox.connect(t,{apiKey:this.apiKey,timeoutMs:e??this.defaultTimeoutMs});return new o(n)}async list(t){return (await Sandbox.list({apiKey:this.apiKey,query:{state:t?.state,metadata:t?.metadata},limit:t?.limit??100}).nextItems()).map(r=>({sandboxId:r.sandboxId,templateId:r.templateId,name:r.name,metadata:r.metadata??{},startedAt:a(r.startedAt),endAt:r.endAt?a(r.endAt):void 0}))}};function g(i={}){let t=i.apiKey??process.env.E2B_API_KEY;if(!t)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 c({...i,apiKey:t})}
|
|
2
|
+
export{c as E2BSandboxProvider,g as createE2BProvider};
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@evolvingmachines/e2b",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"ai",
|
|
6
|
+
"agents",
|
|
7
|
+
"sandbox",
|
|
8
|
+
"e2b",
|
|
9
|
+
"evolve-sdk",
|
|
10
|
+
"orchestration"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/evolving-machines-lab/evolve",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/evolving-machines-lab/evolve.git"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.cjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"license": "Proprietary Beta Evaluation License - See LICENSE",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"require": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup --minify",
|
|
34
|
+
"dev": "tsup --watch",
|
|
35
|
+
"type-check": "tsc --noEmit"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@e2b/code-interpreter": "^2.0.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.15.18",
|
|
42
|
+
"tsup": "^8.4.0",
|
|
43
|
+
"typescript": "^5.8.3"
|
|
44
|
+
}
|
|
45
|
+
}
|