@boxfab/code-interpreter 0.0.0-stage → 0.1.0-alpha.1
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 +10 -0
- package/README.md +82 -2
- package/dist/index.d.mts +562 -0
- package/dist/index.d.ts +562 -0
- package/dist/index.js +718 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +704 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FOUNDRYLABS, INC.
|
|
4
|
+
Copyright (c) 2026 ContextFab, Inc.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BoxFab Code Interpreter (JavaScript / TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run AI-generated code in isolated [BoxFab](https://boxfab.io) sandboxes, Jupyter-style:
|
|
4
|
+
Python, JavaScript, TypeScript, R, Java and Bash, with results such as text, tables and charts
|
|
5
|
+
returned as data.
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
### 1. Install the SDK
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @boxfab/code-interpreter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 2. Get a BoxFab API key
|
|
16
|
+
|
|
17
|
+
Get a key from the [BoxFab dashboard](https://dashboard.boxfab.io) and set it as `BOXFAB_API_KEY`.
|
|
18
|
+
The SDK reads only `BOXFAB_*` variables.
|
|
19
|
+
|
|
20
|
+
### 3. Execute code with code interpreter inside Sandbox
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { Sandbox } from '@boxfab/code-interpreter'
|
|
24
|
+
|
|
25
|
+
const sbx = await Sandbox.create()
|
|
26
|
+
await sbx.runCode('x = 1')
|
|
27
|
+
|
|
28
|
+
const execution = await sbx.runCode('x+=1; x')
|
|
29
|
+
console.log(execution.text) // outputs 2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 4. Bind the configuration to a client
|
|
33
|
+
|
|
34
|
+
The top-level `Sandbox` export reads its configuration from the environment variables. To use an explicit configuration — e.g. several API keys or domains in one process — create a `BoxFab` client and use the resources it exposes:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { BoxFab } from '@boxfab/code-interpreter'
|
|
38
|
+
|
|
39
|
+
const client = new BoxFab({ apiKey: 'e2b_***', domain: 'boxfab.io' })
|
|
40
|
+
|
|
41
|
+
const sbx = await client.Sandbox.create()
|
|
42
|
+
const execution = await sbx.runCode('x = 1; x += 1; x')
|
|
43
|
+
|
|
44
|
+
// The core resources are bound to the client's configuration as well.
|
|
45
|
+
const volume = await client.Volume.create('my-volume')
|
|
46
|
+
const exists = await client.Template.exists('my-template')
|
|
47
|
+
await client.Secret.create('openai-api-key', 'sk-***')
|
|
48
|
+
|
|
49
|
+
// The classes can be destructured and used like the top-level ones.
|
|
50
|
+
const { Sandbox } = client
|
|
51
|
+
const paginator = Sandbox.list()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Per-call options still take precedence over the client's options, and clients are isolated from each other and from the env-configured top-level exports.
|
|
55
|
+
|
|
56
|
+
## Under the hood
|
|
57
|
+
|
|
58
|
+
Sandboxes are created from the `code-interpreter-v1` template, which BoxFab provides to every team:
|
|
59
|
+
a Jupyter server with common data-science packages. BoxFab sandboxes are
|
|
60
|
+
[Firecracker](https://firecracker-microvm.github.io/) microVMs, run on the open-source
|
|
61
|
+
[E2B](https://github.com/e2b-dev/infra) sandbox infrastructure. This package is derived from the
|
|
62
|
+
open-source E2B Code Interpreter SDK;
|
|
63
|
+
[UPSTREAM.md](https://github.com/boxfab/js-sdk/blob/main/UPSTREAM.md) lists every change.
|
|
64
|
+
|
|
65
|
+
**Using the E2B Code Interpreter SDKs.** BoxFab serves the same API and provides the
|
|
66
|
+
`code-interpreter-v1` template, so the E2B Code Interpreter SDKs work with it as well. Set both
|
|
67
|
+
variables, the domain first:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
export E2B_DOMAIN=boxfab.io
|
|
71
|
+
export E2B_API_KEY="<your BoxFab API key>"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Without `E2B_DOMAIN`, the E2B SDKs send requests, including the key, to E2B's own service.
|
|
75
|
+
|
|
76
|
+
Tested against BoxFab with `e2b-code-interpreter` 2.11.6 (Python) and `@e2b/code-interpreter` 2.9.0
|
|
77
|
+
(JavaScript).
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT, as the E2B Code Interpreter SDK it is derived from; see [LICENSE](LICENSE).
|
|
82
|
+
|
|
83
|
+
BoxFab is a product of ContextFab, Inc.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import { BoxFabClientOpts, Sandbox as Sandbox$1, SandboxError, Secret, Template, Volume } from "boxfab";
|
|
2
|
+
export * from "boxfab";
|
|
3
|
+
/**
|
|
4
|
+
* Chart types
|
|
5
|
+
*/
|
|
6
|
+
declare enum ChartType {
|
|
7
|
+
LINE = "line",
|
|
8
|
+
SCATTER = "scatter",
|
|
9
|
+
BAR = "bar",
|
|
10
|
+
PIE = "pie",
|
|
11
|
+
BOX_AND_WHISKER = "box_and_whisker",
|
|
12
|
+
SUPERCHART = "superchart",
|
|
13
|
+
UNKNOWN = "unknown"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ax scale types
|
|
17
|
+
*/
|
|
18
|
+
declare enum ScaleType {
|
|
19
|
+
LINEAR = "linear",
|
|
20
|
+
DATETIME = "datetime",
|
|
21
|
+
CATEGORICAL = "categorical",
|
|
22
|
+
LOG = "log",
|
|
23
|
+
SYMLOG = "symlog",
|
|
24
|
+
LOGIT = "logit",
|
|
25
|
+
FUNCTION = "function",
|
|
26
|
+
FUNCTIONLOG = "functionlog",
|
|
27
|
+
ASINH = "asinh"
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Represents a chart.
|
|
31
|
+
*/
|
|
32
|
+
type Chart = {
|
|
33
|
+
type: ChartType;
|
|
34
|
+
title: string;
|
|
35
|
+
elements: any[];
|
|
36
|
+
};
|
|
37
|
+
type Chart2D = Chart & {
|
|
38
|
+
x_label?: string;
|
|
39
|
+
y_label?: string;
|
|
40
|
+
x_unit?: string;
|
|
41
|
+
y_unit?: string;
|
|
42
|
+
};
|
|
43
|
+
type PointData = {
|
|
44
|
+
label: string;
|
|
45
|
+
points: [number | string, number | string][];
|
|
46
|
+
};
|
|
47
|
+
type PointChart = Chart2D & {
|
|
48
|
+
x_ticks: (number | string)[];
|
|
49
|
+
x_scale: ScaleType;
|
|
50
|
+
x_tick_labels: string[];
|
|
51
|
+
y_ticks: (number | string)[];
|
|
52
|
+
y_scale: ScaleType;
|
|
53
|
+
y_tick_labels: string[];
|
|
54
|
+
elements: PointData[];
|
|
55
|
+
};
|
|
56
|
+
type LineChart = PointChart & {
|
|
57
|
+
type: ChartType.LINE;
|
|
58
|
+
};
|
|
59
|
+
type ScatterChart = PointChart & {
|
|
60
|
+
type: ChartType.SCATTER;
|
|
61
|
+
};
|
|
62
|
+
type BarData = {
|
|
63
|
+
label: string;
|
|
64
|
+
value: string;
|
|
65
|
+
group: string;
|
|
66
|
+
};
|
|
67
|
+
type BarChart = Chart2D & {
|
|
68
|
+
type: ChartType.BAR;
|
|
69
|
+
elements: BarData[];
|
|
70
|
+
};
|
|
71
|
+
type PieData = {
|
|
72
|
+
label: string;
|
|
73
|
+
angle: number;
|
|
74
|
+
radius: number;
|
|
75
|
+
};
|
|
76
|
+
type PieChart = Chart & {
|
|
77
|
+
type: ChartType.PIE;
|
|
78
|
+
elements: PieData[];
|
|
79
|
+
};
|
|
80
|
+
type BoxAndWhiskerData = {
|
|
81
|
+
label: string;
|
|
82
|
+
min: number;
|
|
83
|
+
first_quartile: number;
|
|
84
|
+
median: number;
|
|
85
|
+
third_quartile: number;
|
|
86
|
+
max: number;
|
|
87
|
+
outliers: number[];
|
|
88
|
+
};
|
|
89
|
+
type BoxAndWhiskerChart = Chart2D & {
|
|
90
|
+
type: ChartType.BOX_AND_WHISKER;
|
|
91
|
+
elements: BoxAndWhiskerData[];
|
|
92
|
+
};
|
|
93
|
+
type SuperChart = Chart & {
|
|
94
|
+
type: ChartType.SUPERCHART;
|
|
95
|
+
elements: Chart[];
|
|
96
|
+
};
|
|
97
|
+
type ChartTypes = LineChart | ScatterChart | BarChart | PieChart | BoxAndWhiskerChart | SuperChart;
|
|
98
|
+
/**
|
|
99
|
+
* Represents an output message from the sandbox code execution.
|
|
100
|
+
*/
|
|
101
|
+
declare class OutputMessage {
|
|
102
|
+
/**
|
|
103
|
+
* The output line.
|
|
104
|
+
*/
|
|
105
|
+
readonly line: string;
|
|
106
|
+
/**
|
|
107
|
+
* Unix epoch in nanoseconds.
|
|
108
|
+
*/
|
|
109
|
+
readonly timestamp: number;
|
|
110
|
+
/**
|
|
111
|
+
* Whether the output is an error.
|
|
112
|
+
*/
|
|
113
|
+
readonly error: boolean;
|
|
114
|
+
constructor(
|
|
115
|
+
/**
|
|
116
|
+
* The output line.
|
|
117
|
+
*/
|
|
118
|
+
line: string,
|
|
119
|
+
/**
|
|
120
|
+
* Unix epoch in nanoseconds.
|
|
121
|
+
*/
|
|
122
|
+
timestamp: number,
|
|
123
|
+
/**
|
|
124
|
+
* Whether the output is an error.
|
|
125
|
+
*/
|
|
126
|
+
error: boolean);
|
|
127
|
+
toString(): string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Represents an error that occurred during the execution of a cell.
|
|
131
|
+
* The error contains the name of the error, the value of the error, and the traceback.
|
|
132
|
+
*/
|
|
133
|
+
declare class ExecutionError {
|
|
134
|
+
/**
|
|
135
|
+
* Name of the error.
|
|
136
|
+
**/
|
|
137
|
+
name: string;
|
|
138
|
+
/**
|
|
139
|
+
* Value of the error.
|
|
140
|
+
**/
|
|
141
|
+
value: string;
|
|
142
|
+
/**
|
|
143
|
+
* The raw traceback of the error.
|
|
144
|
+
**/
|
|
145
|
+
traceback: string;
|
|
146
|
+
constructor(
|
|
147
|
+
/**
|
|
148
|
+
* Name of the error.
|
|
149
|
+
**/
|
|
150
|
+
name: string,
|
|
151
|
+
/**
|
|
152
|
+
* Value of the error.
|
|
153
|
+
**/
|
|
154
|
+
value: string,
|
|
155
|
+
/**
|
|
156
|
+
* The raw traceback of the error.
|
|
157
|
+
**/
|
|
158
|
+
traceback: string);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Represents a MIME type.
|
|
162
|
+
*/
|
|
163
|
+
type MIMEType = string;
|
|
164
|
+
type E2BData = {
|
|
165
|
+
data: Record<string, unknown>;
|
|
166
|
+
chart: ChartTypes;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Dictionary that maps MIME types to their corresponding representations of the data.
|
|
170
|
+
*/
|
|
171
|
+
type RawData = {
|
|
172
|
+
[key: MIMEType]: string;
|
|
173
|
+
} & E2BData;
|
|
174
|
+
/**
|
|
175
|
+
* Represents the data to be displayed as a result of executing a cell in a Jupyter notebook.
|
|
176
|
+
* The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
|
|
177
|
+
*
|
|
178
|
+
*
|
|
179
|
+
* The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
|
|
180
|
+
* as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
|
|
181
|
+
* for the actual result the representation is always present for the result, the other representations are always optional.
|
|
182
|
+
*/
|
|
183
|
+
declare class Result {
|
|
184
|
+
readonly isMainResult: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Text representation of the result.
|
|
187
|
+
*/
|
|
188
|
+
readonly text?: string;
|
|
189
|
+
/**
|
|
190
|
+
* HTML representation of the data.
|
|
191
|
+
*/
|
|
192
|
+
readonly html?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Markdown representation of the data.
|
|
195
|
+
*/
|
|
196
|
+
readonly markdown?: string;
|
|
197
|
+
/**
|
|
198
|
+
* SVG representation of the data.
|
|
199
|
+
*/
|
|
200
|
+
readonly svg?: string;
|
|
201
|
+
/**
|
|
202
|
+
* PNG representation of the data.
|
|
203
|
+
*/
|
|
204
|
+
readonly png?: string;
|
|
205
|
+
/**
|
|
206
|
+
* JPEG representation of the data.
|
|
207
|
+
*/
|
|
208
|
+
readonly jpeg?: string;
|
|
209
|
+
/**
|
|
210
|
+
* PDF representation of the data.
|
|
211
|
+
*/
|
|
212
|
+
readonly pdf?: string;
|
|
213
|
+
/**
|
|
214
|
+
* LaTeX representation of the data.
|
|
215
|
+
*/
|
|
216
|
+
readonly latex?: string;
|
|
217
|
+
/**
|
|
218
|
+
* JSON representation of the data.
|
|
219
|
+
*/
|
|
220
|
+
readonly json?: string;
|
|
221
|
+
/**
|
|
222
|
+
* JavaScript representation of the data.
|
|
223
|
+
*/
|
|
224
|
+
readonly javascript?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Contains the data from DataFrame.
|
|
227
|
+
*/
|
|
228
|
+
readonly data?: Record<string, unknown>;
|
|
229
|
+
/**
|
|
230
|
+
* Contains the chart data.
|
|
231
|
+
*/
|
|
232
|
+
readonly chart?: ChartTypes;
|
|
233
|
+
/**
|
|
234
|
+
* Extra data that can be included. Not part of the standard types.
|
|
235
|
+
*/
|
|
236
|
+
readonly extra?: any;
|
|
237
|
+
readonly raw: RawData;
|
|
238
|
+
constructor(rawData: RawData, isMainResult: boolean);
|
|
239
|
+
/**
|
|
240
|
+
* Returns all the formats available for the result.
|
|
241
|
+
*
|
|
242
|
+
* @returns Array of strings representing the formats available for the result.
|
|
243
|
+
*/
|
|
244
|
+
formats(): string[];
|
|
245
|
+
/**
|
|
246
|
+
* Returns the serializable representation of the result.
|
|
247
|
+
*/
|
|
248
|
+
toJSON(): {
|
|
249
|
+
extra?: any;
|
|
250
|
+
text: string | undefined;
|
|
251
|
+
html: string | undefined;
|
|
252
|
+
markdown: string | undefined;
|
|
253
|
+
svg: string | undefined;
|
|
254
|
+
png: string | undefined;
|
|
255
|
+
jpeg: string | undefined;
|
|
256
|
+
pdf: string | undefined;
|
|
257
|
+
latex: string | undefined;
|
|
258
|
+
json: string | undefined;
|
|
259
|
+
javascript: string | undefined;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.
|
|
264
|
+
*/
|
|
265
|
+
type Logs = {
|
|
266
|
+
/**
|
|
267
|
+
* List of strings printed to stdout by prints, subprocesses, etc.
|
|
268
|
+
*/
|
|
269
|
+
stdout: string[];
|
|
270
|
+
/**
|
|
271
|
+
* List of strings printed to stderr by prints, subprocesses, etc.
|
|
272
|
+
*/
|
|
273
|
+
stderr: string[];
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Represents the result of a cell execution.
|
|
277
|
+
*/
|
|
278
|
+
declare class Execution {
|
|
279
|
+
/**
|
|
280
|
+
* List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).
|
|
281
|
+
*/
|
|
282
|
+
results: Result[];
|
|
283
|
+
/**
|
|
284
|
+
* Logs printed to stdout and stderr during execution.
|
|
285
|
+
*/
|
|
286
|
+
logs: Logs;
|
|
287
|
+
/**
|
|
288
|
+
* An Error object if an error occurred, null otherwise.
|
|
289
|
+
*/
|
|
290
|
+
error?: ExecutionError | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* Execution count of the cell.
|
|
293
|
+
*/
|
|
294
|
+
executionCount?: number | undefined;
|
|
295
|
+
constructor(
|
|
296
|
+
/**
|
|
297
|
+
* List of result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).
|
|
298
|
+
*/
|
|
299
|
+
results?: Result[],
|
|
300
|
+
/**
|
|
301
|
+
* Logs printed to stdout and stderr during execution.
|
|
302
|
+
*/
|
|
303
|
+
logs?: Logs,
|
|
304
|
+
/**
|
|
305
|
+
* An Error object if an error occurred, null otherwise.
|
|
306
|
+
*/
|
|
307
|
+
error?: ExecutionError | undefined,
|
|
308
|
+
/**
|
|
309
|
+
* Execution count of the cell.
|
|
310
|
+
*/
|
|
311
|
+
executionCount?: number | undefined);
|
|
312
|
+
/**
|
|
313
|
+
* Returns the text representation of the main result of the cell.
|
|
314
|
+
*/
|
|
315
|
+
get text(): string | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Returns the serializable representation of the execution result.
|
|
318
|
+
*/
|
|
319
|
+
toJSON(): {
|
|
320
|
+
results: Result[];
|
|
321
|
+
logs: Logs;
|
|
322
|
+
error: ExecutionError | undefined;
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Represents a context for code execution.
|
|
327
|
+
*/
|
|
328
|
+
type Context = {
|
|
329
|
+
/**
|
|
330
|
+
* The ID of the context.
|
|
331
|
+
*/
|
|
332
|
+
id: string;
|
|
333
|
+
/**
|
|
334
|
+
* The language of the context.
|
|
335
|
+
*/
|
|
336
|
+
language: string;
|
|
337
|
+
/**
|
|
338
|
+
* The working directory of the context.
|
|
339
|
+
*/
|
|
340
|
+
cwd: string;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Supported language for code execution.
|
|
344
|
+
*/
|
|
345
|
+
type RunCodeLanguage = 'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | (string & {});
|
|
346
|
+
/**
|
|
347
|
+
* Options for running code.
|
|
348
|
+
*/
|
|
349
|
+
interface RunCodeOpts {
|
|
350
|
+
/**
|
|
351
|
+
* Callback for handling stdout messages.
|
|
352
|
+
*/
|
|
353
|
+
onStdout?: (output: OutputMessage) => Promise<any> | any;
|
|
354
|
+
/**
|
|
355
|
+
* Callback for handling stderr messages.
|
|
356
|
+
*/
|
|
357
|
+
onStderr?: (output: OutputMessage) => Promise<any> | any;
|
|
358
|
+
/**
|
|
359
|
+
* Callback for handling the final execution result.
|
|
360
|
+
*/
|
|
361
|
+
onResult?: (data: Result) => Promise<any> | any;
|
|
362
|
+
/**
|
|
363
|
+
* Callback for handling the `ExecutionError` object.
|
|
364
|
+
*/
|
|
365
|
+
onError?: (error: ExecutionError) => Promise<any> | any;
|
|
366
|
+
/**
|
|
367
|
+
* Custom environment variables for code execution.
|
|
368
|
+
*
|
|
369
|
+
* @default {}
|
|
370
|
+
*/
|
|
371
|
+
envs?: Record<string, string>;
|
|
372
|
+
/**
|
|
373
|
+
* Timeout for the code execution in **milliseconds**.
|
|
374
|
+
*
|
|
375
|
+
* @default 60_000 // 60 seconds
|
|
376
|
+
*/
|
|
377
|
+
timeoutMs?: number;
|
|
378
|
+
/**
|
|
379
|
+
* Timeout for the request in **milliseconds**.
|
|
380
|
+
*
|
|
381
|
+
* @default 30_000 // 30 seconds
|
|
382
|
+
*/
|
|
383
|
+
requestTimeoutMs?: number;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Options for creating a code context.
|
|
387
|
+
*/
|
|
388
|
+
interface CreateCodeContextOpts {
|
|
389
|
+
/**
|
|
390
|
+
* Working directory for the context.
|
|
391
|
+
*
|
|
392
|
+
* @default /home/user
|
|
393
|
+
*/
|
|
394
|
+
cwd?: string;
|
|
395
|
+
/**
|
|
396
|
+
* Language for the context.
|
|
397
|
+
*
|
|
398
|
+
* @default python
|
|
399
|
+
*/
|
|
400
|
+
language?: RunCodeLanguage;
|
|
401
|
+
/**
|
|
402
|
+
* Timeout for the request in **milliseconds**.
|
|
403
|
+
*
|
|
404
|
+
* @default 30_000 // 30 seconds
|
|
405
|
+
*/
|
|
406
|
+
requestTimeoutMs?: number;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* BoxFab cloud sandbox is a secure and isolated cloud environment.
|
|
410
|
+
*
|
|
411
|
+
* The sandbox allows you to:
|
|
412
|
+
* - Access Linux OS
|
|
413
|
+
* - Create, list, and delete files and directories
|
|
414
|
+
* - Run commands
|
|
415
|
+
* - Run isolated code
|
|
416
|
+
* - Access the internet
|
|
417
|
+
*
|
|
418
|
+
* Check docs [here](https://boxfab.dev/docs).
|
|
419
|
+
*
|
|
420
|
+
* Use {@link Sandbox.create} to create a new sandbox.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* import { Sandbox } from '@boxfab/code-interpreter'
|
|
425
|
+
*
|
|
426
|
+
* const sandbox = await Sandbox.create()
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
declare class Sandbox extends Sandbox$1 {
|
|
430
|
+
protected static readonly defaultTemplate: string;
|
|
431
|
+
protected get jupyterUrl(): string;
|
|
432
|
+
/**
|
|
433
|
+
* Run the code for the specified language.
|
|
434
|
+
*
|
|
435
|
+
* Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
|
|
436
|
+
* If no language is specified, Python is used.
|
|
437
|
+
*
|
|
438
|
+
* You can reference previously defined variables, imports, and functions in the code.
|
|
439
|
+
*
|
|
440
|
+
* @param code code to execute.
|
|
441
|
+
* @param opts options for executing the code.
|
|
442
|
+
*
|
|
443
|
+
* @returns `Execution` result object.
|
|
444
|
+
*/
|
|
445
|
+
runCode(code: string, opts?: RunCodeOpts & {
|
|
446
|
+
/**
|
|
447
|
+
* Language to use for code execution.
|
|
448
|
+
*
|
|
449
|
+
* If not defined, the default Python context is used.
|
|
450
|
+
*/
|
|
451
|
+
language?: RunCodeLanguage;
|
|
452
|
+
}): Promise<Execution>;
|
|
453
|
+
/**
|
|
454
|
+
* Runs the code in the specified context, if not specified, the default context is used.
|
|
455
|
+
*
|
|
456
|
+
* Specify the `language` or `context` option to run the code as a different language or in a different `Context`.
|
|
457
|
+
*
|
|
458
|
+
* You can reference previously defined variables, imports, and functions in the code.
|
|
459
|
+
*
|
|
460
|
+
* @param code code to execute.
|
|
461
|
+
* @param opts options for executing the code
|
|
462
|
+
*
|
|
463
|
+
* @returns `Execution` result object
|
|
464
|
+
*/
|
|
465
|
+
runCode(code: string, opts?: RunCodeOpts & {
|
|
466
|
+
/**
|
|
467
|
+
* Context to run the code in.
|
|
468
|
+
*/
|
|
469
|
+
context?: Context;
|
|
470
|
+
}): Promise<Execution>;
|
|
471
|
+
/**
|
|
472
|
+
* Creates a new context to run code in.
|
|
473
|
+
*
|
|
474
|
+
* @param opts options for creating the context.
|
|
475
|
+
*
|
|
476
|
+
* @returns context object.
|
|
477
|
+
*/
|
|
478
|
+
createCodeContext(opts?: CreateCodeContextOpts): Promise<Context>;
|
|
479
|
+
/**
|
|
480
|
+
* Removes a context.
|
|
481
|
+
*
|
|
482
|
+
* @param context context to remove.
|
|
483
|
+
*
|
|
484
|
+
* @returns void.
|
|
485
|
+
*/
|
|
486
|
+
removeCodeContext(context: Context | string): Promise<void>;
|
|
487
|
+
/**
|
|
488
|
+
* List all contexts.
|
|
489
|
+
*
|
|
490
|
+
* @returns list of contexts.
|
|
491
|
+
*/
|
|
492
|
+
listCodeContexts(): Promise<Context[]>;
|
|
493
|
+
/**
|
|
494
|
+
* Restart a context.
|
|
495
|
+
*
|
|
496
|
+
* @param context context to restart.
|
|
497
|
+
*
|
|
498
|
+
* @returns void.
|
|
499
|
+
*/
|
|
500
|
+
restartCodeContext(context: Context | string): Promise<void>;
|
|
501
|
+
/**
|
|
502
|
+
* Returns the error to throw for a failed request. If the connection was
|
|
503
|
+
* closed because the sandbox was killed mid-request, returns a descriptive
|
|
504
|
+
* `TimeoutError`. Otherwise falls back to formatting request timeouts and
|
|
505
|
+
* re-throwing the original error.
|
|
506
|
+
*/
|
|
507
|
+
private handleRequestError;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* BoxFab client with an explicitly bound connection configuration.
|
|
511
|
+
*
|
|
512
|
+
* The resources exposed by the client ({@link BoxFab.Sandbox},
|
|
513
|
+
* {@link BoxFab.Volume}, {@link BoxFab.Template}, {@link BoxFab.Secret}) behave exactly
|
|
514
|
+
* like the top-level `Sandbox` / `Volume` / `Template` / `Secret` exports,
|
|
515
|
+
* except the options passed to the client are used as the defaults instead of
|
|
516
|
+
* the environment variables.
|
|
517
|
+
* Per-call options still take precedence over the client's options.
|
|
518
|
+
*
|
|
519
|
+
* Multiple clients are fully isolated from each other and from the top-level
|
|
520
|
+
* env-configured exports.
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* import { BoxFab } from '@boxfab/code-interpreter'
|
|
525
|
+
*
|
|
526
|
+
* const client = new BoxFab({ apiKey: 'e2b_...', domain: 'boxfab.io' })
|
|
527
|
+
*
|
|
528
|
+
* const sandbox = await client.Sandbox.create()
|
|
529
|
+
* const execution = await sandbox.runCode('x = 1; x += 1; x')
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare class BoxFab {
|
|
533
|
+
/**
|
|
534
|
+
* Code Interpreter `Sandbox` class bound to this client's connection
|
|
535
|
+
* configuration.
|
|
536
|
+
*/
|
|
537
|
+
readonly Sandbox: typeof Sandbox;
|
|
538
|
+
/**
|
|
539
|
+
* `Volume` class bound to this client's connection configuration.
|
|
540
|
+
*/
|
|
541
|
+
readonly Volume: typeof Volume;
|
|
542
|
+
/**
|
|
543
|
+
* `Template` bound to this client's connection configuration. Both the
|
|
544
|
+
* builder (`client.Template()`) and the statics
|
|
545
|
+
* (`client.Template.build(...)`, `client.Template.exists(...)`, …) work like
|
|
546
|
+
* the top-level `Template`.
|
|
547
|
+
*/
|
|
548
|
+
readonly Template: typeof Template;
|
|
549
|
+
/**
|
|
550
|
+
* `Secret` class bound to this client's connection configuration.
|
|
551
|
+
*/
|
|
552
|
+
readonly Secret: typeof Secret;
|
|
553
|
+
/**
|
|
554
|
+
* Create a new client with the connection options bound to it.
|
|
555
|
+
*
|
|
556
|
+
* @param opts connection options used as the defaults for every call made
|
|
557
|
+
* through this client's resource classes.
|
|
558
|
+
*/
|
|
559
|
+
constructor(opts?: BoxFabClientOpts);
|
|
560
|
+
}
|
|
561
|
+
export { type BarChart, type BarData, type BoxAndWhiskerChart, type BoxAndWhiskerData, BoxFab, BoxFab as E2B, type BoxFabClientOpts, type BoxFabClientOpts as E2BClientOpts, type Chart, type ChartType, type ChartTypes, type Context, type CreateCodeContextOpts, type Execution, type ExecutionError, type LineChart, type Logs, type MIMEType, type OutputMessage, type PieChart, type PieData, type PointData, type RawData, type Result, type RunCodeLanguage, type RunCodeOpts, Sandbox, Sandbox as default, type ScaleType, type ScatterChart, type SuperChart };
|
|
562
|
+
//# sourceMappingURL=index.d.mts.map
|