@jini-ai/sandbox 0.4.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/CHANGELOG.md +16 -0
- package/LICENSE +201 -0
- package/README.md +209 -0
- package/dist/cjs/core/errors.d.ts +56 -0
- package/dist/cjs/core/errors.js +40 -0
- package/dist/cjs/core/index.d.ts +20 -0
- package/dist/cjs/core/index.js +22 -0
- package/dist/cjs/core/ports.d.ts +232 -0
- package/dist/cjs/core/ports.js +55 -0
- package/dist/cjs/e2b/categorize-e2b-error.d.ts +21 -0
- package/dist/cjs/e2b/categorize-e2b-error.js +27 -0
- package/dist/cjs/e2b/default-vite-react-template.d.ts +26 -0
- package/dist/cjs/e2b/default-vite-react-template.js +122 -0
- package/dist/cjs/e2b/e2b-sandbox-handle.d.ts +131 -0
- package/dist/cjs/e2b/e2b-sandbox-handle.js +28 -0
- package/dist/cjs/e2b/index.d.ts +18 -0
- package/dist/cjs/e2b/index.js +25 -0
- package/dist/cjs/e2b/provider.d.ts +63 -0
- package/dist/cjs/e2b/provider.js +92 -0
- package/dist/cjs/e2b/shell-quote.d.ts +21 -0
- package/dist/cjs/e2b/shell-quote.js +24 -0
- package/dist/cjs/e2b/to-array-buffer.d.ts +18 -0
- package/dist/cjs/e2b/to-array-buffer.js +21 -0
- package/dist/cjs/e2b/wrap-e2b-sandbox.d.ts +31 -0
- package/dist/cjs/e2b/wrap-e2b-sandbox.js +347 -0
- package/dist/cjs/node-worker.d.ts +111 -0
- package/dist/cjs/node-worker.js +157 -0
- package/dist/cjs/package.json +1 -0
- package/dist/core/errors.d.ts +56 -0
- package/dist/core/errors.js +36 -0
- package/dist/core/index.d.ts +20 -0
- package/dist/core/index.js +18 -0
- package/dist/core/ports.d.ts +232 -0
- package/dist/core/ports.js +54 -0
- package/dist/e2b/categorize-e2b-error.d.ts +21 -0
- package/dist/e2b/categorize-e2b-error.js +24 -0
- package/dist/e2b/default-vite-react-template.d.ts +26 -0
- package/dist/e2b/default-vite-react-template.js +119 -0
- package/dist/e2b/e2b-sandbox-handle.d.ts +131 -0
- package/dist/e2b/e2b-sandbox-handle.js +27 -0
- package/dist/e2b/index.d.ts +18 -0
- package/dist/e2b/index.js +15 -0
- package/dist/e2b/provider.d.ts +63 -0
- package/dist/e2b/provider.js +88 -0
- package/dist/e2b/shell-quote.d.ts +21 -0
- package/dist/e2b/shell-quote.js +21 -0
- package/dist/e2b/to-array-buffer.d.ts +18 -0
- package/dist/e2b/to-array-buffer.js +18 -0
- package/dist/e2b/wrap-e2b-sandbox.d.ts +31 -0
- package/dist/e2b/wrap-e2b-sandbox.js +343 -0
- package/dist/node-worker.d.ts +111 -0
- package/dist/node-worker.js +150 -0
- package/package.json +106 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @jini-ai/sandbox
|
|
2
|
+
|
|
3
|
+
## 0.4.0 — 2026-10-02
|
|
4
|
+
|
|
5
|
+
### BREAKING
|
|
6
|
+
|
|
7
|
+
- Published sandbox helpers use required/optional argument objects and injected host policies; process migration documents are archived.
|
|
8
|
+
- Distribution includes runtime output, release documentation and required assets only. Process records and per-job neutrality checks are no longer part of the package surface.
|
|
9
|
+
|
|
10
|
+
## Unreleased
|
|
11
|
+
|
|
12
|
+
- Fix E2B command adapter overload compatibility by declaring the implementation's port result union; runtime behavior and overload contracts are unchanged.
|
|
13
|
+
- **BREAKING:** Error constructors, E2B helpers, sandbox sessions/providers and worker event ports now take required and optional argument objects. E2B output callbacks receive `{ data }`; Node and SDK arguments are translated inside adapters. See `API.md` for migration.
|
|
14
|
+
- Declare the universal core and Node adapter runtimes, preserving core isolation from optional SDKs.
|
|
15
|
+
|
|
16
|
+
- Add a generic node-worker harness with caller-owned entries, payload/result codecs, schedulers and resource budgets.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Open Design contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# `@jini-ai/sandbox`
|
|
2
|
+
|
|
3
|
+
The execution/sandbox sibling to [`@jini-ai/vibecoding`](../vibecoding/README.md)'s edit loop —
|
|
4
|
+
boot an environment, mount files, install dependencies, run commands, preview, and tear down,
|
|
5
|
+
behind one backend-neutral interface.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import type { SandboxProviderPort, SandboxSession } from '@jini-ai/sandbox/core';
|
|
9
|
+
import { createE2bSandboxProvider } from '@jini-ai/sandbox/e2b';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## The split from vibecoding
|
|
13
|
+
|
|
14
|
+
`@jini-ai/vibecoding`'s `EditTarget` interface deliberately has no verbs for running processes,
|
|
15
|
+
installing dependencies, or building — that is a decision documented in its own README, not a
|
|
16
|
+
gap. A host composes the two side by side: vibecoding owns the conversational edit loop over an
|
|
17
|
+
addressable artifact; this package owns making that artifact actually run somewhere and produce
|
|
18
|
+
a preview. Neither package imports the other.
|
|
19
|
+
|
|
20
|
+
## Why three adapters, and why only one exists yet
|
|
21
|
+
|
|
22
|
+
A host application that ships as both a web app and a desktop app needs "run this project and
|
|
23
|
+
preview it" to not assume a remote VM — it needs a shape that admits at least three real
|
|
24
|
+
implementations, with the same project producing identical observable results on any of them
|
|
25
|
+
(same files in, same build/preview behavior out):
|
|
26
|
+
|
|
27
|
+
| adapter | where it runs | status |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `./e2b` | a remote Firecracker microVM (E2B) | **built** — this package's Slice 1 |
|
|
30
|
+
| `./local` | spawned directly on the user's own machine (desktop) | not built — confirmed shipping target |
|
|
31
|
+
| `./webcontainer` | in the browser tab (StackBlitz WebContainers) | not built — blocked on WebContainers' commercial licensing for production use |
|
|
32
|
+
|
|
33
|
+
`./e2b` and `./local` are both confirmed shipping targets, not "one plus a maybe" — a project
|
|
34
|
+
started on desktop must be continuable in a browser and vice versa. E2B was chosen to build
|
|
35
|
+
first because it is genuinely open source and self-hostable — see the design docs this package
|
|
36
|
+
was built from for the full comparison. A remote server-side backend other than E2B (Modal, most
|
|
37
|
+
plausibly) may join `./e2b` later; nothing in `./core` leans on anything E2B-specific — see the
|
|
38
|
+
error-category and content-type sections below for what was checked against that.
|
|
39
|
+
|
|
40
|
+
`./core`'s job is to describe the shape all three (or four) can implement, so that building
|
|
41
|
+
`./local` or `./webcontainer` later is an adapter, not a redesign. Concretely, nothing in
|
|
42
|
+
`./core` may assume:
|
|
43
|
+
|
|
44
|
+
- the sandbox is remote,
|
|
45
|
+
- a preview is a public URL rather than `http://localhost:<port>`,
|
|
46
|
+
- `boot` is slow,
|
|
47
|
+
- file content is always UTF-8 text, or
|
|
48
|
+
- the project root starts out empty.
|
|
49
|
+
|
|
50
|
+
That last one is a real, named asymmetry, not a hidden gap — see below.
|
|
51
|
+
|
|
52
|
+
## The interface
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
interface SandboxProviderPort {
|
|
56
|
+
boot(requiredArgs: Record<string, never>, optionalArgs?: BootOptions): Promise<SandboxSession>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface SandboxSession {
|
|
60
|
+
mountFiles(requiredArgs: { files: readonly SandboxFile[] }): Promise<void>;
|
|
61
|
+
readFile(requiredArgs: { path: string }): Promise<Uint8Array>;
|
|
62
|
+
listFiles(requiredArgs: Record<string, never>, optionalArgs?: { directory?: string }): Promise<readonly string[]>;
|
|
63
|
+
runCommand(requiredArgs: { command: string }, optionalArgs?: RunCommandOptions & { args?: readonly string[] }): Promise<CommandResult>;
|
|
64
|
+
installDependencies(requiredArgs: Record<string, never>, optionalArgs?: RunCommandOptions & { packages?: readonly string[] }): Promise<CommandResult>;
|
|
65
|
+
startProcess(requiredArgs: { command: string }, optionalArgs?: { args?: readonly string[] }): Promise<ProcessHandle>;
|
|
66
|
+
getPreview(): Promise<PreviewTarget>;
|
|
67
|
+
onFileChange(requiredArgs: { listener: (event: FileChangeEvent) => void }): Unsubscribe;
|
|
68
|
+
teardown(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
See `src/core/ports.ts` for the full type definitions and their reasoning — every export there
|
|
73
|
+
carries a doc comment explaining what it's for and, where relevant, what alternative was
|
|
74
|
+
considered and rejected. The headline decisions:
|
|
75
|
+
|
|
76
|
+
**`runCommand`/`installDependencies` can stream, and still resolve with the final result.**
|
|
77
|
+
`RunCommandOptions.onOutput` is called with each output chunk as it's produced; the command still
|
|
78
|
+
resolves with the complete `CommandResult` once it exits. This exists specifically for `npm
|
|
79
|
+
install`'s output scrolling live in a terminal panel — it's a command that exits on its own, so
|
|
80
|
+
it goes through `installDependencies`, not `startProcess`, and without this option that output
|
|
81
|
+
would be invisible until the whole install finished and then arrive as one frozen wall of text.
|
|
82
|
+
|
|
83
|
+
**`startProcess`/`ProcessHandle` is the separate verb for a command that never exits.** A dev
|
|
84
|
+
server is by definition a process `runCommand`'s "wait for it to finish" contract cannot
|
|
85
|
+
represent, and `getPreview` is only meaningful once one is listening. All three intended backends
|
|
86
|
+
have a native shape for a background process (E2B's `commands.run(cmd, { background: true })`, a
|
|
87
|
+
detached `child_process.spawn`, a non-blocking WebContainer `process.spawn`), which is what makes
|
|
88
|
+
it belong in `./core` rather than being `./e2b`-specific.
|
|
89
|
+
|
|
90
|
+
**`SandboxFile.content` is `string | Uint8Array`, and `readFile` always returns raw bytes.**
|
|
91
|
+
A theme's assets (`.png`, `.woff2`, `.mp4`, under `assets/images|fonts|video|audio`) cannot
|
|
92
|
+
round-trip through a UTF-8 string — mounting one as text would silently corrupt it, which is the
|
|
93
|
+
dangerous part, since it would look like it worked. `readFile` never guesses whether a path is
|
|
94
|
+
text or binary; a caller that knows decodes it itself.
|
|
95
|
+
|
|
96
|
+
**`mountFiles` is upsert-only on every adapter — never delete-by-omission.** Not an
|
|
97
|
+
E2B-shaped simplification: on `./local`, `mountFiles` operates on the user's real project
|
|
98
|
+
directory, so "replace the tree" would mean deleting files the session was never given
|
|
99
|
+
permission to touch (a `.git/` folder, anything edited outside the sandbox). Both backends
|
|
100
|
+
independently want identical behavior here, so there's no seam to name — explicit file deletion
|
|
101
|
+
is out of scope for this package's first slice.
|
|
102
|
+
|
|
103
|
+
**`teardown` has two hard guarantees, stated as contract:** every process started via
|
|
104
|
+
`startProcess` is killed (an orphaned dev server on `./local` would hold a port on the user's
|
|
105
|
+
machine forever), and the project root's files are never deleted (moot on a disposable remote
|
|
106
|
+
VM; a hard requirement on `./local`, where the project root IS the user's real directory).
|
|
107
|
+
|
|
108
|
+
**The one asymmetry that could not be unified, named rather than papered over:** `./local`'s
|
|
109
|
+
project root is the user's real directory and may already contain files this package never
|
|
110
|
+
mounted; `./e2b`'s (and any other remote adapter's) project root starts empty except for what
|
|
111
|
+
gets mounted into it. Code built against this interface has to tolerate a project root that
|
|
112
|
+
already has things in it.
|
|
113
|
+
|
|
114
|
+
## Errors
|
|
115
|
+
|
|
116
|
+
Every `SandboxSession`/`SandboxProviderPort` method rejects with `SandboxOperationError` — a real
|
|
117
|
+
class (`src/core/errors.ts`, not `ports.ts`, so `ports.ts` stays truthfully zero-runtime; see its
|
|
118
|
+
own doc comment for why) carrying one of six backend-neutral categories: `unavailable`,
|
|
119
|
+
`permission-denied`, `port-in-use`, `not-found`, `timeout`, `unknown`. A caller branches on
|
|
120
|
+
`category`, never on which adapter it's talking to — "network down" (E2B) and "node isn't
|
|
121
|
+
installed" (local) are different causes for the same `'unavailable'` category. The standard
|
|
122
|
+
`Error` `cause` field is the escape hatch for the backend's own detail.
|
|
123
|
+
|
|
124
|
+
Named `SandboxOperationError` rather than `SandboxError` because `@e2b/code-interpreter`'s own
|
|
125
|
+
base SDK (`e2b`) already exports a class literally called `SandboxError` — importing both into
|
|
126
|
+
the same adapter file under the obvious names would collide.
|
|
127
|
+
|
|
128
|
+
## What got deliberately left out of `./core`, and why
|
|
129
|
+
|
|
130
|
+
Ported from open-lovable's `SandboxProvider`/`E2BProvider`, but NOT carried into the
|
|
131
|
+
backend-neutral interface:
|
|
132
|
+
|
|
133
|
+
- **Session reconnection by ID.** E2B's real SDK supports `Sandbox.connect(sandboxId)` (open-
|
|
134
|
+
lovable's own `reconnect()` stub predates that and just returns `false` — verified against the
|
|
135
|
+
installed `e2b` package's types, not assumed from the older code). It still doesn't belong in
|
|
136
|
+
`./core`: a local desktop process isn't "reconnectable" the same way after the host restarts,
|
|
137
|
+
and a WebContainer instance dies with the browser tab. This is an E2B-adapter-only concern if
|
|
138
|
+
it's ever needed, not a port verb.
|
|
139
|
+
- **Framework-specific scaffolding verbs.** open-lovable's abstract `SandboxProvider` bakes
|
|
140
|
+
`setupViteApp()`/`restartViteServer()` directly into the interface, assuming every project is a
|
|
141
|
+
Vite app. `./core` knows nothing about Vite, React, or any framework. Scaffolding a starter
|
|
142
|
+
template is the host's job — call `mountFiles` with template files, then `startProcess` with
|
|
143
|
+
whatever dev command applies. `./e2b`'s `DEFAULT_VITE_REACT_TEMPLATE` is offered as a
|
|
144
|
+
convenience for hosts that want one, not as part of the required adapter surface.
|
|
145
|
+
- **A session registry keyed by sandbox ID.** open-lovable's `SandboxManager` singleton exists
|
|
146
|
+
because each Next.js API route is a fresh serverless invocation with no memory between
|
|
147
|
+
requests. Jini's daemon is long-running, so a `SandboxSession` return value is already a live
|
|
148
|
+
handle a host can hold onto — no registry concept is needed in `./core`.
|
|
149
|
+
|
|
150
|
+
## `./e2b`
|
|
151
|
+
|
|
152
|
+
`createE2bSandboxProvider({}, config?)` implements `SandboxProviderPort` against a real E2B
|
|
153
|
+
Firecracker microVM. `@e2b/code-interpreter` is an **optional peer dependency** — installing
|
|
154
|
+
`@jini-ai/sandbox` alone pulls no E2B SDK code, and `pnpm guard`'s R12 check (opted in via
|
|
155
|
+
`jini.neutralEntries` in `package.json`, the same mechanism `@jini-ai/infra` uses for its
|
|
156
|
+
database drivers) fails the build if anything under `./core` ever imports it.
|
|
157
|
+
|
|
158
|
+
Structurally:
|
|
159
|
+
|
|
160
|
+
- `e2b-sandbox-handle.ts` — the narrow slice of `@e2b/code-interpreter`'s `Sandbox` this adapter
|
|
161
|
+
actually calls, written as its own interface. This is what makes the wrapping logic testable
|
|
162
|
+
against a plain object literal instead of a real, network-backed sandbox.
|
|
163
|
+
- `wrap-e2b-sandbox.ts` — all of the E2B-specific translation: shell command building (every
|
|
164
|
+
argument is shell-quoted, not just ones that look risky), binary-content conversion, the
|
|
165
|
+
`FilesystemEventType` → `FileChangeKind` mapping (`chmod` is dropped — a permissions change
|
|
166
|
+
isn't a content change; `rename` maps to `modified` rather than a guessed create/delete, since
|
|
167
|
+
E2B's event carries only one path, not an old/new pair), `getPreview`'s liveness check, and
|
|
168
|
+
process tracking so `teardown` can kill everything `startProcess` started.
|
|
169
|
+
- `categorize-e2b-error.ts` — maps E2B SDK error *names* (not imported classes — see the file's
|
|
170
|
+
own doc) onto `SandboxErrorCategory`.
|
|
171
|
+
- `to-array-buffer.ts` — converts a `Uint8Array` to the `ArrayBuffer` E2B's `files.write` accepts,
|
|
172
|
+
correctly handling a view with a non-zero `byteOffset` over a larger shared buffer.
|
|
173
|
+
- `provider.ts` — the one file that imports `@e2b/code-interpreter` itself, calls
|
|
174
|
+
`Sandbox.create()`, and adapts the result into `E2bSandboxHandle` via `toE2bHandle`. That
|
|
175
|
+
adaptation is an explicit wrapper function, not a direct structural pass-through of the real
|
|
176
|
+
`Sandbox` object, because TypeScript's assignability check between E2B's overloaded `write`
|
|
177
|
+
(single-file and batch forms) and this interface's batch-only signature doesn't reliably
|
|
178
|
+
resolve to the matching overload — a real, reproduced compile error, not a theoretical concern.
|
|
179
|
+
- `default-vite-react-template.ts` — the same starter files open-lovable's `setupViteApp`
|
|
180
|
+
produces, as plain `SandboxFile[]` data. The real `files.write` API this adapter uses takes a
|
|
181
|
+
string directly and creates intermediate directories on its own, so no Python-heredoc script
|
|
182
|
+
is needed to place them the way open-lovable's version required.
|
|
183
|
+
|
|
184
|
+
**`getPreview` does one bounded-timeout check, not a retry loop.** open-lovable's E2B path starts
|
|
185
|
+
Vite and then sleeps a fixed delay before assuming it's ready. This adapter instead does a single
|
|
186
|
+
`HEAD` request against the forwarded host with a timeout, and rejects (category `'timeout'`) if
|
|
187
|
+
nothing answers. A caller that wants to poll does so by calling `getPreview()` again — the retry
|
|
188
|
+
policy is the caller's to choose, not baked into the adapter.
|
|
189
|
+
|
|
190
|
+
**`mountFiles` writes every file in one batched call**, using E2B's multi-file `write` overload —
|
|
191
|
+
one network round trip regardless of how many files are given, not one per file.
|
|
192
|
+
|
|
193
|
+
**One assumption flagged for verification, not confirmed against a live sandbox:** `listFiles`
|
|
194
|
+
assumes `files.list`'s `EntryInfo.path` is absolute, inferred from its type-level doc plus this
|
|
195
|
+
adapter always calling `write`/`list` with absolute paths — no E2B credentials were available
|
|
196
|
+
while building this. `relativeToRoot` in `wrap-e2b-sandbox.ts` is the one place to change if a
|
|
197
|
+
real sandbox's `list()` turns out to echo paths differently.
|
|
198
|
+
|
|
199
|
+
Every other claim in this file about E2B's real API shape (`commands.run`'s
|
|
200
|
+
`background`/`onStdout`/`onStderr` options working on foreground calls too, `files.write`
|
|
201
|
+
auto-creating parent directories, `files.read`'s `format: 'bytes'` returning `Uint8Array`
|
|
202
|
+
natively, `files.watchDir`'s event types being lowercase, `Sandbox.kill()` returning a
|
|
203
|
+
`boolean`) was checked against the installed `@e2b/code-interpreter`/`e2b` package's own `.d.ts`,
|
|
204
|
+
not inferred from open-lovable's source or paraphrased docs — several of those checks caught
|
|
205
|
+
real mistakes in earlier drafts before they shipped.
|
|
206
|
+
|
|
207
|
+
## Worker execution
|
|
208
|
+
|
|
209
|
+
`./node-worker` provides bounded per-call workers with explicit entry paths, payload/result codecs, clocks and resource budgets. See [API.md](https://github.com/AINSEP/Jini/blob/main/packages/sandbox/API.md) for composition and migration. `./core` remains universal and imports no adapter; `./e2b` and `./node-worker` use Node.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The one error type every `SandboxSession`/`SandboxProviderPort` method rejects with.
|
|
3
|
+
*
|
|
4
|
+
* Purpose:
|
|
5
|
+
* Separated from `ports.ts` on purpose — everything in `ports.ts` is an `interface`/`type` that
|
|
6
|
+
* erases at compile time, and a category a caller can branch on has to exist somewhere at
|
|
7
|
+
* runtime, not just in a type annotation. Keeping the one real class in its own file lets
|
|
8
|
+
* `ports.ts` keep its zero-runtime-statement property (and the literal truth of its own header
|
|
9
|
+
* comment) rather than being "mostly types, plus one class" and quietly stopping being either.
|
|
10
|
+
*
|
|
11
|
+
* Architectural role:
|
|
12
|
+
* Still `./core` — re-exported alongside everything in `ports.ts` from `index.ts`, so nothing
|
|
13
|
+
* changes for a consumer importing `@jini-ai/sandbox/core`. `pnpm guard`'s R12 check scopes to
|
|
14
|
+
* `src/core` as a whole (see `jini.neutralEntries` in `package.json`), not to `ports.ts`
|
|
15
|
+
* specifically, so this file inherits the same "no adapter import, ever" enforcement.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Backend-neutral reasons a sandbox operation can fail. A caller handles one of these six
|
|
19
|
+
* categories, never a backend name — "network down" (E2B) and "node isn't installed" (local) are
|
|
20
|
+
* different causes for the same category, `'unavailable'`, and neither should force a caller to
|
|
21
|
+
* branch on which adapter it's talking to.
|
|
22
|
+
*/
|
|
23
|
+
export type SandboxErrorCategory =
|
|
24
|
+
/** The backend itself could not be reached or started: network failure, quota exceeded, a
|
|
25
|
+
* required local runtime/binary missing. */
|
|
26
|
+
'unavailable'
|
|
27
|
+
/** The operation was refused for lack of rights: an invalid/rejected API key or access token,
|
|
28
|
+
* no filesystem write permission. */
|
|
29
|
+
| 'permission-denied'
|
|
30
|
+
/** The requested port was already bound. */
|
|
31
|
+
| 'port-in-use'
|
|
32
|
+
/** The requested resource doesn't exist — a file path, a session that's already torn down. */
|
|
33
|
+
| 'not-found'
|
|
34
|
+
/** The operation didn't complete within its bound. */
|
|
35
|
+
| 'timeout'
|
|
36
|
+
/** Any other backend-specific failure. `cause` carries the detail. */
|
|
37
|
+
| 'unknown';
|
|
38
|
+
/**
|
|
39
|
+
* The one error type every `SandboxSession`/`SandboxProviderPort` method rejects with. Named
|
|
40
|
+
* `SandboxOperationError` rather than `SandboxError` because `@e2b/code-interpreter`'s own base
|
|
41
|
+
* SDK (`e2b`) already exports a class literally called `SandboxError` — importing both into the
|
|
42
|
+
* same adapter file under the obvious names would collide.
|
|
43
|
+
*
|
|
44
|
+
* `cause` (the standard `Error` field, via `ErrorOptions`) is the escape hatch for the backend's
|
|
45
|
+
* own detail — the original E2B SDK error, the Node `ENOENT`, whatever a specific adapter caught.
|
|
46
|
+
* `category` is what a caller is expected to actually branch on; `cause` is for logging and
|
|
47
|
+
* debugging, not for a caller to inspect to figure out what really happened per backend.
|
|
48
|
+
*/
|
|
49
|
+
export declare class SandboxOperationError extends Error {
|
|
50
|
+
readonly category: SandboxErrorCategory;
|
|
51
|
+
constructor({ category, message }: {
|
|
52
|
+
category: SandboxErrorCategory;
|
|
53
|
+
message: string;
|
|
54
|
+
}, options?: ErrorOptions);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file The one error type every `SandboxSession`/`SandboxProviderPort` method rejects with.
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Separated from `ports.ts` on purpose — everything in `ports.ts` is an `interface`/`type` that
|
|
7
|
+
* erases at compile time, and a category a caller can branch on has to exist somewhere at
|
|
8
|
+
* runtime, not just in a type annotation. Keeping the one real class in its own file lets
|
|
9
|
+
* `ports.ts` keep its zero-runtime-statement property (and the literal truth of its own header
|
|
10
|
+
* comment) rather than being "mostly types, plus one class" and quietly stopping being either.
|
|
11
|
+
*
|
|
12
|
+
* Architectural role:
|
|
13
|
+
* Still `./core` — re-exported alongside everything in `ports.ts` from `index.ts`, so nothing
|
|
14
|
+
* changes for a consumer importing `@jini-ai/sandbox/core`. `pnpm guard`'s R12 check scopes to
|
|
15
|
+
* `src/core` as a whole (see `jini.neutralEntries` in `package.json`), not to `ports.ts`
|
|
16
|
+
* specifically, so this file inherits the same "no adapter import, ever" enforcement.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.SandboxOperationError = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* The one error type every `SandboxSession`/`SandboxProviderPort` method rejects with. Named
|
|
22
|
+
* `SandboxOperationError` rather than `SandboxError` because `@e2b/code-interpreter`'s own base
|
|
23
|
+
* SDK (`e2b`) already exports a class literally called `SandboxError` — importing both into the
|
|
24
|
+
* same adapter file under the obvious names would collide.
|
|
25
|
+
*
|
|
26
|
+
* `cause` (the standard `Error` field, via `ErrorOptions`) is the escape hatch for the backend's
|
|
27
|
+
* own detail — the original E2B SDK error, the Node `ENOENT`, whatever a specific adapter caught.
|
|
28
|
+
* `category` is what a caller is expected to actually branch on; `cause` is for logging and
|
|
29
|
+
* debugging, not for a caller to inspect to figure out what really happened per backend.
|
|
30
|
+
*/
|
|
31
|
+
class SandboxOperationError extends Error {
|
|
32
|
+
category;
|
|
33
|
+
constructor({ category, message }, options) {
|
|
34
|
+
super(message, options);
|
|
35
|
+
this.name = 'SandboxOperationError';
|
|
36
|
+
this.category = category;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.SandboxOperationError = SandboxOperationError;
|
|
40
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @jini-ai/sandbox/core
|
|
3
|
+
*
|
|
4
|
+
* The backend-neutral execution surface: the port every sandbox adapter implements, plus the
|
|
5
|
+
* types that cross it. Importing this entry point loads no adapter — `pnpm guard`'s R12 check
|
|
6
|
+
* enforces that against every optional peer this package declares.
|
|
7
|
+
*
|
|
8
|
+
* Note there is no `.` export on this package. A root barrel that re-exported both this module
|
|
9
|
+
* and an adapter would make every consumer load that adapter regardless of which subpath they
|
|
10
|
+
* asked for, because Node does not tree-shake: whatever the static import graph reaches gets
|
|
11
|
+
* executed. Omitting `.` is the enforcement mechanism, not a stylistic choice.
|
|
12
|
+
*
|
|
13
|
+
* `SandboxOperationError` is a real runtime export (a class, defined in `errors.ts`), not a
|
|
14
|
+
* type — everything else here erases at compile time. See its doc comment for why a ports
|
|
15
|
+
* module needs one, and why it lives in its own file rather than in `ports.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export { SandboxOperationError } from './errors.js';
|
|
18
|
+
export type { SandboxErrorCategory } from './errors.js';
|
|
19
|
+
export type { BootOptions, CommandResult, FileChangeEvent, FileChangeKind, PreviewTarget, ProcessHandle, ProcessOutputChunk, RunCommandOptions, SandboxFile, SandboxProviderPort, SandboxSession, Unsubscribe, } from './ports.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxOperationError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module @jini-ai/sandbox/core
|
|
6
|
+
*
|
|
7
|
+
* The backend-neutral execution surface: the port every sandbox adapter implements, plus the
|
|
8
|
+
* types that cross it. Importing this entry point loads no adapter — `pnpm guard`'s R12 check
|
|
9
|
+
* enforces that against every optional peer this package declares.
|
|
10
|
+
*
|
|
11
|
+
* Note there is no `.` export on this package. A root barrel that re-exported both this module
|
|
12
|
+
* and an adapter would make every consumer load that adapter regardless of which subpath they
|
|
13
|
+
* asked for, because Node does not tree-shake: whatever the static import graph reaches gets
|
|
14
|
+
* executed. Omitting `.` is the enforcement mechanism, not a stylistic choice.
|
|
15
|
+
*
|
|
16
|
+
* `SandboxOperationError` is a real runtime export (a class, defined in `errors.ts`), not a
|
|
17
|
+
* type — everything else here erases at compile time. See its doc comment for why a ports
|
|
18
|
+
* module needs one, and why it lives in its own file rather than in `ports.ts`.
|
|
19
|
+
*/
|
|
20
|
+
var errors_js_1 = require("./errors.js");
|
|
21
|
+
Object.defineProperty(exports, "SandboxOperationError", { enumerable: true, get: function () { return errors_js_1.SandboxOperationError; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|