@solarisdk/e2b-compat 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPAT.md +88 -0
- package/LICENSE +17 -0
- package/LICENSE-E2B +9 -0
- package/NOTICE +13 -0
- package/README.md +67 -2
- package/dist/box.d.ts +28 -0
- package/dist/box.d.ts.map +1 -0
- package/dist/box.js +102 -0
- package/dist/box.js.map +1 -0
- package/dist/code-interpreter.d.ts +157 -0
- package/dist/code-interpreter.d.ts.map +1 -0
- package/dist/code-interpreter.js +357 -0
- package/dist/code-interpreter.js.map +1 -0
- package/dist/commands.d.ts +141 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +302 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +32 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +92 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +79 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +159 -0
- package/dist/errors.js.map +1 -0
- package/dist/filesystem.d.ts +99 -0
- package/dist/filesystem.d.ts.map +1 -0
- package/dist/filesystem.js +245 -0
- package/dist/filesystem.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox.d.ts +190 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +431 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/template.d.ts +187 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +360 -0
- package/dist/template.js.map +1 -0
- package/package.json +52 -4
package/COMPAT.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# COMPAT.md: E2B SDK compatibility (target: e2b 2.59 and @e2b/code-interpreter 2.9)
|
|
2
|
+
|
|
3
|
+
Legend: **OK** works and is tested; **DIFF** works with a behaviour difference (explained); **NO** throws
|
|
4
|
+
`SolariCompatUnsupported` naming the feature. "Live" means `test-live/staging.test.mjs` runs it against staging.
|
|
5
|
+
|
|
6
|
+
## At a glance
|
|
7
|
+
- **Works**: sandbox create / connect / list / info / kill / timeout / pause / resume / metrics, snapshots and fork,
|
|
8
|
+
commands (foreground, background, stdin, list, kill), PTY, the filesystem API (read in four formats, write one or many,
|
|
9
|
+
list with depth, info, exists, makeDir, rename, remove, watch, signed upload and download URLs), the code interpreter
|
|
10
|
+
(`runCode` with state, callbacks, errors, bash, contexts, rich results), the template builder and `Template.build`.
|
|
11
|
+
- **Not available** (throws): egress network rules, MCP gateway, IAM tokens, E2B Volumes and Secrets APIs, template tags,
|
|
12
|
+
`setStartCmd` / `setReadyCmd`, `setUser`, Dockerfile input, private registries, start-time and template filters on
|
|
13
|
+
`Sandbox.list`, filesystem-only pause and `onResume: 'reboot'`, JavaScript/TypeScript/R/Java in `runCode`.
|
|
14
|
+
|
|
15
|
+
## Setup and configuration
|
|
16
|
+
| E2B | Here |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `E2B_API_KEY`, `apiKey` | Only `slr_…` keys are used; see README. |
|
|
19
|
+
| `E2B_DOMAIN`, `E2B_API_URL`, `domain`, `apiUrl` | Honoured only when they point at Solari or loopback. |
|
|
20
|
+
| `headers`, `apiHeaders`, `proxy` | NO. |
|
|
21
|
+
| `requestTimeoutMs`, `retries`, `debug`, `logger`, `signal`, `validateApiKey`, `httpVersion` | Accepted, ignored (Solari's transport has its own retry policy). Every option that is accepted but ignored is marked "ignored" in this file; any other option either works or throws. |
|
|
22
|
+
| `new E2B(opts)` client object, `Volume`, `Secret` | NO. Use the static `Sandbox` / `Template` APIs. |
|
|
23
|
+
|
|
24
|
+
## Sandbox
|
|
25
|
+
| Call | Status | Notes |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `Sandbox.create(template?, opts)` | OK, live | `template`: `base`, a template name from `Template.build`, or a `tpl_…` id. Default `base` (`code-interpreter-v1` in `/code-interpreter`). |
|
|
28
|
+
| `timeoutMs` | DIFF | E2B's is a lifetime; Solari's is a rolling idle window that resets on use. Default 300 000 as in E2B. The per-plan deadline still bounds total life. |
|
|
29
|
+
| `metadata`, `envs` | OK, live | |
|
|
30
|
+
| `lifecycle: { onTimeout, autoResume }` | OK | `onTimeout: { action: 'pause', mode: 'filesystem' }` pauses with RAM too (a superset). |
|
|
31
|
+
| `volumeMounts: { path: 'vol_…' or name }` | DIFF | Solari persistent volumes by id or name. `Volume` objects: NO. |
|
|
32
|
+
| `secure`, `sandboxUrl` | Accepted, ignored (sandboxes are always access-controlled). |
|
|
33
|
+
| `allowInternetAccess: false`, `network`, `iam`, `mcp` | NO. |
|
|
34
|
+
| `Sandbox.connect(id, { timeoutMs })`, `sbx.connect()` | OK, live | Resumes a paused or stopped sandbox. `onResume: 'reboot'`: NO. |
|
|
35
|
+
| `Sandbox.list(opts)` | DIFF | Pages with `hasNext` / `nextItems()`. Filters: `metadata`, `state`. `startedAfter` and `template`: NO. `templateId` in each `SandboxInfo` is empty (Solari does not report it). Solari `starting` counts as running, `stopped` as paused. |
|
|
36
|
+
| `getInfo`, `isRunning`, `kill`, `setTimeout` | OK, live | `kill` returns `false` for a sandbox that is already gone. |
|
|
37
|
+
| `getMetrics()` | DIFF | One current sample (no history); `memCache` is 0. |
|
|
38
|
+
| `pause()` / `Sandbox.pause(id)` | OK, live | Keeps RAM and disk. `mode: 'filesystem'`, `keepMemory: false`: treated as a full pause. |
|
|
39
|
+
| `createSnapshot({ name })`, `listSnapshots`, `Sandbox.deleteSnapshot` | OK, live | Snapshots are RAM + disk. `mode: 'filesystem'` is ignored. A name lookup reads at most 1000 snapshots, so a match beyond that is not found. Instance `listSnapshots()` lists the snapshots taken of that sandbox. |
|
|
40
|
+
| `fork({ count })` | DIFF, live | Checkpoint then `count` new sandboxes from it; the checkpoint is deleted afterwards. Returns `Sandbox \| Error` per copy. |
|
|
41
|
+
| `getHost(port)` | NO | E2B returns the host synchronously; Solari mints preview URLs on the gateway. Use the extension `await sbx.getPreviewUrl(port)` (returns `{ url, token? }`). |
|
|
42
|
+
| `uploadUrl`, `downloadUrl` | OK | `user` option: NO. |
|
|
43
|
+
| `updateNetwork`, `getMcpUrl`, `getMcpToken` (returns undefined) | NO | |
|
|
44
|
+
| `git` | NO | Deprecated in E2B; use `commands.run('git …')`. |
|
|
45
|
+
| Lifecycle events API, webhooks, OTel export, sandbox logs API | NO | |
|
|
46
|
+
|
|
47
|
+
## Commands and PTY
|
|
48
|
+
| Call | Status | Notes |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `commands.run(cmd, opts)` | OK, live | Runs `bash -lc` (a POSIX `sh` on images without bash) from the home directory. A non-zero exit throws `CommandExitError`, as E2B does. `timeoutMs` default 60 000 (0 disables). `onStdout` / `onStderr`, `envs`, `cwd`, `user`: OK. |
|
|
51
|
+
| `commands.run(cmd, { background: true })` | OK, live | Returns a `CommandHandle`: `pid`, `stdout`, `stderr`, `exitCode`, `wait()`, `kill()`, `sendStdin()`, `disconnect()`. |
|
|
52
|
+
| `commands.list`, `kill(pid)`, `sendStdin(pid)`, `connect(pid)`, `streamInput(pid)` | DIFF | `pid` is a number this package hands out; Solari keeps the process on the control channel that started it. These work for commands started by **this process**; another process gets `NotFoundError`. The process and context tables live as long as the process and are not pruned. |
|
|
53
|
+
| `closeStdin` | NO | Solari cannot close a command's stdin. End the program another way (for example a sentinel line). |
|
|
54
|
+
| `pty.create`, `sendInput`, `resize`, `kill`, `streamInput` | OK, live | `connect(pid)`: this process only. `handle.wait()` resolves when `kill` is called; a shell that exits by itself is not observed. `user`: NO. |
|
|
55
|
+
|
|
56
|
+
## Filesystem
|
|
57
|
+
| Call | Status | Notes |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `read` (`text`, `bytes`, `blob`, `stream`) | OK, live | Relative paths resolve against the guest's `$HOME`. `stream` is a single chunk. A missing file throws `FileNotFoundError`. |
|
|
60
|
+
| `write(path, data)`, `write(entries)`, `writeFiles` | OK, live | `string`, `ArrayBuffer`, `Blob`, `ReadableStream`. Parent directories are created. `metadata`: NO. `gzip`, `useOctetStream`: accepted, ignored. |
|
|
61
|
+
| `list(path, { depth })`, `getInfo` | DIFF, live | `owner` and `group` are empty; `symlinkTarget` is not reported (symlinks are followed: a link lists as its target file). |
|
|
62
|
+
| `exists`, `makeDir`, `rename`, `remove` | OK, live | |
|
|
63
|
+
| `watchDir(path, onEvent, { recursive })` | DIFF, live | Event `name` is relative to the watched path. Solari reports creates as `write`. `includeEntry`: NO. A watch ends after `timeoutMs` (default 60 s) as in E2B. |
|
|
64
|
+
| `user` on any filesystem call | NO | |
|
|
65
|
+
|
|
66
|
+
## Code interpreter (`@solarisdk/e2b-compat/code-interpreter`)
|
|
67
|
+
| Call | Status | Notes |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `runCode(code, { language? \| context? })` | OK, live | Python (and `bash`). Passing both `language` and `context` throws `InvalidArgumentError`. Python state persists across calls in the default context. |
|
|
70
|
+
| Other languages | NO | The guest ships a Python kernel only: `javascript`, `typescript`, `r`, `java` throw. `bash` runs each call as a fresh shell (no state between calls). |
|
|
71
|
+
| `onStdout`, `onStderr`, `onResult`, `onError` | DIFF | Called after the run finishes, not while it runs (Solari returns the result in one reply). |
|
|
72
|
+
| `Execution` (`results`, `logs`, `error`, `text`) | DIFF | `executionCount` is undefined. `error` is `{ name, value, traceback }`. The last result with a text repr is `isMainResult`. |
|
|
73
|
+
| `Result` formats | DIFF | `text`, `html`, `markdown`, `svg`, `png`, `jpeg`, `latex`, `json`, `chart`. `pdf`, `javascript`, `data` and `extra` are not produced. `chart` appears when the guest kernel extracts a structured chart (not for every figure). |
|
|
74
|
+
| `envs`, per-run | NO | |
|
|
75
|
+
| `timeoutMs` | DIFF | Stops waiting and throws `TimeoutError`; the kernel keeps running the code. No default timeout. |
|
|
76
|
+
| `createCodeContext({ cwd, language })` | OK, live | Python only. |
|
|
77
|
+
| `listCodeContexts`, `removeCodeContext`, `restartCodeContext` | DIFF, live | Solari cannot list or destroy kernels. `list` returns contexts created by this process; `remove` forgets the context (the kernel stays until the sandbox ends); `restart` clears the context's variables and working directory without restarting the process. |
|
|
78
|
+
| Default template | DIFF | `code-interpreter-v1` is built into your org on first `Sandbox.create()` without a template: about 80 seconds, billed as a template build. Two processes that both find it missing each start a build, so prebuild it once with `buildCodeInterpreterTemplate()`. |
|
|
79
|
+
|
|
80
|
+
## Templates
|
|
81
|
+
| Call | Status | Notes |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `Template().fromBaseImage / fromImage / fromPythonImage / fromNodeImage / fromUbuntuImage / fromDebianImage / fromAlpineImage / fromFedoraImage / fromArchImage / fromBunImage / fromTemplate` | OK, live | `fromBaseImage()` is Solari's base image. The others are public registry images. Credentials, `fromAWSRegistry`, `fromGCPRegistry`, `fromDockerfile`: NO. |
|
|
84
|
+
| `aptInstall`, `pipInstall`, `npmInstall`, `bunInstall`, `runCmd`, `copy`, `copyItems`, `makeDir`, `remove`, `rename`, `makeSymlink`, `gitClone`, `setWorkdir`, `setEnvs` | OK, live | Compiled onto Solari's image steps. `setEnvs` persists in the template (E2B: build time only). `user` options other than `root`: NO. `copy` reads from `fileContextPath` (default: the current directory). |
|
|
85
|
+
| `setUser`, `setStartCmd`, `setReadyCmd`, `addMcpServer`, dev containers | NO | Solari templates run no start command. Start processes after `Sandbox.create` with `commands.run(..., { background: true })`. |
|
|
86
|
+
| `skipCache()` | Accepted, ignored. |
|
|
87
|
+
| `Template.build(template, name)`, `buildInBackground`, `getBuildStatus`, `exists` | OK, live | `name:latest` is accepted; any other tag, and the `tags` option: NO (Solari templates are not versioned). `onBuildLogs` receives start and end entries. |
|
|
88
|
+
| `Template.assignTags`, `removeTags`, `getTags`, `toJSON`, `toDockerfile` | NO | |
|
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2026 Solari Desktop
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
package/LICENSE-E2B
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FOUNDRYLABS, INC.
|
|
4
|
+
|
|
5
|
+
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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
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/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
@solarisdk/e2b-compat
|
|
2
|
+
|
|
3
|
+
The public API shapes (class, method, option and error names, and the result types) follow the `e2b` and
|
|
4
|
+
`@e2b/code-interpreter` JavaScript SDKs (e2b 2.59, @e2b/code-interpreter 2.9), which are distributed under the MIT
|
|
5
|
+
licence:
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2025 FOUNDRYLABS, INC.
|
|
8
|
+
|
|
9
|
+
The licence text is reproduced in LICENSE-E2B. No E2B source code is bundled; the implementation is written against the
|
|
10
|
+
Solari SDKs (@solarisdk/core, @solarisdk/sandbox).
|
|
11
|
+
|
|
12
|
+
This package is not affiliated with, endorsed by, or sponsored by E2B or FOUNDRYLABS, INC. "E2B" is the name of their
|
|
13
|
+
product; it appears here only to describe API compatibility.
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @solarisdk/e2b-compat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An E2B-compatible API on top of [Solari Sandbox](https://getsolari.com). Change the import, keep your sandbox code.
|
|
4
|
+
|
|
5
|
+
> **Not affiliated with, endorsed by, or sponsored by E2B.** "E2B" is E2B's product name; it appears here only to
|
|
6
|
+
> describe API compatibility. The API shapes follow the MIT-licensed `e2b` and `@e2b/code-interpreter` SDKs, see
|
|
7
|
+
> [NOTICE](./NOTICE). Do not look for this package under `@e2b/*`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// before: import { Sandbox } from '@e2b/code-interpreter';
|
|
11
|
+
import { Sandbox } from '@solarisdk/e2b-compat/code-interpreter';
|
|
12
|
+
|
|
13
|
+
const sbx = await Sandbox.create(); // SOLARI_API_KEY in the environment
|
|
14
|
+
const execution = await sbx.runCode('x = 1\nx + 1');
|
|
15
|
+
console.log(execution.text); // "2"
|
|
16
|
+
const r = await sbx.commands.run('echo hello');
|
|
17
|
+
console.log(r.stdout);
|
|
18
|
+
await sbx.files.write('/tmp/a.txt', 'hi');
|
|
19
|
+
await sbx.kill();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The plain `e2b` package maps to the package root:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// before: import { Sandbox, Template } from 'e2b';
|
|
26
|
+
import { Sandbox, Template } from '@solarisdk/e2b-compat';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Exports: `Sandbox` (default and named; create, connect, list, kill, pause, snapshots, fork, `commands`, `files`, `pty`),
|
|
30
|
+
`Template` and the template builder, the E2B error classes (`SandboxError`, `TimeoutError`, `NotFoundError`,
|
|
31
|
+
`FileNotFoundError`, `CommandExitError`, `AuthenticationError`, ...), `SolariCompatUnsupported`, and from
|
|
32
|
+
`/code-interpreter`: `Sandbox` with `runCode` and code contexts, `Execution`, `Result`, `Context`.
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
| | Order |
|
|
37
|
+
|---|---|
|
|
38
|
+
| API key | `apiKey` option, `SOLARI_API_KEY`, `E2B_API_KEY`: only an `slr_…` Solari key is ever used. A non-`slr_` value (for example a real E2B key) is skipped with a warning (the key is never printed or sent); with no Solari key the call throws |
|
|
39
|
+
| Base URL | `apiUrl` / `domain` option (Solari or loopback only, anything else throws), `SOLARI_BASE_URL`, `E2B_API_URL` / `E2B_DOMAIN` (only if they point at getsolari.com or loopback; otherwise ignored with a warning), default `https://api.getsolari.com` |
|
|
40
|
+
|
|
41
|
+
An E2B key does not work here: use a Solari API key.
|
|
42
|
+
|
|
43
|
+
## The code-interpreter template
|
|
44
|
+
|
|
45
|
+
`@e2b/code-interpreter` runs in a template with a data-analysis stack (pandas, numpy, scipy, scikit-learn, seaborn,
|
|
46
|
+
plotly, ...). Solari builds the equivalent, `code-interpreter-v1`, into your org the first time
|
|
47
|
+
`Sandbox.create()` is called without a template (about 80 seconds, once). To do it ahead of time:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { buildCodeInterpreterTemplate } from '@solarisdk/e2b-compat/code-interpreter';
|
|
51
|
+
await buildCodeInterpreterTemplate();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`SOLARI_CODE_INTERPRETER_TEMPLATE` overrides the template (a name or `tpl_…` id). The package list is
|
|
55
|
+
`CODE_INTERPRETER_PACKAGES`; the very large audio, NLP and computer-vision wheels E2B ships (spacy, librosa, opencv,
|
|
56
|
+
numba, gensim) are not included.
|
|
57
|
+
|
|
58
|
+
## What works, what does not
|
|
59
|
+
|
|
60
|
+
[COMPAT.md](./COMPAT.md) is the support matrix. Anything Solari cannot do throws `SolariCompatUnsupported`
|
|
61
|
+
(a `SandboxError`) naming the feature; nothing is silently ignored. The sibling Python package is
|
|
62
|
+
`sdk/python-e2b-compat` (`solari-e2b-compat`) and follows the same rules.
|
|
63
|
+
|
|
64
|
+
## Tests
|
|
65
|
+
|
|
66
|
+
- `npm test`: offline unit tests, a fake gateway.
|
|
67
|
+
- `SOLARI_API_KEY=… SOLARI_BASE_URL=https://api-sta.getsolari.com node --test test-live/staging.test.mjs`: live tests
|
|
68
|
+
against staging. They create their own sandboxes, snapshots and templates and delete only those.
|
package/dist/box.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Sandbox as CoreSandbox } from "@solarisdk/core";
|
|
2
|
+
import type { Conn } from "./config.js";
|
|
3
|
+
/** Native image sandboxes: a bash when the image has one, else sh. The command is "$1", so it is never re-parsed. */
|
|
4
|
+
export declare const NATIVE_SHELL_SCRIPT = "if [ -x /bin/bash ]; then exec /bin/bash -c \"$1\"; else exec /bin/sh -c \"$1\"; fi";
|
|
5
|
+
/** `[program, args]` for an E2B-style shell string: `bash -lc` normally (E2B runs `/bin/bash -l -c`), native-image safe otherwise. */
|
|
6
|
+
export declare function shellArgs(native: boolean, command: string): [string, string[]];
|
|
7
|
+
/** @internal */
|
|
8
|
+
export declare class Box {
|
|
9
|
+
readonly conn: Conn;
|
|
10
|
+
readonly id: string;
|
|
11
|
+
private h;
|
|
12
|
+
private native;
|
|
13
|
+
private homeP;
|
|
14
|
+
constructor(conn: Conn, id: string, initial?: CoreSandbox);
|
|
15
|
+
private attach;
|
|
16
|
+
/** The connected control handle, cached. */
|
|
17
|
+
handle(): Promise<CoreSandbox>;
|
|
18
|
+
drop(): void;
|
|
19
|
+
/** Close this process's own control channel (if open) before the sandbox is paused or killed under it. */
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
/** Run `fn` on the live handle; if the channel was closed under us (first call after a resume), reconnect and retry. */
|
|
22
|
+
on<T>(fn: (sb: CoreSandbox) => Promise<T>, what?: "sandbox" | "file" | "other"): Promise<T>;
|
|
23
|
+
isNative(): Promise<boolean>;
|
|
24
|
+
/** The guest's $HOME (E2B's default cwd and relative-path base), created if missing. */
|
|
25
|
+
home(): Promise<string>;
|
|
26
|
+
abs(path: string): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=box.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8C,KAAK,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1G,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAMxC,qHAAqH;AACrH,eAAO,MAAM,mBAAmB,wFAAoF,CAAC;AAErH,sIAAsI;AACtI,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAE9E;AAED,gBAAgB;AAChB,qBAAa,GAAG;IAMZ,QAAQ,CAAC,IAAI,EAAE,IAAI;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM;IANrB,OAAO,CAAC,CAAC,CAAmC;IAC5C,OAAO,CAAC,MAAM,CAA+B;IAC7C,OAAO,CAAC,KAAK,CAA8B;gBAGhC,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,WAAW;IAKvB,OAAO,CAAC,MAAM;IAWd,4CAA4C;IAC5C,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC;IAK9B,IAAI,IAAI,IAAI;IAIZ,0GAA0G;IACpG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B,wHAAwH;IAClH,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,SAAS,GAAG,MAAM,GAAG,OAAiB,GAAG,OAAO,CAAC,CAAC,CAAC;IAa1G,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAW5B,wFAAwF;IACxF,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAiBjB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAKzC"}
|
package/dist/box.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Per-sandbox plumbing shared by Sandbox, Commands, Filesystem and Pty: the live control handle (reconnecting after a
|
|
2
|
+
// resume), the guest's $HOME, and the shell wrapper E2B-style `commands.run` needs.
|
|
3
|
+
import { ConnectionError, GatewayError, SolariError } from "@solarisdk/core";
|
|
4
|
+
import { translateError } from "./errors.js";
|
|
5
|
+
const DEFAULT_HOME = "/home/user";
|
|
6
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
/** Native image sandboxes: a bash when the image has one, else sh. The command is "$1", so it is never re-parsed. */
|
|
8
|
+
export const NATIVE_SHELL_SCRIPT = 'if [ -x /bin/bash ]; then exec /bin/bash -c "$1"; else exec /bin/sh -c "$1"; fi';
|
|
9
|
+
/** `[program, args]` for an E2B-style shell string: `bash -lc` normally (E2B runs `/bin/bash -l -c`), native-image safe otherwise. */
|
|
10
|
+
export function shellArgs(native, command) {
|
|
11
|
+
return native ? ["/bin/sh", ["-c", NATIVE_SHELL_SCRIPT, "sh", command]] : ["/bin/bash", ["-lc", command]];
|
|
12
|
+
}
|
|
13
|
+
/** @internal */
|
|
14
|
+
export class Box {
|
|
15
|
+
conn;
|
|
16
|
+
id;
|
|
17
|
+
h;
|
|
18
|
+
native;
|
|
19
|
+
homeP;
|
|
20
|
+
constructor(conn, id, initial) {
|
|
21
|
+
this.conn = conn;
|
|
22
|
+
this.id = id;
|
|
23
|
+
if (initial)
|
|
24
|
+
this.h = this.attach(Promise.resolve(initial));
|
|
25
|
+
}
|
|
26
|
+
attach(p) {
|
|
27
|
+
const h = p.then(async (sb) => {
|
|
28
|
+
await sb.connect();
|
|
29
|
+
return sb;
|
|
30
|
+
});
|
|
31
|
+
h.catch(() => {
|
|
32
|
+
if (this.h === h)
|
|
33
|
+
this.h = undefined;
|
|
34
|
+
});
|
|
35
|
+
return h;
|
|
36
|
+
}
|
|
37
|
+
/** The connected control handle, cached. */
|
|
38
|
+
handle() {
|
|
39
|
+
if (!this.h)
|
|
40
|
+
this.h = this.attach(this.conn.solari.connect(this.id));
|
|
41
|
+
return this.h;
|
|
42
|
+
}
|
|
43
|
+
drop() {
|
|
44
|
+
this.h = undefined;
|
|
45
|
+
}
|
|
46
|
+
/** Close this process's own control channel (if open) before the sandbox is paused or killed under it. */
|
|
47
|
+
async close() {
|
|
48
|
+
const h = this.h;
|
|
49
|
+
this.h = undefined;
|
|
50
|
+
if (h)
|
|
51
|
+
(await h.catch(() => undefined))?.close();
|
|
52
|
+
}
|
|
53
|
+
/** Run `fn` on the live handle; if the channel was closed under us (first call after a resume), reconnect and retry. */
|
|
54
|
+
async on(fn, what = "other") {
|
|
55
|
+
for (let attempt = 0;; attempt++) {
|
|
56
|
+
try {
|
|
57
|
+
return await fn(await this.handle());
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
const closed = e instanceof SolariError && !(e instanceof GatewayError) && (e instanceof ConnectionError || /closed|not connected|disconnect|websocket/i.test(e.message));
|
|
61
|
+
if (!closed || attempt >= 2)
|
|
62
|
+
throw translateError(e, what);
|
|
63
|
+
this.drop();
|
|
64
|
+
await sleep(500 * (attempt + 1));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
isNative() {
|
|
69
|
+
if (!this.native) {
|
|
70
|
+
const p = this.conn.solari.get(this.id).then((v) => Boolean(v.fromImage));
|
|
71
|
+
p.catch(() => {
|
|
72
|
+
this.native = undefined;
|
|
73
|
+
});
|
|
74
|
+
this.native = p;
|
|
75
|
+
}
|
|
76
|
+
return this.native;
|
|
77
|
+
}
|
|
78
|
+
/** The guest's $HOME (E2B's default cwd and relative-path base), created if missing. */
|
|
79
|
+
home() {
|
|
80
|
+
if (!this.homeP) {
|
|
81
|
+
const p = (async () => {
|
|
82
|
+
const [sh, args] = shellArgs(await this.isNative(), 'printf %s "$HOME"');
|
|
83
|
+
const r = await this.on((sb) => sb.commands.run(sh, { args }));
|
|
84
|
+
const home = r.stdout.trim() || DEFAULT_HOME;
|
|
85
|
+
await this.on((sb) => sb.commands.run("/bin/mkdir", { args: ["-p", home] }));
|
|
86
|
+
return home;
|
|
87
|
+
})();
|
|
88
|
+
p.catch(() => {
|
|
89
|
+
this.homeP = undefined;
|
|
90
|
+
});
|
|
91
|
+
this.homeP = p;
|
|
92
|
+
}
|
|
93
|
+
return this.homeP;
|
|
94
|
+
}
|
|
95
|
+
async abs(path) {
|
|
96
|
+
if (path.startsWith("/"))
|
|
97
|
+
return path;
|
|
98
|
+
const home = await this.home();
|
|
99
|
+
return path === "~" ? home : path.startsWith("~/") ? `${home}/${path.slice(2)}` : `${home}/${path}`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=box.js.map
|
package/dist/box.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box.js","sourceRoot":"","sources":["../src/box.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,oFAAoF;AAEpF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAA+B,MAAM,iBAAiB,CAAC;AAE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EAAE,CAAC,CAAC,CAAC;gBAC7E,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,EAAE,CAAC;YACL,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;gBACX,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACzB,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY;QACpB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACtC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;IACtG,CAAC;CACF"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type Chart as CoreChart, type CodeResultItem } from "@solarisdk/core";
|
|
2
|
+
import type { Conn } from "./config.js";
|
|
3
|
+
import { Sandbox as BaseSandbox, type SandboxOpts } from "./sandbox.js";
|
|
4
|
+
export declare enum ChartType {
|
|
5
|
+
LINE = "line",
|
|
6
|
+
SCATTER = "scatter",
|
|
7
|
+
BAR = "bar",
|
|
8
|
+
PIE = "pie",
|
|
9
|
+
BOX_AND_WHISKER = "box_and_whisker",
|
|
10
|
+
SUPERCHART = "superchart",
|
|
11
|
+
UNKNOWN = "unknown"
|
|
12
|
+
}
|
|
13
|
+
export declare enum ScaleType {
|
|
14
|
+
LINEAR = "linear",
|
|
15
|
+
DATETIME = "datetime",
|
|
16
|
+
CATEGORICAL = "categorical",
|
|
17
|
+
LOG = "log",
|
|
18
|
+
SYMLOG = "symlog",
|
|
19
|
+
LOGIT = "logit",
|
|
20
|
+
FUNCTION = "function",
|
|
21
|
+
FUNCTIONLOG = "functionlog",
|
|
22
|
+
ASINH = "asinh"
|
|
23
|
+
}
|
|
24
|
+
export type Chart = {
|
|
25
|
+
type: ChartType;
|
|
26
|
+
title: string;
|
|
27
|
+
elements: any[];
|
|
28
|
+
[k: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
export type ChartTypes = Chart;
|
|
31
|
+
export declare class OutputMessage {
|
|
32
|
+
readonly line: string;
|
|
33
|
+
readonly timestamp: number;
|
|
34
|
+
readonly error: boolean;
|
|
35
|
+
constructor(line: string, timestamp: number, error: boolean);
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
export declare class ExecutionError {
|
|
39
|
+
name: string;
|
|
40
|
+
value: string;
|
|
41
|
+
traceback: string;
|
|
42
|
+
constructor(name: string, value: string, traceback: string);
|
|
43
|
+
}
|
|
44
|
+
export type MIMEType = string;
|
|
45
|
+
export type RawData = {
|
|
46
|
+
[key: MIMEType]: unknown;
|
|
47
|
+
} & {
|
|
48
|
+
data?: Record<string, unknown>;
|
|
49
|
+
chart?: Chart;
|
|
50
|
+
};
|
|
51
|
+
export declare class Result {
|
|
52
|
+
readonly raw: RawData;
|
|
53
|
+
readonly isMainResult: boolean;
|
|
54
|
+
readonly text?: string;
|
|
55
|
+
readonly html?: string;
|
|
56
|
+
readonly markdown?: string;
|
|
57
|
+
readonly svg?: string;
|
|
58
|
+
readonly png?: string;
|
|
59
|
+
readonly jpeg?: string;
|
|
60
|
+
readonly pdf?: string;
|
|
61
|
+
readonly latex?: string;
|
|
62
|
+
readonly json?: string;
|
|
63
|
+
readonly javascript?: string;
|
|
64
|
+
readonly data?: Record<string, unknown>;
|
|
65
|
+
readonly chart?: Chart;
|
|
66
|
+
readonly extra?: any;
|
|
67
|
+
constructor(raw: RawData, isMainResult: boolean);
|
|
68
|
+
formats(): string[];
|
|
69
|
+
toJSON(): {
|
|
70
|
+
text: string | undefined;
|
|
71
|
+
html: string | undefined;
|
|
72
|
+
markdown: string | undefined;
|
|
73
|
+
svg: string | undefined;
|
|
74
|
+
png: string | undefined;
|
|
75
|
+
jpeg: string | undefined;
|
|
76
|
+
pdf: string | undefined;
|
|
77
|
+
latex: string | undefined;
|
|
78
|
+
json: string | undefined;
|
|
79
|
+
javascript: string | undefined;
|
|
80
|
+
extra?: any;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export type Logs = {
|
|
84
|
+
stdout: string[];
|
|
85
|
+
stderr: string[];
|
|
86
|
+
};
|
|
87
|
+
export declare class Execution {
|
|
88
|
+
results: Result[];
|
|
89
|
+
logs: Logs;
|
|
90
|
+
error?: ExecutionError | undefined;
|
|
91
|
+
executionCount?: number | undefined;
|
|
92
|
+
constructor(results?: Result[], logs?: Logs, error?: ExecutionError | undefined, executionCount?: number | undefined);
|
|
93
|
+
get text(): string | undefined;
|
|
94
|
+
toJSON(): {
|
|
95
|
+
results: Result[];
|
|
96
|
+
logs: Logs;
|
|
97
|
+
error: ExecutionError | undefined;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export type Context = {
|
|
101
|
+
id: string;
|
|
102
|
+
language: string;
|
|
103
|
+
cwd: string;
|
|
104
|
+
};
|
|
105
|
+
export type RunCodeLanguage = "python" | "javascript" | "typescript" | "r" | "java" | "bash" | (string & {});
|
|
106
|
+
export interface RunCodeOpts {
|
|
107
|
+
onStdout?: (output: OutputMessage) => Promise<any> | any;
|
|
108
|
+
onStderr?: (output: OutputMessage) => Promise<any> | any;
|
|
109
|
+
onResult?: (data: Result) => Promise<any> | any;
|
|
110
|
+
onError?: (error: ExecutionError) => Promise<any> | any;
|
|
111
|
+
envs?: Record<string, string>;
|
|
112
|
+
timeoutMs?: number;
|
|
113
|
+
requestTimeoutMs?: number;
|
|
114
|
+
}
|
|
115
|
+
export interface CreateCodeContextOpts {
|
|
116
|
+
cwd?: string;
|
|
117
|
+
language?: RunCodeLanguage;
|
|
118
|
+
requestTimeoutMs?: number;
|
|
119
|
+
}
|
|
120
|
+
declare function mapChart(c: CoreChart): Chart;
|
|
121
|
+
declare function toResult(item: CodeResultItem, isMain: boolean): Result;
|
|
122
|
+
declare function toExecutionError(err: unknown): ExecutionError;
|
|
123
|
+
export declare const CODE_INTERPRETER_TEMPLATE = "code-interpreter-v1";
|
|
124
|
+
/** The data-analysis stack of E2B's default code-interpreter image, minus the very large audio/NLP/vision wheels. */
|
|
125
|
+
export declare const CODE_INTERPRETER_PACKAGES: string[];
|
|
126
|
+
/** Build `code-interpreter-v1` into your org (several minutes, once). `Sandbox.create()` calls this when it is missing. */
|
|
127
|
+
export declare function buildCodeInterpreterTemplate(opts?: import("./config.js").ConnectionOpts & {
|
|
128
|
+
onLog?: (line: string) => void;
|
|
129
|
+
}): Promise<string>;
|
|
130
|
+
export declare class Sandbox extends BaseSandbox {
|
|
131
|
+
protected static readonly defaultTemplate: string;
|
|
132
|
+
protected static resolveTemplate(conn: Conn, template: string): Promise<string>;
|
|
133
|
+
runCode(code: string, opts?: RunCodeOpts & {
|
|
134
|
+
language?: RunCodeLanguage;
|
|
135
|
+
}): Promise<Execution>;
|
|
136
|
+
runCode(code: string, opts?: RunCodeOpts & {
|
|
137
|
+
context?: Context;
|
|
138
|
+
}): Promise<Execution>;
|
|
139
|
+
private runPython;
|
|
140
|
+
private runBash;
|
|
141
|
+
createCodeContext(opts?: CreateCodeContextOpts): Promise<Context>;
|
|
142
|
+
/** Contexts created through this process (Solari cannot list a sandbox's kernels). */
|
|
143
|
+
listCodeContexts(): Promise<Context[]>;
|
|
144
|
+
/** Forgets the context. The kernel stays alive until the sandbox ends (Solari has no kernel destroy call). */
|
|
145
|
+
removeCodeContext(context: Context | string): Promise<void>;
|
|
146
|
+
/** Clears the context's variables and working directory (the kernel process is not restarted). */
|
|
147
|
+
restartCodeContext(context: Context | string): Promise<void>;
|
|
148
|
+
}
|
|
149
|
+
export type { SandboxOpts };
|
|
150
|
+
export default Sandbox;
|
|
151
|
+
/** @internal Exposed for unit tests. */
|
|
152
|
+
export declare const _internal: {
|
|
153
|
+
toResult: typeof toResult;
|
|
154
|
+
toExecutionError: typeof toExecutionError;
|
|
155
|
+
mapChart: typeof mapChart;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=code-interpreter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-interpreter.d.ts","sourceRoot":"","sources":["../src/code-interpreter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyB,KAAK,KAAK,IAAI,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAKxE,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,eAAe,oBAAoB;IACnC,UAAU,eAAe;IACzB,OAAO,YAAY;CACpB;AACD,oBAAY,SAAS;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;CAChB;AACD,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,GAAG,EAAE,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAC9F,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC;AAE/B,qBAAa,aAAa;IAEtB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,SA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