@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +201 -0
  3. package/README.md +209 -0
  4. package/dist/cjs/core/errors.d.ts +56 -0
  5. package/dist/cjs/core/errors.js +40 -0
  6. package/dist/cjs/core/index.d.ts +20 -0
  7. package/dist/cjs/core/index.js +22 -0
  8. package/dist/cjs/core/ports.d.ts +232 -0
  9. package/dist/cjs/core/ports.js +55 -0
  10. package/dist/cjs/e2b/categorize-e2b-error.d.ts +21 -0
  11. package/dist/cjs/e2b/categorize-e2b-error.js +27 -0
  12. package/dist/cjs/e2b/default-vite-react-template.d.ts +26 -0
  13. package/dist/cjs/e2b/default-vite-react-template.js +122 -0
  14. package/dist/cjs/e2b/e2b-sandbox-handle.d.ts +131 -0
  15. package/dist/cjs/e2b/e2b-sandbox-handle.js +28 -0
  16. package/dist/cjs/e2b/index.d.ts +18 -0
  17. package/dist/cjs/e2b/index.js +25 -0
  18. package/dist/cjs/e2b/provider.d.ts +63 -0
  19. package/dist/cjs/e2b/provider.js +92 -0
  20. package/dist/cjs/e2b/shell-quote.d.ts +21 -0
  21. package/dist/cjs/e2b/shell-quote.js +24 -0
  22. package/dist/cjs/e2b/to-array-buffer.d.ts +18 -0
  23. package/dist/cjs/e2b/to-array-buffer.js +21 -0
  24. package/dist/cjs/e2b/wrap-e2b-sandbox.d.ts +31 -0
  25. package/dist/cjs/e2b/wrap-e2b-sandbox.js +347 -0
  26. package/dist/cjs/node-worker.d.ts +111 -0
  27. package/dist/cjs/node-worker.js +157 -0
  28. package/dist/cjs/package.json +1 -0
  29. package/dist/core/errors.d.ts +56 -0
  30. package/dist/core/errors.js +36 -0
  31. package/dist/core/index.d.ts +20 -0
  32. package/dist/core/index.js +18 -0
  33. package/dist/core/ports.d.ts +232 -0
  34. package/dist/core/ports.js +54 -0
  35. package/dist/e2b/categorize-e2b-error.d.ts +21 -0
  36. package/dist/e2b/categorize-e2b-error.js +24 -0
  37. package/dist/e2b/default-vite-react-template.d.ts +26 -0
  38. package/dist/e2b/default-vite-react-template.js +119 -0
  39. package/dist/e2b/e2b-sandbox-handle.d.ts +131 -0
  40. package/dist/e2b/e2b-sandbox-handle.js +27 -0
  41. package/dist/e2b/index.d.ts +18 -0
  42. package/dist/e2b/index.js +15 -0
  43. package/dist/e2b/provider.d.ts +63 -0
  44. package/dist/e2b/provider.js +88 -0
  45. package/dist/e2b/shell-quote.d.ts +21 -0
  46. package/dist/e2b/shell-quote.js +21 -0
  47. package/dist/e2b/to-array-buffer.d.ts +18 -0
  48. package/dist/e2b/to-array-buffer.js +18 -0
  49. package/dist/e2b/wrap-e2b-sandbox.d.ts +31 -0
  50. package/dist/e2b/wrap-e2b-sandbox.js +343 -0
  51. package/dist/node-worker.d.ts +111 -0
  52. package/dist/node-worker.js +150 -0
  53. package/package.json +106 -0
@@ -0,0 +1,36 @@
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
+ * The one error type every `SandboxSession`/`SandboxProviderPort` method rejects with. Named
19
+ * `SandboxOperationError` rather than `SandboxError` because `@e2b/code-interpreter`'s own base
20
+ * SDK (`e2b`) already exports a class literally called `SandboxError` — importing both into the
21
+ * same adapter file under the obvious names would collide.
22
+ *
23
+ * `cause` (the standard `Error` field, via `ErrorOptions`) is the escape hatch for the backend's
24
+ * own detail — the original E2B SDK error, the Node `ENOENT`, whatever a specific adapter caught.
25
+ * `category` is what a caller is expected to actually branch on; `cause` is for logging and
26
+ * debugging, not for a caller to inspect to figure out what really happened per backend.
27
+ */
28
+ export class SandboxOperationError extends Error {
29
+ category;
30
+ constructor({ category, message }, options) {
31
+ super(message, options);
32
+ this.name = 'SandboxOperationError';
33
+ this.category = category;
34
+ }
35
+ }
36
+ //# 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,18 @@
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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,232 @@
1
+ /**
2
+ * @file Backend-neutral execution contracts.
3
+ *
4
+ * Purpose:
5
+ * The vocabulary a host talks to a running sandbox through, with no statement about which
6
+ * backend that is. Every declaration here is an `interface`/`type` that erases at compile time,
7
+ * so this module contributes zero bytes and zero `require()` calls to a consumer's runtime graph.
8
+ * `SandboxOperationError` — the error type these methods reject with — lives in `errors.ts`
9
+ * instead, specifically so that claim stays true here rather than becoming "true except for one
10
+ * class." See `errors.ts`'s own doc comment for why it needs to be real runtime code.
11
+ *
12
+ * How it relates to the package:
13
+ * `core` is the half of `@jini-ai/sandbox` that must stay installable with no adapter present —
14
+ * a host that hasn't decided on E2B/local/WebContainer yet can still depend on `./core` for
15
+ * types and never compile `@e2b/code-interpreter`. That property is enforced the same way
16
+ * `@jini-ai/db`'s `core` enforces it against `better-sqlite3`: `pnpm guard`'s R12 check
17
+ * walks this directory's transitive import closure and fails if it reaches an adapter folder or
18
+ * an adapter package. See `scripts/check-driver-isolation.ts`.
19
+ *
20
+ * Architectural role:
21
+ * Ports. Adapters under `<adapter>/` implement `SandboxProviderPort`; host domain code depends
22
+ * on these and never on an adapter. The direction is one-way — `e2b` may import `core`, never
23
+ * the reverse — which is what lets `local` and `webcontainer` land later without restructuring
24
+ * either side.
25
+ *
26
+ * Three adapters are intended against this shape, only the first of which exists yet:
27
+ * - `e2b` (remote Firecracker microVM, this package's Slice 1) — a `PreviewTarget.url` is a
28
+ * forwarded public host, `boot()` genuinely takes seconds, the project root starts empty.
29
+ * - `local` (desktop: spawn `npm`/`vite` on the user's own machine, not yet built) — a
30
+ * `PreviewTarget.url` is `http://localhost:<port>`, `boot()` can resolve near-instantly, and
31
+ * the project root is the user's real, possibly-non-empty directory.
32
+ * - `webcontainer` (browser-only, blocked on WebContainers' commercial licensing, not yet
33
+ * built) — same shape again, just running in a tab instead of a VM or a desktop process.
34
+ * Both `e2b` and `local` are confirmed shipping targets — a host app that ships as both web and
35
+ * desktop needs the same project editable on either with identical observable results (same
36
+ * files in, same build/preview behavior out), not "one plus a maybe." A remote server-side
37
+ * backend other than E2B (e.g. Modal) is plausible later too; nothing below assumes E2B
38
+ * specifically — see the per-type notes for what was checked against that possibility.
39
+ *
40
+ * Nothing below may assume the sandbox is remote, that a preview is a public URL rather than
41
+ * `localhost`, or that `boot` is slow. A verb that only makes sense for one of the three belongs
42
+ * on that adapter's own class, not here — see the package README for what got excluded on that
43
+ * basis (session reconnection by ID, framework-specific scaffolding verbs).
44
+ *
45
+ * One asymmetry could NOT be unified away, so it's named here instead of papered over: `local`'s
46
+ * project root is the user's real directory and may already contain files this package never
47
+ * mounted (a `.git/` folder, files the user edited outside the sandbox entirely); `e2b`'s (and
48
+ * any other remote adapter's) project root starts empty except for what gets mounted into it.
49
+ * Nothing here promises the project root's contents are fully described by what this session's
50
+ * caller has mounted — code built against this interface must tolerate a project root that
51
+ * already has things in it.
52
+ */
53
+ /**
54
+ * A file to place at a path relative to the sandbox's project root. `content` is a plain
55
+ * `string` for text — UTF-8 by convention — or raw bytes for anything else. Theme assets under
56
+ * `assets/images|fonts|video|audio` (`.png`, `.woff2`, `.mp4`, …) are exactly why this isn't
57
+ * `string` alone: mounting a `.woff2` as UTF-8 text would silently corrupt it, and "silently" is
58
+ * the dangerous part — it would look like it worked. `Uint8Array` rather than `ArrayBuffer` or a
59
+ * base64 string because it's what both Node (`Buffer` already extends it) and the browser share
60
+ * with no conversion — the same reason `readFile` returns it below.
61
+ */
62
+ export interface SandboxFile {
63
+ readonly path: string;
64
+ readonly content: string | Uint8Array;
65
+ }
66
+ /** The result of running one command to completion. */
67
+ export interface CommandResult {
68
+ readonly stdout: string;
69
+ readonly stderr: string;
70
+ readonly exitCode: number;
71
+ }
72
+ /**
73
+ * Where the running dev server can currently be reached. Deliberately just a `url`, not a
74
+ * `publicUrl` — a local adapter returns `http://localhost:5173`, a remote one returns a
75
+ * forwarded host. Neither is more "canonical" than the other, and core must not encode a
76
+ * preference between them. Port allocation and port conflicts are a `local`-only concern (an
77
+ * already-bound port is meaningless for a fresh remote VM) and deliberately have no
78
+ * representation here — they surface as a `SandboxOperationError` with category `'port-in-use'`
79
+ * from whichever call first hits the conflict (typically `boot` or `startProcess`), not as a
80
+ * field on this type.
81
+ */
82
+ export interface PreviewTarget {
83
+ readonly url: string;
84
+ }
85
+ /** What kind of change a sandbox-originated file event represents. */
86
+ export type FileChangeKind = 'created' | 'modified' | 'deleted';
87
+ /**
88
+ * A file change the sandbox made on its own — a lockfile write from `installDependencies`, an
89
+ * HMR-triggered rewrite from the dev server itself. Not a notification of changes the host made
90
+ * through `mountFiles`; those are already known to the caller that made them. `path` carries no
91
+ * content — call `readFile` in response if the caller needs to know what actually changed.
92
+ */
93
+ export interface FileChangeEvent {
94
+ readonly path: string;
95
+ readonly kind: FileChangeKind;
96
+ }
97
+ /** Stops a previously registered listener from receiving further events. */
98
+ export type Unsubscribe = () => void;
99
+ /** One line of output from a still-running process, tagged by which stream it came from. Shared
100
+ * by `runCommand`'s optional live-output callback and `startProcess`'s `ProcessHandle` — one
101
+ * chunk shape for both rather than a second one for the foreground case. */
102
+ export interface ProcessOutputChunk {
103
+ readonly stream: 'stdout' | 'stderr';
104
+ readonly text: string;
105
+ }
106
+ /**
107
+ * A still-running process the caller can observe and stop — what `startProcess` returns for a
108
+ * command that is not expected to exit on its own. This exists because `getPreview` is only
109
+ * meaningful once something like a dev server is listening, and a dev server is by definition a
110
+ * command `runCommand`'s "wait for it to finish" contract cannot represent. All three intended
111
+ * adapters have a native shape for this (E2B's `commands.run(..., { background: true })`, a
112
+ * detached `child_process.spawn`, a WebContainer `process.spawn`), so it belongs in core rather
113
+ * than being adapter-specific.
114
+ */
115
+ export interface ProcessHandle {
116
+ /** Stop the process. Resolves once it has actually stopped. */
117
+ kill(): Promise<void>;
118
+ /** Subscribe to output as it's produced. Returns an `Unsubscribe`. */
119
+ onOutput(requiredArgs: {
120
+ listener: (chunk: ProcessOutputChunk) => void;
121
+ }): Unsubscribe;
122
+ }
123
+ /** Options shared by `runCommand` and `installDependencies` for observing output while the
124
+ * command is still in flight, without changing what either resolves with. */
125
+ export interface RunCommandOptions {
126
+ /** Called for each chunk of output as it's produced. The command the owner most wants to
127
+ * watch live — `npm install` — exits on its own and therefore goes through `runCommand`/
128
+ * `installDependencies`, not `startProcess`; without this, that output would be invisible
129
+ * until the whole install finished and then arrive as one frozen wall of text. */
130
+ readonly onOutput?: (chunk: ProcessOutputChunk) => void;
131
+ }
132
+ /**
133
+ * One running sandbox instance: a project root plus a process the host can install into,
134
+ * command, preview, and watch. `SandboxProviderPort.boot()` returns this; every other verb
135
+ * happens through it. Every method below rejects with `SandboxOperationError` on failure.
136
+ */
137
+ export interface SandboxSession {
138
+ /**
139
+ * Write (create or overwrite) files at their given paths. Upsert only — never deletes a file
140
+ * that isn't in `files`, on any adapter. This is not a simplification made for `e2b`'s sake: on
141
+ * `local`, `mountFiles` operates on the user's real project directory, so "replace the tree"
142
+ * would mean deleting files the user never gave this session permission to touch (a `.git/`
143
+ * folder, anything edited outside the sandbox). Because delete-by-omission is unsafe on
144
+ * `local`, upsert-only is the one semantic that's actually safe and correct on every adapter —
145
+ * there's no seam to name here, both backends already want the same behavior. A caller that
146
+ * needs to remove a file is out of scope for this package's first slice.
147
+ */
148
+ mountFiles(requiredArgs: {
149
+ files: readonly SandboxFile[];
150
+ }): Promise<void>;
151
+ /** Read one file's current bytes. Always returns raw bytes, never a decoded string — a caller
152
+ * that knows a path is text decodes it itself (`new TextDecoder().decode(...)`); guessing
153
+ * encoding from a path or extension is exactly the kind of silent-corruption risk
154
+ * `SandboxFile.content` exists to avoid on the write side. Rejects with category `'not-found'`
155
+ * if nothing exists at `path`. */
156
+ readFile(requiredArgs: {
157
+ path: string;
158
+ }): Promise<Uint8Array>;
159
+ /** List project files under `directory` (default: the project root), as paths relative to the
160
+ * project root — the same convention `SandboxFile.path` and `FileChangeEvent.path` use.
161
+ * Adapters document their traversal limits and excluded dependency/build/VCS directories. */
162
+ listFiles(requiredArgs: Record<string, never>, optionalArgs?: {
163
+ directory?: string;
164
+ }): Promise<readonly string[]>;
165
+ /** Run one command and wait for it to exit. Not for commands that don't exit on their own —
166
+ * see `startProcess` for those. `options.onOutput`, if given, is called with each chunk as
167
+ * it's produced; the command still resolves with the complete `CommandResult` once it exits,
168
+ * callers that only need the final result can ignore the option entirely. */
169
+ runCommand(requiredArgs: {
170
+ command: string;
171
+ }, optionalArgs?: RunCommandOptions & {
172
+ args?: readonly string[];
173
+ }): Promise<CommandResult>;
174
+ /**
175
+ * Install dependencies: the sandbox's package manager with no args when `packages` is
176
+ * omitted, or install exactly the named packages when given. Kept distinct from `runCommand`
177
+ * rather than left as a caller-composed shell string because the three intended adapters have
178
+ * genuinely different install mechanics, not just different shells. Takes the same
179
+ * `RunCommandOptions` as `runCommand` for the same reason: `npm install`'s scrolling output is
180
+ * exactly what a live terminal view needs to show, and it exits on its own rather than running
181
+ * forever, so it belongs here rather than behind `startProcess`.
182
+ */
183
+ installDependencies(requiredArgs: Record<string, never>, optionalArgs?: RunCommandOptions & {
184
+ packages?: readonly string[];
185
+ }): Promise<CommandResult>;
186
+ /** Start a command that is not expected to exit on its own — a dev server, most importantly.
187
+ * Returns as soon as the process has started, not once it's ready; use `getPreview` to find
188
+ * out once something is actually listening. */
189
+ startProcess(requiredArgs: {
190
+ command: string;
191
+ }, optionalArgs?: {
192
+ args?: readonly string[];
193
+ }): Promise<ProcessHandle>;
194
+ /** Where the dev server can currently be reached. Rejects (category `'timeout'`, typically) if
195
+ * nothing is listening yet. */
196
+ getPreview(): Promise<PreviewTarget>;
197
+ /** Subscribe to file changes the sandbox makes on its own. Returns an `Unsubscribe`. */
198
+ onFileChange(requiredArgs: {
199
+ listener: (event: FileChangeEvent) => void;
200
+ }): Unsubscribe;
201
+ /**
202
+ * Stop the sandbox and free its resources: every process this session started via
203
+ * `startProcess` is killed — a dev server that outlives `teardown` is, on `local`, an orphaned
204
+ * process holding a port on the user's own machine forever, so this is a hard requirement, not
205
+ * a nice-to-have. Never deletes the project root's files. On a remote adapter that's moot (the
206
+ * whole disposable VM goes away, and the user's real files were never in it to begin with); on
207
+ * `local`, where the project root IS the user's real directory, `teardown` must not touch the
208
+ * filesystem at all beyond stopping the processes it started. The session is unusable after
209
+ * this resolves.
210
+ */
211
+ teardown(): Promise<void>;
212
+ }
213
+ /**
214
+ * What a provider needs to start a session. Kept minimal on purpose: provider-specific options
215
+ * (an E2B API key, a local working directory root) belong on each adapter's own constructor or
216
+ * options type, not here — folding them in would make `core` describe backends it can't see.
217
+ */
218
+ export interface BootOptions {
219
+ /** Hint for which base template/image to start from. Meaning is adapter-specific. */
220
+ readonly template?: string;
221
+ }
222
+ /**
223
+ * The provider-level port: turns a still-cold environment into a running `SandboxSession`.
224
+ * Implemented once per backend. Rejects with `SandboxOperationError` — category `'unavailable'`
225
+ * for "couldn't reach or start the backend at all" (network failure, quota exceeded, `node` not
226
+ * on `PATH`), `'port-in-use'` for a pre-boot port conflict a `local` adapter can detect early,
227
+ * `'permission-denied'` for a rejected credential or an unwritable local directory.
228
+ */
229
+ export interface SandboxProviderPort {
230
+ boot(requiredArgs: Record<string, never>, optionalArgs?: BootOptions): Promise<SandboxSession>;
231
+ }
232
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file Backend-neutral execution contracts.
3
+ *
4
+ * Purpose:
5
+ * The vocabulary a host talks to a running sandbox through, with no statement about which
6
+ * backend that is. Every declaration here is an `interface`/`type` that erases at compile time,
7
+ * so this module contributes zero bytes and zero `require()` calls to a consumer's runtime graph.
8
+ * `SandboxOperationError` — the error type these methods reject with — lives in `errors.ts`
9
+ * instead, specifically so that claim stays true here rather than becoming "true except for one
10
+ * class." See `errors.ts`'s own doc comment for why it needs to be real runtime code.
11
+ *
12
+ * How it relates to the package:
13
+ * `core` is the half of `@jini-ai/sandbox` that must stay installable with no adapter present —
14
+ * a host that hasn't decided on E2B/local/WebContainer yet can still depend on `./core` for
15
+ * types and never compile `@e2b/code-interpreter`. That property is enforced the same way
16
+ * `@jini-ai/db`'s `core` enforces it against `better-sqlite3`: `pnpm guard`'s R12 check
17
+ * walks this directory's transitive import closure and fails if it reaches an adapter folder or
18
+ * an adapter package. See `scripts/check-driver-isolation.ts`.
19
+ *
20
+ * Architectural role:
21
+ * Ports. Adapters under `<adapter>/` implement `SandboxProviderPort`; host domain code depends
22
+ * on these and never on an adapter. The direction is one-way — `e2b` may import `core`, never
23
+ * the reverse — which is what lets `local` and `webcontainer` land later without restructuring
24
+ * either side.
25
+ *
26
+ * Three adapters are intended against this shape, only the first of which exists yet:
27
+ * - `e2b` (remote Firecracker microVM, this package's Slice 1) — a `PreviewTarget.url` is a
28
+ * forwarded public host, `boot()` genuinely takes seconds, the project root starts empty.
29
+ * - `local` (desktop: spawn `npm`/`vite` on the user's own machine, not yet built) — a
30
+ * `PreviewTarget.url` is `http://localhost:<port>`, `boot()` can resolve near-instantly, and
31
+ * the project root is the user's real, possibly-non-empty directory.
32
+ * - `webcontainer` (browser-only, blocked on WebContainers' commercial licensing, not yet
33
+ * built) — same shape again, just running in a tab instead of a VM or a desktop process.
34
+ * Both `e2b` and `local` are confirmed shipping targets — a host app that ships as both web and
35
+ * desktop needs the same project editable on either with identical observable results (same
36
+ * files in, same build/preview behavior out), not "one plus a maybe." A remote server-side
37
+ * backend other than E2B (e.g. Modal) is plausible later too; nothing below assumes E2B
38
+ * specifically — see the per-type notes for what was checked against that possibility.
39
+ *
40
+ * Nothing below may assume the sandbox is remote, that a preview is a public URL rather than
41
+ * `localhost`, or that `boot` is slow. A verb that only makes sense for one of the three belongs
42
+ * on that adapter's own class, not here — see the package README for what got excluded on that
43
+ * basis (session reconnection by ID, framework-specific scaffolding verbs).
44
+ *
45
+ * One asymmetry could NOT be unified away, so it's named here instead of papered over: `local`'s
46
+ * project root is the user's real directory and may already contain files this package never
47
+ * mounted (a `.git/` folder, files the user edited outside the sandbox entirely); `e2b`'s (and
48
+ * any other remote adapter's) project root starts empty except for what gets mounted into it.
49
+ * Nothing here promises the project root's contents are fully described by what this session's
50
+ * caller has mounted — code built against this interface must tolerate a project root that
51
+ * already has things in it.
52
+ */
53
+ export {};
54
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file Maps whatever the E2B SDK throws onto core's backend-neutral `SandboxErrorCategory`.
3
+ *
4
+ * Purpose:
5
+ * Every `E2bSandboxHandle` call this adapter makes can fail, and every `SandboxSession` method
6
+ * must reject with a `SandboxOperationError` carrying one of core's six categories — not a raw
7
+ * SDK error, which would leak `/e2b`-specific detail through a port meant to hide it.
8
+ *
9
+ * The mapping is by error `.name`, checked against the real `e2b` package's exported error class
10
+ * names (`AuthenticationError`, `FileNotFoundError`, …) — as strings, not as imported classes.
11
+ * Importing those classes here would give `categorizeE2bError` (and therefore
12
+ * `wrap-e2b-sandbox.ts`, which has been import-free of the real SDK by design since Slice 1) a
13
+ * hard dependency on `@e2b/code-interpreter`. Matching by name keeps that boundary: only
14
+ * `provider.ts` needs the real SDK installed to run; this file needs it only to have once read
15
+ * its `.d.ts`, which is a very different kind of dependency and doesn't show up in `import`.
16
+ */
17
+ import type { SandboxErrorCategory } from '../core/errors.js';
18
+ export declare function categorizeE2bError({ error }: {
19
+ error: unknown;
20
+ }): SandboxErrorCategory;
21
+ //# sourceMappingURL=categorize-e2b-error.d.ts.map
@@ -0,0 +1,24 @@
1
+ /** Real `e2b` SDK error class names this adapter knows how to categorize, keyed to which
2
+ * `SandboxErrorCategory` they mean. Anything not in this map — including a caught value that
3
+ * isn't an `Error` at all — falls through to `'unknown'`. */
4
+ const KNOWN_ERROR_NAMES = {
5
+ AuthenticationError: 'permission-denied',
6
+ FileNotFoundError: 'not-found',
7
+ NotFoundError: 'not-found',
8
+ SandboxNotFoundError: 'not-found',
9
+ TimeoutError: 'timeout',
10
+ RateLimitError: 'unavailable',
11
+ NotEnoughSpaceError: 'unavailable',
12
+ };
13
+ /** The `.name` of whatever was thrown, or `undefined` for a non-`Error` throw (E2B's SDK
14
+ * shouldn't throw a bare string/object, but a caller of this function must not assume). */
15
+ function nameOf(error) {
16
+ return error instanceof Error ? error.name : undefined;
17
+ }
18
+ export function categorizeE2bError({ error }) {
19
+ const name = nameOf(error);
20
+ if (name === undefined)
21
+ return 'unknown';
22
+ return KNOWN_ERROR_NAMES[name] ?? 'unknown';
23
+ }
24
+ //# sourceMappingURL=categorize-e2b-error.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file A starter Vite + React + Tailwind project, as plain file data.
3
+ *
4
+ * Purpose:
5
+ * Ported from open-lovable's `E2BProvider.setupViteApp` — the same file contents, minus the
6
+ * Python-heredoc plumbing that wrote them. That plumbing existed because open-lovable's E2B
7
+ * usage wrote files by executing a Python script inside the sandbox; the real
8
+ * `@e2b/code-interpreter` filesystem API this adapter uses (`files.write`) takes a plain string
9
+ * directly; a caller mounts this template with one `session.mountFiles({ files: DEFAULT_VITE_REACT_TEMPLATE })`
10
+ * call and no code execution is needed to place it.
11
+ *
12
+ * Architectural role:
13
+ * A convenience export, not part of the adapter's required surface. `SandboxProviderPort`/
14
+ * `SandboxSession` know nothing about Vite, React, or Tailwind — see `core/ports.ts`'s doc
15
+ * comment on why scaffolding a framework starter is a host-level concern, not the port's job.
16
+ * This lives under `./e2b` (not `./core`) for that reason: it is something an E2B-backed host
17
+ * may choose to use, not something every adapter must carry.
18
+ */
19
+ import type { SandboxFile } from '../core/ports.js';
20
+ /** Same starter app open-lovable's `setupViteApp` produces: a working Vite + React + Tailwind
21
+ * project with one placeholder screen, dropped in as data rather than assembled by a script
22
+ * running inside the sandbox. `allowedHosts` in `vite.config.js` intentionally omits
23
+ * `.vercel.run` (open-lovable supports Vercel Sandbox as a second backend; this package does
24
+ * not — see the README's three-adapter plan). */
25
+ export declare const DEFAULT_VITE_REACT_TEMPLATE: readonly SandboxFile[];
26
+ //# sourceMappingURL=default-vite-react-template.d.ts.map
@@ -0,0 +1,119 @@
1
+ const PACKAGE_JSON = `{
2
+ "name": "sandbox-app",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "vite --host",
7
+ "build": "vite build",
8
+ "preview": "vite preview"
9
+ },
10
+ "dependencies": {
11
+ "react": "^18.2.0",
12
+ "react-dom": "^18.2.0"
13
+ },
14
+ "devDependencies": {
15
+ "@vitejs/plugin-react": "^4.0.0",
16
+ "vite": "^4.3.9",
17
+ "tailwindcss": "^3.3.0",
18
+ "postcss": "^8.4.31",
19
+ "autoprefixer": "^10.4.16"
20
+ }
21
+ }
22
+ `;
23
+ const VITE_CONFIG = `import { defineConfig } from 'vite'
24
+ import react from '@vitejs/plugin-react'
25
+
26
+ export default defineConfig({
27
+ plugins: [react()],
28
+ server: {
29
+ host: '0.0.0.0',
30
+ port: 5173,
31
+ strictPort: true,
32
+ hmr: false,
33
+ allowedHosts: ['.e2b.app', '.e2b.dev', 'localhost', '127.0.0.1']
34
+ }
35
+ })
36
+ `;
37
+ const TAILWIND_CONFIG = `/** @type {import('tailwindcss').Config} */
38
+ export default {
39
+ content: [
40
+ "./index.html",
41
+ "./src/**/*.{js,ts,jsx,tsx}",
42
+ ],
43
+ theme: {
44
+ extend: {},
45
+ },
46
+ plugins: [],
47
+ }
48
+ `;
49
+ const POSTCSS_CONFIG = `export default {
50
+ plugins: {
51
+ tailwindcss: {},
52
+ autoprefixer: {},
53
+ },
54
+ }
55
+ `;
56
+ const INDEX_HTML = `<!DOCTYPE html>
57
+ <html lang="en">
58
+ <head>
59
+ <meta charset="UTF-8" />
60
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
61
+ <title>Sandbox App</title>
62
+ </head>
63
+ <body>
64
+ <div id="root"></div>
65
+ <script type="module" src="/src/main.jsx"></script>
66
+ </body>
67
+ </html>
68
+ `;
69
+ const MAIN_JSX = `import React from 'react'
70
+ import ReactDOM from 'react-dom/client'
71
+ import App from './App.jsx'
72
+ import './index.css'
73
+
74
+ ReactDOM.createRoot(document.getElementById('root')).render(
75
+ <React.StrictMode>
76
+ <App />
77
+ </React.StrictMode>,
78
+ )
79
+ `;
80
+ const APP_JSX = `function App() {
81
+ return (
82
+ <div className="min-h-screen bg-gray-900 text-white flex items-center justify-center p-4">
83
+ <div className="text-center max-w-2xl">
84
+ <p className="text-lg text-gray-400">
85
+ Sandbox Ready<br/>
86
+ Start building your React app with Vite and Tailwind CSS!
87
+ </p>
88
+ </div>
89
+ </div>
90
+ )
91
+ }
92
+
93
+ export default App
94
+ `;
95
+ const INDEX_CSS = `@tailwind base;
96
+ @tailwind components;
97
+ @tailwind utilities;
98
+
99
+ body {
100
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
101
+ background-color: rgb(17 24 39);
102
+ }
103
+ `;
104
+ /** Same starter app open-lovable's `setupViteApp` produces: a working Vite + React + Tailwind
105
+ * project with one placeholder screen, dropped in as data rather than assembled by a script
106
+ * running inside the sandbox. `allowedHosts` in `vite.config.js` intentionally omits
107
+ * `.vercel.run` (open-lovable supports Vercel Sandbox as a second backend; this package does
108
+ * not — see the README's three-adapter plan). */
109
+ export const DEFAULT_VITE_REACT_TEMPLATE = [
110
+ { path: 'package.json', content: PACKAGE_JSON },
111
+ { path: 'vite.config.js', content: VITE_CONFIG },
112
+ { path: 'tailwind.config.js', content: TAILWIND_CONFIG },
113
+ { path: 'postcss.config.js', content: POSTCSS_CONFIG },
114
+ { path: 'index.html', content: INDEX_HTML },
115
+ { path: 'src/main.jsx', content: MAIN_JSX },
116
+ { path: 'src/App.jsx', content: APP_JSX },
117
+ { path: 'src/index.css', content: INDEX_CSS },
118
+ ];
119
+ //# sourceMappingURL=default-vite-react-template.js.map