@opencoredev/sandbox-sdk 1.0.0-beta.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +70 -63
- package/dist/ai.js +1 -1
- package/dist/chunk-23tjmd39.js +8 -0
- package/dist/chunk-2ts3evzh.js +2 -0
- package/dist/chunk-83avbjns.js +2 -0
- package/dist/chunk-8786zrns.js +2 -0
- package/dist/chunk-8wq767xb.js +17 -0
- package/dist/chunk-9w9rddra.js +2 -0
- package/dist/chunk-bd481sb7.js +2 -0
- package/dist/chunk-ch71kvcp.js +2 -0
- package/dist/chunk-ckym4cht.js +23 -0
- package/dist/chunk-hgrwyjrb.js +2 -0
- package/dist/chunk-hzbssbep.js +31 -0
- package/dist/chunk-k60b4r27.js +2 -0
- package/dist/chunk-kk1hw8wa.js +1 -0
- package/dist/chunk-nw845a93.js +27 -0
- package/dist/chunk-q5vqajhg.js +2 -0
- package/dist/chunk-x2skgx3m.js +5 -0
- package/dist/chunk-x681p5d2.js +68 -0
- package/dist/chunk-xgxfy2n8.js +4 -0
- package/dist/core/process-records.d.ts +25 -0
- package/dist/errors.d.ts +67 -1
- package/dist/files.d.ts +11 -4
- package/dist/git.d.ts +1 -1
- package/dist/http.d.ts +225 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/keys.d.ts +5 -0
- package/dist/mastra.d.ts +1 -1
- package/dist/mastra.js +1 -1
- package/dist/memory.d.ts +4 -1
- package/dist/memory.js +11 -9
- package/dist/native.d.ts +127 -0
- package/dist/openai.js +1 -1
- package/dist/peer.d.ts +9 -0
- package/dist/provider.d.ts +38 -5
- package/dist/provider.js +1 -0
- package/dist/providers/agentos/errors.d.ts +3 -2
- package/dist/providers/agentos/index.d.ts +2 -9
- package/dist/providers/agentos/index.js +2 -2
- package/dist/providers/agentos/provider.d.ts +50 -0
- package/dist/providers/boat/index.d.ts +52 -9
- package/dist/providers/boat/index.js +1 -1
- package/dist/providers/boat-api/exec.d.ts +15 -2
- package/dist/providers/boat-api/follow.d.ts +24 -0
- package/dist/providers/boat-api/index.d.ts +45 -7
- package/dist/providers/boat-api/transport.d.ts +77 -0
- package/dist/providers/boxd/errors.d.ts +2 -2
- package/dist/providers/boxd/execute.d.ts +2 -2
- package/dist/providers/boxd/index.d.ts +2 -22
- package/dist/providers/boxd/index.js +24 -4
- package/dist/providers/boxd/provider.d.ts +74 -0
- package/dist/providers/boxd/transfers.d.ts +9 -0
- package/dist/providers/daytona/api.d.ts +124 -0
- package/dist/providers/daytona/buffered.d.ts +2 -2
- package/dist/providers/daytona/errors.d.ts +18 -2
- package/dist/providers/daytona/exec.d.ts +3 -3
- package/dist/providers/daytona/index.d.ts +53 -4
- package/dist/providers/daytona/index.js +18 -10
- package/dist/providers/daytona/multipart.d.ts +25 -0
- package/dist/providers/e2b/envd.d.ts +113 -0
- package/dist/providers/e2b/errors.d.ts +20 -3
- package/dist/providers/e2b/index.d.ts +41 -3
- package/dist/providers/e2b/index.js +1 -1
- package/dist/providers/freestyle/client.d.ts +87 -0
- package/dist/providers/freestyle/deadline.d.ts +3 -2
- package/dist/providers/freestyle/errors.d.ts +14 -1
- package/dist/providers/freestyle/execute.d.ts +3 -7
- package/dist/providers/freestyle/index.d.ts +28 -2
- package/dist/providers/freestyle/index.js +5 -33
- package/dist/providers/local/docker.d.ts +10 -6
- package/dist/providers/local/index.d.ts +29 -0
- package/dist/providers/local/index.js +2 -2
- package/dist/providers/railway/errors.d.ts +7 -1
- package/dist/providers/railway/index.d.ts +2 -23
- package/dist/providers/railway/index.js +1 -1
- package/dist/providers/railway/provider.d.ts +53 -0
- package/dist/providers/sandboxer/index.d.ts +15 -8
- package/dist/providers/sandboxer/index.js +1 -1
- package/dist/providers/superserve/errors.d.ts +2 -2
- package/dist/providers/superserve/execute.d.ts +3 -8
- package/dist/providers/superserve/index.d.ts +32 -3
- package/dist/providers/superserve/index.js +5 -37
- package/dist/providers/superserve/routes.d.ts +80 -0
- package/dist/providers/superserve/session.d.ts +33 -0
- package/dist/providers/tenki/deadline.d.ts +1 -1
- package/dist/providers/tenki/errors.d.ts +3 -3
- package/dist/providers/tenki/exec.d.ts +1 -1
- package/dist/providers/tenki/files.d.ts +1 -1
- package/dist/providers/tenki/index.d.ts +2 -27
- package/dist/providers/tenki/index.js +19 -16
- package/dist/providers/tenki/provider.d.ts +95 -0
- package/dist/providers/tenki/ready.d.ts +1 -1
- package/dist/providers/tenki/records.d.ts +16 -0
- package/dist/providers/tenki/stream.d.ts +2 -2
- package/dist/providers/upstash/buffered.d.ts +1 -1
- package/dist/providers/upstash/errors.d.ts +1 -1
- package/dist/providers/upstash/exec.d.ts +2 -2
- package/dist/providers/upstash/files.d.ts +1 -1
- package/dist/providers/upstash/index.d.ts +2 -34
- package/dist/providers/upstash/index.js +12 -18
- package/dist/providers/upstash/provider.d.ts +81 -0
- package/dist/providers/vercel/errors.d.ts +3 -1
- package/dist/providers/vercel/index.d.ts +13 -5
- package/dist/providers/vercel/index.js +1 -1
- package/dist/providers/vercel/provider.d.ts +50 -2
- package/dist/providers/vercel/transport.d.ts +7 -4
- package/dist/run.d.ts +6 -4
- package/dist/shared/deadline.d.ts +12 -0
- package/dist/shared/guest.d.ts +18 -0
- package/dist/shared/json.d.ts +11 -0
- package/dist/shared/metadata.d.ts +19 -0
- package/dist/shared/narrow.d.ts +8 -0
- package/dist/shared/native-error.d.ts +42 -0
- package/dist/shared/paged-exec.d.ts +22 -0
- package/dist/shared/shell.d.ts +2 -0
- package/dist/{providers/freestyle → shared}/wire.d.ts +1 -1
- package/dist/shell/process-records.d.ts +44 -0
- package/dist/streams.d.ts +72 -0
- package/dist/testing.d.ts +12 -2
- package/dist/testing.js +7 -4
- package/dist/tool-security.d.ts +4 -4
- package/dist/tools.d.ts +3 -2
- package/dist/tools.js +1 -1
- package/dist/types.d.ts +14 -6
- package/package.json +29 -46
- package/dist/chunk-59t3rqja.js +0 -2
- package/dist/chunk-cwx6cc31.js +0 -2
- package/dist/chunk-exv1kf89.js +0 -60
- package/dist/chunk-gc8zdxyb.js +0 -2
- package/dist/chunk-hjzhc3qg.js +0 -40
- package/dist/chunk-md6fmprc.js +0 -1
- package/dist/chunk-t5vr9nd8.js +0 -8
- package/dist/chunk-v6y7eqxw.js +0 -27
- package/dist/chunk-yed8mvs7.js +0 -2
- package/dist/chunk-yrsb6hws.js +0 -5
- package/dist/chunk-z9rjzn28.js +0 -2
- package/dist/providers/boxd/guest.d.ts +0 -14
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fields adapters read from a thrown native SDK error. A native SDK can throw anything, so
|
|
3
|
+
* each optional field is set only when the thrown value carries it with that type. Text fields
|
|
4
|
+
* classify the failure; they can echo the request, so what an adapter keeps goes through
|
|
5
|
+
* `describeNative` or a bounded allowlist.
|
|
6
|
+
*/
|
|
7
|
+
export interface NativeError {
|
|
8
|
+
/** An Error's `name`, or "" for anything else thrown. Bundlers can rename it with the class. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** An Error's `message`, or "" for anything else thrown. */
|
|
11
|
+
message: string;
|
|
12
|
+
/** A numeric `status` field. */
|
|
13
|
+
status?: number;
|
|
14
|
+
/** A numeric `statusCode` field. */
|
|
15
|
+
statusCode?: number;
|
|
16
|
+
/** The status of an attached fetch `Response`. */
|
|
17
|
+
responseStatus?: number;
|
|
18
|
+
/** boxd's gRPC status code. */
|
|
19
|
+
grpcCode?: number;
|
|
20
|
+
/** A string or numeric `code` field: an errno such as `ENOENT`, a provider code, or an RPC code. */
|
|
21
|
+
code?: string | number;
|
|
22
|
+
/** Boat's API envelope error code. */
|
|
23
|
+
apiCode?: string;
|
|
24
|
+
/** The `error.code` of a parsed response body, which the Vercel SDK attaches as `json`. */
|
|
25
|
+
bodyCode?: string;
|
|
26
|
+
/** Daytona's `source`: which Daytona service answered. */
|
|
27
|
+
source?: string;
|
|
28
|
+
/** The request path a Freestyle API error names. */
|
|
29
|
+
path?: string;
|
|
30
|
+
/** A `requestId` field. */
|
|
31
|
+
requestId?: string;
|
|
32
|
+
/** The sandbox a failed Daytona create names. */
|
|
33
|
+
sandboxId?: string;
|
|
34
|
+
/** String values of a `headers` field: a fetch `Headers` or a plain object. */
|
|
35
|
+
headers: ReadonlyMap<string, string>;
|
|
36
|
+
/** String values of a gRPC `metadata` field. */
|
|
37
|
+
metadata: ReadonlyMap<string, string>;
|
|
38
|
+
/** The value this error wraps, for adapters that read a chain. */
|
|
39
|
+
cause?: unknown;
|
|
40
|
+
}
|
|
41
|
+
/** Decodes the fields of {@link NativeError} from any thrown value. */
|
|
42
|
+
export declare function decodeNative(cause: unknown): NativeError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ExecInput, ExecResult } from "../provider.js";
|
|
2
|
+
import { SandboxError, type ErrorCode } from "../errors.js";
|
|
3
|
+
/** A guest that runs paged supervisors: Freestyle and Superserve. */
|
|
4
|
+
export interface PagedGuest {
|
|
5
|
+
raw(command: string): Promise<string>;
|
|
6
|
+
read(path: string, range: {
|
|
7
|
+
offset: number;
|
|
8
|
+
length: number;
|
|
9
|
+
}, signal?: AbortSignal): Promise<Uint8Array>;
|
|
10
|
+
}
|
|
11
|
+
export interface PagedExecution {
|
|
12
|
+
guest: PagedGuest;
|
|
13
|
+
input: ExecInput;
|
|
14
|
+
/** Runs the provider's supervisor for `root` and returns its first response page. */
|
|
15
|
+
launch: (root: string, signal: AbortSignal) => Promise<string>;
|
|
16
|
+
/** Builds the provider's own error, so messages keep its name and advice. */
|
|
17
|
+
fail: (message: string, code?: ErrorCode) => SandboxError;
|
|
18
|
+
}
|
|
19
|
+
/** Runs a command through a supervisor that answers with its first output page,
|
|
20
|
+
* then reads the rest of its output with bounded ranged reads.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pagedExecute(execution: PagedExecution): Promise<ExecResult>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Exit codes the record programs use to report a state, not a failure. */
|
|
2
|
+
export declare const recordExit: {
|
|
3
|
+
/** The log reader found no spec.json: the process was never started. */
|
|
4
|
+
readonly missing: 66;
|
|
5
|
+
/** Setup found a spec.json without an exit file: the process is still running. */
|
|
6
|
+
readonly running: 73;
|
|
7
|
+
/** Setup could not enter the working directory and recorded that as the process exit. */
|
|
8
|
+
readonly badCwd: 74;
|
|
9
|
+
};
|
|
10
|
+
/** Print spec.json, a NUL, a `base start size status` header line, then a base64 log window.
|
|
11
|
+
* It takes the writer's lock, so rotation cannot pair a new base with an old log. */
|
|
12
|
+
export declare function logPageScript(input: {
|
|
13
|
+
dir: string;
|
|
14
|
+
/** Absolute log offset to read after; undefined starts at the oldest kept byte. */
|
|
15
|
+
after: number | undefined;
|
|
16
|
+
lookbehind: number;
|
|
17
|
+
length: number;
|
|
18
|
+
}): string;
|
|
19
|
+
/** Prepare a process directory in one exec. stdin carries spec.json and restart.json as two
|
|
20
|
+
* base64 lines, which keeps exact UTF-8 bytes through transports that normalize input.
|
|
21
|
+
* A missing working directory becomes the process's own failed exit and log. */
|
|
22
|
+
export declare function recordSetupScript(input: {
|
|
23
|
+
dir: string;
|
|
24
|
+
cwd: string;
|
|
25
|
+
}): string;
|
|
26
|
+
/** The sed program the stream readers apply to each chunk. Each secret line is replaced
|
|
27
|
+
* whole, and each of its prefixes at a chunk's end and suffixes at its start, so a secret
|
|
28
|
+
* split across two reads is still redacted. */
|
|
29
|
+
export declare function redactionSedScript(secrets: readonly string[]): string;
|
|
30
|
+
/** The supervisor runs the command with stdout and stderr on two FIFOs, feeds each through
|
|
31
|
+
* a stream reader into out.log, and writes the exit code when it ends, TERM included. */
|
|
32
|
+
export declare function supervisorScript(input: {
|
|
33
|
+
dir: string;
|
|
34
|
+
cwd: string;
|
|
35
|
+
command: string;
|
|
36
|
+
sedPath: string;
|
|
37
|
+
}): string;
|
|
38
|
+
/** Start the supervisor detached from this exec and record its pid. With waitForExit, poll
|
|
39
|
+
* about 100 ms for a command that exits at once and print its exit code if it does. */
|
|
40
|
+
export declare function detachedLaunchScript(input: {
|
|
41
|
+
dir: string;
|
|
42
|
+
supervisor: string;
|
|
43
|
+
waitForExit: boolean;
|
|
44
|
+
}): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Frame readers for streamed provider responses: NDJSON, server-sent events and Connect envelopes.
|
|
3
|
+
*
|
|
4
|
+
* Each reads a `ReadableStream<Uint8Array>` and yields frames as an async iterable. Frames are split on bytes,
|
|
5
|
+
* so a UTF-8 character or a frame header split across chunks is reassembled. Every frame is bounded
|
|
6
|
+
* (`maxFrameBytes`, default 16 MiB). Leaving a `for await` early (break, return, throw) cancels the body.
|
|
7
|
+
*
|
|
8
|
+
* Failures are SandboxErrors; {@link streamFault} says which protocol fault it was, so an adapter can resume
|
|
9
|
+
* a `disconnected` or `truncated` stream and give up on the rest:
|
|
10
|
+
* - `disconnected`: reading the body failed (the connection dropped).
|
|
11
|
+
* - `truncated`: the body ended inside a frame, or before the protocol's terminal frame.
|
|
12
|
+
* - `frame_too_large`: a frame is larger than `maxFrameBytes`.
|
|
13
|
+
* - `malformed`: a frame is not valid for the protocol.
|
|
14
|
+
*/
|
|
15
|
+
import type { JsonValue } from "./shared/json.js";
|
|
16
|
+
export type StreamFault = "disconnected" | "truncated" | "frame_too_large" | "malformed";
|
|
17
|
+
export interface StreamOptions {
|
|
18
|
+
/** Provider name on errors. */
|
|
19
|
+
provider: string;
|
|
20
|
+
sandboxId?: string;
|
|
21
|
+
/** Largest frame in bytes. Default: 16 MiB. */
|
|
22
|
+
maxFrameBytes?: number;
|
|
23
|
+
/** Stop reading, cancel the body and reject with `aborted`. */
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
/** The protocol fault behind a stream error, or `undefined` for any other error. */
|
|
27
|
+
export declare function streamFault(cause: unknown): StreamFault | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Newline-delimited JSON: one value per `\n`-terminated line (`\r\n` too). Blank lines are skipped. A last line
|
|
30
|
+
* without a newline is accepted when it parses as JSON; otherwise it is `truncated`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ndjson(body: ReadableStream<Uint8Array>, options: StreamOptions): AsyncGenerator<JsonValue | undefined, void, undefined>;
|
|
33
|
+
/** One server-sent event. */
|
|
34
|
+
export interface ServerSentEvent {
|
|
35
|
+
/** The `event:` field. Default: `"message"`. */
|
|
36
|
+
event: string;
|
|
37
|
+
/** The `data:` lines joined with `\n`. */
|
|
38
|
+
data: string;
|
|
39
|
+
/** The last event ID seen so far (`id:` persists across events), for a `Last-Event-ID` resume. */
|
|
40
|
+
id?: string;
|
|
41
|
+
/** The `retry:` reconnection time in ms, when this event set one. */
|
|
42
|
+
retry?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Server-sent events (the WHATWG `text/event-stream` format): `\n`, `\r\n` or `\r` line ends, `:` comments,
|
|
46
|
+
* multi-line `data`, and `id` that persists. Events with no `data` line are not dispatched, as in browsers.
|
|
47
|
+
* A body that ends inside an event (no blank line after it) is `truncated`, unless `lenientEnd` dispatches it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function sse(body: ReadableStream<Uint8Array>, options: StreamOptions & {
|
|
50
|
+
lenientEnd?: boolean;
|
|
51
|
+
}): AsyncGenerator<ServerSentEvent, void, undefined>;
|
|
52
|
+
/** A Connect streaming frame: a message, or the end-of-stream frame with the outcome. */
|
|
53
|
+
export type ConnectFrame = {
|
|
54
|
+
kind: "message";
|
|
55
|
+
message: JsonValue | undefined;
|
|
56
|
+
} | {
|
|
57
|
+
kind: "end";
|
|
58
|
+
error?: {
|
|
59
|
+
code: string;
|
|
60
|
+
message?: string;
|
|
61
|
+
details?: unknown[];
|
|
62
|
+
};
|
|
63
|
+
metadata?: Record<string, string[]>;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Connect protocol server-stream envelopes (JSON codec): a flags byte, a 4-byte big-endian length, then the
|
|
67
|
+
* payload. Flag `0x02` marks the end-of-stream frame (`{ error?, metadata? }`), which must come last. A body
|
|
68
|
+
* that ends without it is `truncated`; compressed frames (`0x01`) are `malformed`, since none is negotiated.
|
|
69
|
+
*/
|
|
70
|
+
export declare function connectEnvelopes(body: ReadableStream<Uint8Array>, options: StreamOptions): AsyncGenerator<ConnectFrame, void, undefined>;
|
|
71
|
+
/** Encodes one Connect envelope with a JSON payload, for a streaming request body. */
|
|
72
|
+
export declare function connectEnvelope(message: JsonValue | undefined, end?: boolean): Uint8Array;
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import type { Provider } from "./provider.js";
|
|
2
2
|
/** Register a provider-independent Vitest suite. Call inside a test module.
|
|
3
|
-
* live must be explicitly true to run a cloud provider.
|
|
4
|
-
*
|
|
3
|
+
* live must be explicitly true to run a cloud provider. Each case calls the factory
|
|
4
|
+
* for a fresh provider, and the reattach check connects through a second one, so a
|
|
5
|
+
* factory for in-process state must return a shared instance.
|
|
5
6
|
* Live runs give each case 120 seconds by default, since real providers boot
|
|
6
7
|
* machines and cross the network; pass timeoutMs to change it.
|
|
8
|
+
* snapshotExpiry declares what `snapshot({ expiresInMs })` does: "honored" must
|
|
9
|
+
* return a snapshot, "refused" must throw unsupported or invalid_argument. snapshot()
|
|
10
|
+
* returns only an ID, so the suite cannot read the expiry back; check it in the
|
|
11
|
+
* provider's own tests. Omit it to check only the core's input validation.
|
|
12
|
+
* unsupported skips checks the provider cannot run, with the reason: gitPush for a
|
|
13
|
+
* runtime without git, httpProbe for previews that no HTTP client can reach.
|
|
7
14
|
*/
|
|
8
15
|
export declare function runConformance(factory: () => Provider | Promise<Provider>, options: {
|
|
9
16
|
live: boolean;
|
|
10
17
|
ports?: number[];
|
|
11
18
|
timeoutMs?: number;
|
|
19
|
+
snapshotExpiry?: "honored" | "refused";
|
|
12
20
|
unsupported?: {
|
|
13
21
|
processes?: string;
|
|
14
22
|
previews?: string;
|
|
15
23
|
gitPush?: string;
|
|
24
|
+
httpProbe?: string;
|
|
25
|
+
fileModes?: string;
|
|
16
26
|
};
|
|
17
27
|
}): void;
|
package/dist/testing.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{X,O,j,W,Q}from"./chunk-hgrwyjrb.js";import{e}from"./chunk-xgxfy2n8.js";import{describe as D,test as c,expect as a,afterEach as P}from"vitest";import{mkdtemp as S,mkdir as T,writeFile as _,readFile as A,rm as R}from"node:fs/promises";import{tmpdir as I}from"node:os";import{join as w}from"node:path";function z(m,n){let f=n.timeoutMs??(n.live?120000:void 0);D("Sandbox SDK conformance",{timeout:f},()=>{let u=[],h=[];async function g(){let t=await m();if(!n.live&&!["memory","local"].includes(t.name))throw new e("Live provider refused. live is false. Enable live explicitly with provider credentials.",{code:"invalid_argument"});return t}async function d(t={},s){let o=s??await g(),i=await O(o,{ports:n.ports,...t});return u.push(i),{provider:o,box:i}}P(async()=>{await Promise.all(u.splice(0).map((t)=>t.destroy())),await Promise.all(h.splice(0).map((t)=>R(t,{recursive:!0,force:!0})))}),c("create, key lookup, connect and labels",async()=>{let t=await g(),s=`conformance-${crypto.randomUUID()}`,o=await O(t,{key:s,labels:{suite:s}});u.push(o);let i=await O(t,{key:s});u.push(i),a(o.created).toBe(!0),a(i.created).toBe(!1),a(i.id).toBe(o.id);let r=await j(t,o.id);u.push(r),a(r.native).toBeDefined(),await a.poll(async()=>(await W(t,{labels:{suite:s}})).map((p)=>p.id),{timeout:15000,interval:500}).toEqual([o.id])}),c("exit results, stdin, resolved cwd and default environment",async()=>{let{box:t}=await d();a(await t.run("false")).toMatchObject({ok:!1,exitCode:1,timedOut:!1}),a(await t.run("exit 7")).toMatchObject({exitCode:7}),a((await t.run("cat",{stdin:`input
|
|
2
2
|
`})).stdout).toBe(`input
|
|
3
3
|
`),a((await t.run("pwd")).stdout).toBe(`/workspace
|
|
4
|
-
`),a((await t.run(`printf '%s' "$CI:$PAGER:$GIT_TERMINAL_PROMPT:$DEBIAN_FRONTEND:$TERM:$NO_COLOR"`)).stdout).toBe("1:cat:0:noninteractive:dumb:1")}),
|
|
5
|
-
`)}),
|
|
6
|
-
second`,"app/b.ts":"two two","app/raw":new Uint8Array([0,255])}),a(await t.files.read("app/raw",{as:"bytes"})).toEqual(new Uint8Array([0,255])),a((await t.files.stat("app/a.ts")).type).toBe("file"),a((await t.files.list("app",{recursive:!0,glob:"**/*.ts"})).length).toBe(2),a(await t.files.search("TODO",{path:"app",glob:"*.ts"})).toMatchObject([{line:1,text:"TODO one"}]),await a(t.files.edit("app/a.ts",{find:"missing",replace:"x"})).rejects.toMatchObject({code:"edit_not_found"}),await a(t.files.edit("app/b.ts",{find:"two",replace:"x"})).rejects.toMatchObject({code:"edit_not_unique"});let
|
|
4
|
+
`),a((await t.run(`printf '%s' "$CI:$PAGER:$GIT_TERMINAL_PROMPT:$DEBIAN_FRONTEND:$TERM:$NO_COLOR"`)).stdout).toBe("1:cat:0:noninteractive:dumb:1")});let E=Math.max(f??0,30000);c("timeout and abort kill a launched command before its delayed side effect",{timeout:E},async()=>{let{box:t}=await d(),s=Date.now();await t.run("true");let o=Date.now()-s,i=500+2*o,r=Math.ceil((i+o+500)/1000)*1000,p=500+o;async function l(b,y){let x=Promise.resolve(t.run(`echo launched > ${b}-launched; sleep ${r/1000}; echo survived > ${b}-survived`,y));return await a.poll(()=>t.files.exists(`${b}-launched`),{timeout:r,interval:20}).toBe(!0),{run:x,launchedAt:Date.now()}}async function v(b,y){let x=y+r+p-Date.now();await new Promise((C)=>setTimeout(C,Math.max(0,x))),a(await t.files.exists(`${b}-survived`)).toBe(!1)}let M=await l("timeout",{timeoutMs:i});a(await M.run).toMatchObject({timedOut:!0,exitCode:null,ok:!1}),await v("timeout",M.launchedAt);let k=new AbortController,B=await l("abort",{signal:k.signal});k.abort(),a(await B.run).toMatchObject({timedOut:!0,exitCode:null,ok:!1}),await v("abort",B.launchedAt)}),c("bounded head and tail output, interleaving and streaming",async()=>{let{box:t}=await d(),s=await t.run(`printf '${"a".repeat(1024)}END'`,{maxOutputBytes:64});a(s.truncated).toBe(!0),a(s.stdout.startsWith("a")).toBe(!0),a(s.stdout.endsWith("END")).toBe(!0),a(s.stdout).toContain("bytes cut");let o=t.run("printf A; printf B >&2; printf C"),i=[];for await(let l of o)i.push(l.text);let r=await o;a(r).toMatchObject({stdout:"AC",stderr:"B",output:i.join("")});let p=[];for await(let l of t.run("echo streamed"))p.push(l.text);a(p.join("")).toBe(`streamed
|
|
5
|
+
`)}),c("tag escaping and chain options prevent interpolation execution",async()=>{let{box:t}=await d(),s="x'; echo injected; printf '";a((await t.$`printf '%s' ${"x'; echo injected; printf '"}`.cwd(".").env({X:"ok"}).timeout(n.live?1e4:1000)).stdout).toBe("x'; echo injected; printf '"),a((await t.run(`printf '%s' "$X"`)).stdout).toBe("")}),c("all file primitives, exact edits, glob search, checkpoints",async()=>{let{box:t}=await d({trackChanges:!0});await t.files.write({"app/a.ts":`TODO one
|
|
6
|
+
second`,"app/b.ts":"two two","app/raw":new Uint8Array([0,255])}),a(await t.files.read("app/raw",{as:"bytes"})).toEqual(new Uint8Array([0,255])),a((await t.files.stat("app/a.ts")).type).toBe("file"),a((await t.files.list("app",{recursive:!0,glob:"**/*.ts"})).length).toBe(2),a(await t.files.search("TODO",{path:"app",glob:"*.ts"})).toMatchObject([{line:1,text:"TODO one"}]),await a(t.files.edit("app/a.ts",{find:"missing",replace:"x"})).rejects.toMatchObject({code:"edit_not_found"}),await a(t.files.edit("app/b.ts",{find:"two",replace:"x"})).rejects.toMatchObject({code:"edit_not_unique"});let s=await t.files.mark();await t.files.edit("app/a.ts",{find:"TODO",replace:"DONE"}),await t.files.remove("app/b.ts"),await t.files.write("app/new","new"),a(await t.files.changes({since:s})).toMatchObject({added:["/workspace/app/new"],modified:["/workspace/app/a.ts"],removed:["/workspace/app/b.ts"]}),a((await t.files.changes()).added).toContain("/workspace/app/a.ts"),await t.files.remove("app",{recursive:!0}),a(await t.files.exists("app")).toBe(!1)}),c("write mode sets permission bits and rejects invalid modes",async(t)=>{if(n.unsupported?.fileModes){t.skip(n.unsupported.fileModes);return}let{box:s}=await d();await s.files.write("modes/secret","x",{mode:384}),await s.files.write({"modes/a":"a","modes/b":"b"},{mode:416}),a((await s.run("stat -c %a modes/secret modes/a modes/b")).stdout).toBe(`600
|
|
7
|
+
640
|
|
8
|
+
640
|
|
9
|
+
`);for(let o of[-1,4096,1.5,Number.NaN])await a(s.files.write("modes/bad","x",{mode:o})).rejects.toMatchObject({code:"invalid_argument"});a(await s.files.exists("modes/bad")).toBe(!1)}),c("snapshot expiresInMs is validated, forwarded to the provider, and accepted or refused as declared",async(t)=>{let s=await g(),o=N(s),{box:i}=await d({},s);if(!X(i,"snapshot")){t.skip();return}if(await a(i.snapshot({expiresInMs:-1})).rejects.toMatchObject({code:"invalid_argument"}),a(o).toEqual([]),n.snapshotExpiry==="honored")a((await i.snapshot({expiresInMs:86400000})).id).not.toBe(""),a(o).toEqual([{expiresInMs:86400000}]);else if(n.snapshotExpiry==="refused")await a(i.snapshot({expiresInMs:86400000})).rejects.toMatchObject({name:"SandboxError",code:a.stringMatching(/^(unsupported|invalid_argument)$/)}),a(o).toEqual([{expiresInMs:86400000}])}),c("changes without since needs trackChanges or an explicit mark",async()=>{let{box:t}=await d();await a(t.files.changes()).rejects.toMatchObject({code:"invalid_argument",message:a.stringContaining("trackChanges: true")}),await t.files.write("late","x");let s=await t.files.mark("start");await t.files.write("late","y"),a((await t.files.changes()).modified).toEqual(["/workspace/late"]),a((await t.files.changes({since:s})).modified).toEqual(["/workspace/late"])}),c("upload/download round trip with ignores",async()=>{let{box:t}=await d(),s=await S(w(I(),"sdk-conformance-"));h.push(s),await T(w(s,"source")),await _(w(s,"source","keep"),"hello"),await _(w(s,"source","ignore"),"no"),await t.files.upload(w(s,"source"),"upload",{ignore:["ignore"]}),a(await t.files.exists("upload/ignore")).toBe(!1),await t.files.download("upload",w(s,"download")),a(await A(w(s,"download","keep"),"utf8")).toBe("hello")}),c("file watch observes changes",{timeout:Math.max(f??0,60000)},async()=>{let{box:t}=await d(),s=Date.now();await t.files.write("watch/file","a");let o=Date.now()-s,i=[],r=t.files.watch("watch",(l)=>i.push(l.type),{recursive:!0,intervalMs:10}),p=0;try{await a.poll(async()=>(await t.files.write("watch/file",`different-${p++}`),i),{timeout:Math.max(1e4,20*o),interval:50}).toContain("modified")}finally{r()}}),c("process logs, cursors, fresh client reattach, stop and exit-before-ready",async(t)=>{if(n.unsupported?.processes){t.skip(n.unsupported.processes);return}let{box:s}=await d(),o=await s.start("echo READY; sleep 5",{name:"dev",ready:{log:/READY/},readyTimeoutMs:2000});a(o.ready).toBe(!0);let i=await o.logs();a(i.text).toContain("READY"),a((await o.logs({after:i.nextCursor})).text).toBe("");let r=await j(await g(),s.id);u.push(r),a((await r.processes()).map((p)=>p.name)).toContain("dev"),a((await r.process("dev").logs()).text).toContain("READY"),await r.process("dev").stop({graceMs:10}),a((await o.wait()).exitCode).not.toBe(null),await a(s.start("exit 3",{name:"early",ready:{log:/never/},readyTimeoutMs:1000})).rejects.toMatchObject({code:"process_exited"})}),c("readiness timeout preserves the process",async(t)=>{if(n.unsupported?.processes){t.skip(n.unsupported.processes);return}let{box:s}=await d();await a(s.start("sleep 5",{name:"unready",ready:{log:/never/},readyTimeoutMs:30})).rejects.toMatchObject({code:"timeout"}),a(s.process("unready").ready).toBe(!1),a((await s.processes())[0]?.status).toBe("running"),await s.process("unready").stop({graceMs:10})}),c("preview and capability gating",async()=>{let{provider:t,box:s}=await d();if(n.unsupported?.previews)await a(s.preview(3000)).rejects.toMatchObject({code:"unsupported"});else a(["http:","https:"]).toContain(new URL((await s.preview(3000)).url).protocol);for(let[o,i]of[["pause","pause"],["snapshot","snapshot"],["terminal","terminal"]])a(i in s).toBe(t.capabilities.has(o));if(!t.capabilities.has("network-policy"))await a(O(t,{network:"none"})).rejects.toMatchObject({code:"unsupported"});if(!t.capabilities.has("size"))await a(O(t,{size:"small"})).rejects.toMatchObject({code:"unsupported"})}),c("close, disposal, destroy and label-scoped reaping",async()=>{let{provider:t,box:s}=await d(),o=s.id;await s.close(),a((await j(t,o)).id).toBe(o),await s.destroy(),await a(j(t,o)).rejects.toMatchObject({code:"not_found"});let i=crypto.randomUUID(),r=await O(t,{key:i,labels:{reap:i}});u.push(r),await r[Symbol.asyncDispose](),a((await t.connect(r.id)).id).toBe(r.id),a(await Q(t,{labels:{reap:i},olderThanMs:0})).toBe(1);let p=await O(t);await p[Symbol.asyncDispose](),await a(t.connect(p.id)).rejects.toMatchObject({code:"not_found"})}),c("usage counters",async()=>{let{box:t}=await d();await t.run("echo abc"),a(await t.usage()).toMatchObject({commands:1,bytesOut:4})}),c("local bare git clone, commit and push (live providers only)",async(t)=>{if(n.unsupported?.gitPush){t.skip(n.unsupported.gitPush);return}let{box:s}=await d();a((await s.run("git init --bare /tmp/sdk-bare")).ok).toBe(!0),a((await s.git.clone("/tmp/sdk-bare",{dir:"repo"})).ok).toBe(!0),await s.run("git config user.name Conformance; git config user.email test@example.com",{cwd:"repo"}),await s.files.write("repo/test","test"),a((await s.git.commit("repo",{message:"conformance",all:!0})).ok).toBe(!0),a((await s.git.status("repo")).stdout).toBe(""),a((await s.git.push("repo",{branch:"HEAD"})).ok).toBe(!0)}),c("real HTTP preview probe (live Linux providers only)",async(t)=>{let s=n.unsupported?.previews??n.unsupported?.httpProbe;if(s){t.skip(s);return}let{box:o}=await d(),i=await o.start(`node -e 'require("http").createServer((_,r)=>r.end("ok")).listen(3000,"0.0.0.0")'`,{name:"http",ready:{http:{port:3000}}});a(i.ready).toBe(!0),a((await o.preview(3000,{waitMs:2000})).url).toBeTruthy(),await i.stop()})})}function N(m){let n=[],f=m.snapshot;if(f)m.snapshot=(u,h)=>(n.push(h),f.call(m,u,h));return n}export{z as runConformance};
|
package/dist/tool-security.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Redactor } from "./errors.js";
|
|
2
|
-
import type { OutputChunk } from "./types.js";
|
|
3
|
-
export declare function registerToolRedactor(box:
|
|
4
|
-
export declare function redactToolText(box:
|
|
2
|
+
import type { OutputChunk, SandboxBase } from "./types.js";
|
|
3
|
+
export declare function registerToolRedactor(box: SandboxBase<unknown>, redactor: Redactor): void;
|
|
4
|
+
export declare function redactToolText(box: SandboxBase<unknown>, text: string): string;
|
|
5
5
|
/** ANSI sequences and secrets can both cross transport boundaries. Normalize before redacting. */
|
|
6
|
-
export declare function toolOutputFilter(box:
|
|
6
|
+
export declare function toolOutputFilter(box: SandboxBase<unknown>, emit: (chunk: OutputChunk) => void): {
|
|
7
7
|
push(chunk: OutputChunk): undefined;
|
|
8
8
|
flush(): void;
|
|
9
9
|
};
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { Sandbox, OutputChunk } from "./types.js";
|
|
3
|
+
import type { JsonValue } from "./shared/json.js";
|
|
3
4
|
export declare const toolSchemas: {
|
|
4
5
|
run: z.ZodObject<{
|
|
5
6
|
command: z.ZodString;
|
|
@@ -75,7 +76,7 @@ export interface ToolResult {
|
|
|
75
76
|
text: string;
|
|
76
77
|
}
|
|
77
78
|
export declare function createSandboxTools(box: Sandbox, options?: SandboxToolsOptions): {
|
|
78
|
-
name: "
|
|
79
|
+
name: "search" | "changes" | "run" | "read_file" | "write_file" | "edit_file" | "start_process" | "process_logs" | "stop_process" | "list_files" | "preview";
|
|
79
80
|
description: string;
|
|
80
81
|
inputSchema: z.ZodObject<{
|
|
81
82
|
command: z.ZodString;
|
|
@@ -113,5 +114,5 @@ export declare function createSandboxTools(box: Sandbox, options?: SandboxToolsO
|
|
|
113
114
|
port: z.ZodNumber;
|
|
114
115
|
path: z.ZodOptional<z.ZodString>;
|
|
115
116
|
}, z.core.$strict>;
|
|
116
|
-
execute(input:
|
|
117
|
+
execute(input: JsonValue, emit?: ((event: ToolEvent) => void) | undefined, signal?: AbortSignal): Promise<ToolResult>;
|
|
117
118
|
}[];
|
package/dist/tools.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{P,M}from"./chunk-nw845a93.js";import"./chunk-ckym4cht.js";import"./chunk-23tjmd39.js";export{M as createSandboxTools,P as toolSchemas};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Capability, CreateInput, FileInfo, Labels, OutputChunk, Provider, SandboxInfo, Terminal, Preview } from "./provider.js";
|
|
1
|
+
import type { Capability, CreateInput, FileInfo, Labels, OutputChunk, Provider, SandboxInfo, Terminal, Preview, SnapshotOptions } from "./provider.js";
|
|
2
2
|
import type { Files } from "./files.js";
|
|
3
3
|
import type { Git } from "./git.js";
|
|
4
4
|
import type { ProcessHandle, ProcessInfo, StartOptions } from "./processes.js";
|
|
@@ -27,7 +27,15 @@ export interface CreateOptions extends Omit<CreateInput, "labels"> {
|
|
|
27
27
|
trackChanges?: boolean;
|
|
28
28
|
}
|
|
29
29
|
/** Options for `connectSandbox`. */
|
|
30
|
-
export
|
|
30
|
+
export interface ConnectOptions extends Pick<CreateOptions, "secrets"> {
|
|
31
|
+
/**
|
|
32
|
+
* Read back the secrets recorded at creation so they stay in the environment and redacted. It costs one
|
|
33
|
+
* command, run before the first `run`, `start`, `process`, `files`, or `terminal` call, never on connect.
|
|
34
|
+
* `destroy`, `close`, `pause`, `resume`, `snapshot`, and `usage` never need it. Pass `false` to skip it,
|
|
35
|
+
* for example when the handle only inspects or cleans up a sandbox. Default: `true`.
|
|
36
|
+
*/
|
|
37
|
+
recoverSecrets?: boolean;
|
|
38
|
+
}
|
|
31
39
|
/** Options for `listSandboxes`. */
|
|
32
40
|
export interface ListOptions {
|
|
33
41
|
/** Only return sandboxes that carry every one of these labels. */
|
|
@@ -79,11 +87,11 @@ export interface RunResult {
|
|
|
79
87
|
command: string;
|
|
80
88
|
}
|
|
81
89
|
/**
|
|
82
|
-
* A lazy command. Nothing runs until you `await` it
|
|
83
|
-
* or iterate it with `for await` (for live {@link OutputChunk}s).
|
|
90
|
+
* A lazy command. Nothing runs until you `await` it, call `then`, `catch` or `finally`
|
|
91
|
+
* (for the {@link RunResult}), or iterate it with `for await` (for live {@link OutputChunk}s).
|
|
84
92
|
* Chain `cwd`, `env`, or `timeout` before starting it.
|
|
85
93
|
*/
|
|
86
|
-
export interface RunHandle extends
|
|
94
|
+
export interface RunHandle extends Promise<RunResult>, AsyncIterable<OutputChunk> {
|
|
87
95
|
/** Run in this directory. */
|
|
88
96
|
cwd(path: string): RunHandle;
|
|
89
97
|
/** Add environment variables for this command. */
|
|
@@ -160,7 +168,7 @@ export interface CapabilityMethods {
|
|
|
160
168
|
};
|
|
161
169
|
snapshot: {
|
|
162
170
|
/** Save the sandbox state. Pass the returned `id` as `createSandbox(provider, { from: id })`. */
|
|
163
|
-
snapshot(): Promise<{
|
|
171
|
+
snapshot(options?: SnapshotOptions): Promise<{
|
|
164
172
|
id: string;
|
|
165
173
|
}>;
|
|
166
174
|
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencoredev/sandbox-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "One TypeScript API for cloud and local sandboxes: E2B, Daytona, Vercel, Upstash, Docker, and more. Run commands, edit files, start servers, and give AI agents a sandbox.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"sandbox",
|
|
7
|
-
"code-execution",
|
|
8
|
-
"ai-agents",
|
|
9
6
|
"agent-tools",
|
|
10
|
-
"
|
|
7
|
+
"ai-agents",
|
|
8
|
+
"ai-sdk",
|
|
9
|
+
"code-execution",
|
|
11
10
|
"daytona",
|
|
12
|
-
"vercel-sandbox",
|
|
13
|
-
"upstash",
|
|
14
11
|
"docker",
|
|
15
|
-
"
|
|
16
|
-
"ai-sdk",
|
|
12
|
+
"e2b",
|
|
17
13
|
"mastra",
|
|
14
|
+
"microvm",
|
|
18
15
|
"openai-agents",
|
|
19
|
-
"
|
|
16
|
+
"sandbox",
|
|
17
|
+
"typescript",
|
|
18
|
+
"upstash",
|
|
19
|
+
"vercel-sandbox"
|
|
20
20
|
],
|
|
21
21
|
"homepage": "https://sandbox-sdk.app",
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/opencoredev/sandbox-sdk/issues"
|
|
24
24
|
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "OpenCore",
|
|
25
27
|
"repository": {
|
|
26
28
|
"type": "git",
|
|
27
29
|
"url": "git+https://github.com/opencoredev/sandbox-sdk.git",
|
|
28
30
|
"directory": "packages/sdk"
|
|
29
31
|
},
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"author": "OpenCore",
|
|
32
|
-
"type": "module",
|
|
33
|
-
"sideEffects": false,
|
|
34
32
|
"files": [
|
|
35
33
|
"dist",
|
|
36
34
|
"README.md",
|
|
37
35
|
"LICENSE",
|
|
38
36
|
"CHANGELOG.md"
|
|
39
37
|
],
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"tag": "next"
|
|
43
|
-
},
|
|
38
|
+
"type": "module",
|
|
39
|
+
"sideEffects": false,
|
|
44
40
|
"exports": {
|
|
45
41
|
".": {
|
|
46
42
|
"types": "./dist/index.d.ts",
|
|
@@ -128,13 +124,19 @@
|
|
|
128
124
|
},
|
|
129
125
|
"./package.json": "./package.json"
|
|
130
126
|
},
|
|
127
|
+
"publishConfig": {
|
|
128
|
+
"access": "public"
|
|
129
|
+
},
|
|
131
130
|
"scripts": {
|
|
132
131
|
"build": "bun scripts/build.ts && tsc -p tsconfig.build.json",
|
|
132
|
+
"prepack": "bun run build",
|
|
133
133
|
"typecheck": "tsc --noEmit",
|
|
134
134
|
"lint": "oxlint src tests scripts",
|
|
135
135
|
"test": "timeout 120s vitest run --maxWorkers=4 && bun scripts/size.ts",
|
|
136
136
|
"check:size": "bun scripts/size.ts",
|
|
137
|
-
"smoke:consumer": "timeout 900s bun scripts/consumer-smoke.ts"
|
|
137
|
+
"smoke:consumer": "timeout 900s bun scripts/consumer-smoke.ts",
|
|
138
|
+
"smoke:consumer:nopeers": "timeout 900s bun scripts/consumer-smoke-nopeers.ts",
|
|
139
|
+
"smoke:bundle": "timeout 600s bun scripts/bundle-smoke.ts"
|
|
138
140
|
},
|
|
139
141
|
"devDependencies": {
|
|
140
142
|
"@boatdev/sdk": "1.9.9",
|
|
@@ -143,34 +145,30 @@
|
|
|
143
145
|
"@mastra/core": "^1.78.0",
|
|
144
146
|
"@openai/agents": "^0.20.0",
|
|
145
147
|
"@rivet-dev/agentos-core": "0.4.1",
|
|
148
|
+
"@superserve/sdk": "0.11.4",
|
|
146
149
|
"@tenkicloud/sandbox": "^1.4.1",
|
|
147
150
|
"@upstash/box": "^0.7.9",
|
|
148
151
|
"@vercel/sandbox": "3.8.0",
|
|
149
152
|
"ai": "^7.0.143",
|
|
150
153
|
"e2b": "2.56.0",
|
|
154
|
+
"esbuild": "0.28.1",
|
|
151
155
|
"freestyle": "0.2.20",
|
|
152
156
|
"railway": "3.16.0",
|
|
153
157
|
"vitest": "^3.2.4",
|
|
154
|
-
"zod": "^4.6.7"
|
|
155
|
-
"@superserve/sdk": "0.11.4"
|
|
158
|
+
"zod": "^4.6.7"
|
|
156
159
|
},
|
|
157
160
|
"peerDependencies": {
|
|
158
|
-
"@
|
|
161
|
+
"@boxd-sh/sdk": "^0.2.17",
|
|
159
162
|
"@mastra/core": "^1.78.0",
|
|
160
163
|
"@openai/agents": "^0.20.0",
|
|
164
|
+
"@rivet-dev/agentos-core": "0.4.1",
|
|
165
|
+
"@tenkicloud/sandbox": "^1.4.1",
|
|
161
166
|
"@upstash/box": "^0.7.9",
|
|
162
167
|
"@vercel/sandbox": "^3.8.0",
|
|
163
168
|
"ai": "^7.0.143",
|
|
164
|
-
"e2b": "^2.56.0",
|
|
165
|
-
"vitest": ">=3",
|
|
166
|
-
"zod": "^4.6.7",
|
|
167
169
|
"railway": "^3.16.0",
|
|
168
|
-
"
|
|
169
|
-
"
|
|
170
|
-
"@rivet-dev/agentos-core": "0.4.1",
|
|
171
|
-
"@boxd-sh/sdk": "^0.2.17",
|
|
172
|
-
"freestyle": "^0.2.20",
|
|
173
|
-
"@superserve/sdk": "^0.11.4"
|
|
170
|
+
"vitest": ">=3",
|
|
171
|
+
"zod": "^4.6.7"
|
|
174
172
|
},
|
|
175
173
|
"peerDependenciesMeta": {
|
|
176
174
|
"vitest": {
|
|
@@ -188,24 +186,15 @@
|
|
|
188
186
|
"zod": {
|
|
189
187
|
"optional": true
|
|
190
188
|
},
|
|
191
|
-
"e2b": {
|
|
192
|
-
"optional": true
|
|
193
|
-
},
|
|
194
189
|
"@vercel/sandbox": {
|
|
195
190
|
"optional": true
|
|
196
191
|
},
|
|
197
|
-
"@daytonaio/sdk": {
|
|
198
|
-
"optional": true
|
|
199
|
-
},
|
|
200
192
|
"@upstash/box": {
|
|
201
193
|
"optional": true
|
|
202
194
|
},
|
|
203
195
|
"railway": {
|
|
204
196
|
"optional": true
|
|
205
197
|
},
|
|
206
|
-
"@boatdev/sdk": {
|
|
207
|
-
"optional": true
|
|
208
|
-
},
|
|
209
198
|
"@tenkicloud/sandbox": {
|
|
210
199
|
"optional": true
|
|
211
200
|
},
|
|
@@ -214,12 +203,6 @@
|
|
|
214
203
|
},
|
|
215
204
|
"@boxd-sh/sdk": {
|
|
216
205
|
"optional": true
|
|
217
|
-
},
|
|
218
|
-
"freestyle": {
|
|
219
|
-
"optional": true
|
|
220
|
-
},
|
|
221
|
-
"@superserve/sdk": {
|
|
222
|
-
"optional": true
|
|
223
206
|
}
|
|
224
207
|
},
|
|
225
208
|
"engines": {
|
package/dist/chunk-59t3rqja.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{e,l,r}from"./chunk-gc8zdxyb.js";var h=new WeakMap,O=(n,t)=>h.get(n)?.get(t);function M(n,t,a){let i=h.get(n);if(!i)i=new Map,h.set(n,i);if(i.delete(t),i.set(t,a),i.size>256){let o=i.keys().next().value;if(o!==void 0)i.delete(o)}}function L(n,t){h.get(n)?.delete(t)}function v(n,t){let a=h.get(n);if(!a)return;for(let[i,o]of a)if(o===t)a.delete(i)}function T(n,t){return n.capabilities.has(t)}var _={"sandbox-sdk":"1"},R=new WeakMap;function j(n,t){for(let a of Object.keys({...t.env,...t.secrets}))if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(a))r("Invalid environment variable name");for(let a of n.capabilities)if(a==="pause"&&(!n.pause||!n.resume)||a==="snapshot"&&!n.snapshot||a==="terminal"&&!n.terminal)throw new e("Invalid adapter capabilities. A declared method is missing. Fix the adapter contract.",{code:"provider"});if(t.size!==void 0&&!n.capabilities.has("size"))throw new e("Creation refused. Provider cannot enforce size. Choose a provider with size support.",{code:"unsupported"});if(t.network!==void 0&&t.network!=="all"&&!n.capabilities.has("network-policy"))throw new e("Creation refused. Provider cannot enforce network policy. Choose a provider with network-policy support.",{code:"unsupported"});if(t.from!==void 0&&!n.capabilities.has("snapshot"))throw new e("Creation refused. Provider cannot restore snapshots. Choose a provider with snapshot support.",{code:"unsupported"});if(t.keyMode==="exact"&&n.keyMode!=="exact"&&!t.locator?.withLock)throw new e("Exact key mode unavailable. Two-function locator storage cannot enforce distributed uniqueness. Supply locator.withLock or use an exact provider.",{code:"unsupported"});for(let a of t.ports??[])if(!Number.isInteger(a)||a<1||a>65535)r("Invalid port");for(let a of[t.timeoutMs,t.idleTimeoutMs])if(a!==void 0&&(!Number.isFinite(a)||a<=0))r("Timeouts must be positive milliseconds")}async function p(n,t={}){let a=new l;a.add(Object.values(t.secrets??{}));async function i(){let u;try{if(j(n,t),t.signal?.aborted)throw new e("Creation aborted. Signal was already aborted. Retry with a fresh signal.",{code:"aborted"});let c;if(t.key){let x=await t.locator?.get(t.key)??O(n,t.key);if(x)try{c=await n.connect(x)}catch(k){if(!(k instanceof e)||k.code!=="not_found")throw k;L(n,t.key)}c??=await n.find(t.key)}let m=!c;if(!c){let{secrets:x,locator:k,keyMode:A,trackChanges:H,...F}=t,C=n.create({...F,env:{...t.env,...x},labels:{...t.labels,..._}}).catch(async(b)=>{if(t.key&&n.keyMode==="exact"&&!t.signal?.aborted){let w=await n.find(t.key);if(w)return m=!1,w}throw b});if(t.signal){let b=t.signal,w=()=>{},K=new Promise((P,z)=>{if(w=()=>z(new e("Creation aborted. The signal was cancelled. Any late sandbox will be destroyed.",{code:"aborted"})),b.addEventListener("abort",w,{once:!0}),b.aborted)w()}),B=C.then(async(P)=>{if(b.aborted){if(m)await n.destroy(P.id);throw new e("Creation aborted. Late sandbox destroyed. Retry with a fresh signal.",{code:"aborted"})}return P});try{c=await Promise.race([B,K])}finally{b.removeEventListener("abort",w)}}else c=await C;if(m)u=c}if(t.signal?.aborted){if(u)await n.destroy(u.id);throw u=void 0,new e("Creation aborted. Sandbox arrived after cancellation and was destroyed. Retry with a fresh signal.",{code:"aborted"})}if(t.key)await t.locator?.set(t.key,c.id),M(n,t.key,c.id);let{makeHandle:I}=await import("./chunk-hjzhc3qg.js");return await I(n,c,m,t,a)}catch(c){if(u)v(n,u.id),await n.destroy(u.id).catch(()=>{});throw a.error(c,n.name)}}if(!t.key)return i();let o=R.get(n);if(!o)o=new Map,R.set(n,o);let s=o.get(t.key)??Promise.resolve(),{key:f,locator:y}=t,d=s.catch(()=>{}).then(()=>t.keyMode==="exact"&&n.keyMode==="best-effort"&&y?.withLock?y.withLock(f,i):i());o.set(t.key,d);try{return await d}finally{if(o.get(t.key)===d)o.delete(t.key)}}async function g(n,t,a={}){let i=new l;i.add(Object.values(a.secrets??{}));try{j(n,a);let o=await n.connect(t),{makeHandle:s}=await import("./chunk-hjzhc3qg.js");return await s(n,o,!1,{...a,key:o.key},i)}catch(o){throw i.error(o,n.name,t)}}async function S(n,t={}){try{return(await n.list({...t.labels,..._})).filter((a)=>a.labels["sandbox-sdk"]==="1")}catch(a){throw new l().error(a,n.name)}}async function E(n,t={}){if(t.olderThanMs!==void 0&&(!Number.isFinite(t.olderThanMs)||t.olderThanMs<0))r("olderThanMs must be non-negative");let a=t.idleOnly?(await import("./chunk-md6fmprc.js")).isRunActive:()=>!1,i=0;try{for(let o of await S(n,t))if(Date.now()-o.createdAt>=(t.olderThanMs??0)){if(t.idleOnly){if(a(n.name,o.id))continue;let s;try{let f=await n.connect(o.id),{makeHandle:y}=await import("./chunk-hjzhc3qg.js");s=await y(n,f,!1,{},new l,!1)}catch(f){if(f instanceof e&&f.code==="not_found"){i++;continue}throw f}try{let[f,y]=await Promise.all([s.processes(),s.files.list("/tmp/.sandbox-sdk/runs").catch(async(d)=>{if(d instanceof e&&(["file_not_found","not_found"].includes(d.code)||d.code==="provider"&&!await s.files.exists("/tmp/.sandbox-sdk/runs")))return[];throw d})]);if(f.some((d)=>d.status==="running"||d.status==="starting")||y.length>0)continue}finally{await s.close()}}if(a(n.name,o.id))continue;v(n,o.id);try{await n.destroy(o.id)}catch(s){if(!(s instanceof e)||s.code!=="not_found")throw s}i++}return i}catch(o){throw new l().error(o,n.name)}}
|
|
2
|
-
export{v,T,p,g,S,E};
|
package/dist/chunk-cwx6cc31.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{f}from"./chunk-t5vr9nd8.js";import{stripVTControlCharacters as u}from"node:util";var i=new WeakMap;function C(s,r){i.set(s,r)}function p(s){let r=i.get(s);if(!r)throw Error("Unknown sandbox handle. Secret redaction cannot be guaranteed. Use createSandbox or connectSandbox.");return r}function _(s,r){return p(s).text(u(r))}function P(s,r){let n={stdout:"plain",stderr:"plain"},c=f(p(s),r,!0);return{push(a){let t=n[a.stream],o="";for(let e of a.text)switch(t){case"plain":if(e==="\x1B")t="escape";else if(e==="")t="csi";else if("".includes(e))t="string";else o+=e;break;case"escape":t=e==="["?"csi":"]PX^_".includes(e)?"string":e>=" "&&e<="/"?"escape":"plain";break;case"csi":if(e>="@"&&e<="~")t="plain";break;case"string":if(e==="\x07"||e==="")t="plain";else if(e==="\x1B")t="string_escape";break;case"string_escape":t=e==="\\"?"plain":"string";break;default:return t}if(n[a.stream]=t,o)c.push({stream:a.stream,text:o})},flush(){c.flush()}}}
|
|
2
|
-
export{C,_,P};
|
package/dist/chunk-exv1kf89.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import{e}from"./chunk-gc8zdxyb.js";var a=(o)=>`'${o.replaceAll("'","'\\''")}'`,n=(o,...s)=>`python3 -c ${a(o)} ${s.map(a).join(" ")}`,d=`def stdin_file():
|
|
2
|
-
try: return os.fdopen(os.memfd_create('sandbox-sdk-stdin'),'w+b')
|
|
3
|
-
except (AttributeError,OSError):
|
|
4
|
-
import tempfile
|
|
5
|
-
return tempfile.TemporaryFile()
|
|
6
|
-
class Process:
|
|
7
|
-
def __init__(self,v,env,stdin,session=False):
|
|
8
|
-
if not all(hasattr(os,name) for name in ['posix_spawn','waitstatus_to_exitcode']):
|
|
9
|
-
self.legacy(v,env,stdin,session); return
|
|
10
|
-
directory=os.open('.',os.O_RDONLY)
|
|
11
|
-
r,w=os.pipe(); e,x=os.pipe()
|
|
12
|
-
try:
|
|
13
|
-
os.chdir(v['cwd'])
|
|
14
|
-
error=FileNotFoundError(2,os.strerror(2),'sh')
|
|
15
|
-
signals=[getattr(signal,s) for s in ['SIGPIPE','SIGXFZ','SIGXFSZ'] if hasattr(signal,s)]
|
|
16
|
-
for path in os.get_exec_path(env):
|
|
17
|
-
try:
|
|
18
|
-
self.pid=os.posix_spawn(os.path.join(path,'sh'),['sh','-c',v['command']],env,file_actions=[(os.POSIX_SPAWN_DUP2,stdin.fileno(),0),(os.POSIX_SPAWN_DUP2,w,1),(os.POSIX_SPAWN_DUP2,x,2)],setsid=session,setsigdef=signals)
|
|
19
|
-
break
|
|
20
|
-
except (FileNotFoundError,NotADirectoryError): pass
|
|
21
|
-
except OSError as failure:
|
|
22
|
-
if failure.errno==38: raise NotImplementedError()
|
|
23
|
-
error=failure
|
|
24
|
-
else: raise error
|
|
25
|
-
except NotImplementedError:
|
|
26
|
-
os.close(r); os.close(e)
|
|
27
|
-
self.legacy(v,env,stdin,session); return
|
|
28
|
-
except BaseException:
|
|
29
|
-
os.close(r); os.close(e); raise
|
|
30
|
-
finally:
|
|
31
|
-
os.fchdir(directory); os.close(directory); os.close(w); os.close(x)
|
|
32
|
-
self.stdout=os.fdopen(r,'rb',buffering=0); self.stderr=os.fdopen(e,'rb',buffering=0)
|
|
33
|
-
self.code=None
|
|
34
|
-
def legacy(self,v,env,stdin,session):
|
|
35
|
-
import subprocess
|
|
36
|
-
self.child=subprocess.Popen(['sh','-c',v['command']],cwd=v['cwd'],env=env,stdin=stdin,stdout=subprocess.PIPE,stderr=subprocess.PIPE,start_new_session=session)
|
|
37
|
-
self.pid=self.child.pid; self.stdout=self.child.stdout; self.stderr=self.child.stderr
|
|
38
|
-
def poll(self):
|
|
39
|
-
if hasattr(self,'child'): return self.child.poll()
|
|
40
|
-
if self.code is None:
|
|
41
|
-
pid,status=os.waitpid(self.pid,os.WNOHANG)
|
|
42
|
-
if pid: self.code=os.waitstatus_to_exitcode(status)
|
|
43
|
-
return self.code
|
|
44
|
-
def wait(self):
|
|
45
|
-
if hasattr(self,'child'): return self.child.wait()
|
|
46
|
-
if self.code is None: self.code=os.waitstatus_to_exitcode(os.waitpid(self.pid,0)[1])
|
|
47
|
-
return self.code
|
|
48
|
-
`,c=(o,s,f="provider")=>new e(`${s}. Check the ${o.name} sandbox before retrying.`,{code:f,provider:o.name}),y=`import os,sys,json,stat
|
|
49
|
-
p=sys.argv[1]
|
|
50
|
-
def info(p):
|
|
51
|
-
s=os.lstat(p)
|
|
52
|
-
return dict(path=p,type='symlink' if stat.S_ISLNK(s.st_mode) else 'directory' if stat.S_ISDIR(s.st_mode) else 'file',size=s.st_size,modifiedAt=s.st_mtime*1000)
|
|
53
|
-
try: print(json.dumps([info(os.path.join(p,n)) for n in os.listdir(p)] if sys.argv[2]=='list' else info(p)))
|
|
54
|
-
except FileNotFoundError: print('SDK_FILE_NOT_FOUND')`;function u(o,s){if(!s||typeof s!=="object"||!("path"in s)||typeof s.path!=="string"||!("type"in s)||s.type!=="file"&&s.type!=="directory"&&s.type!=="symlink"||!("size"in s)||typeof s.size!=="number"||!("modifiedAt"in s)||typeof s.modifiedAt!=="number")throw c(o,"Invalid file metadata");return{path:s.path,type:s.type,size:s.size,modifiedAt:s.modifiedAt}}function h(o,s){let f=async(t,r,i)=>{let l=await o(t),p=await l.raw(n(y,r,i));if(p.trim()==="SDK_FILE_NOT_FOUND")throw c(l,"File does not exist","file_not_found");let m=JSON.parse(p);return{g:l,value:m}};return{writeCreatesParents:!0,readRange:(t,r,i)=>s(t,async()=>(await o(t)).read(r,i)),read:(t,r)=>s(t,async()=>(await o(t)).read(r)),write:(t,r,i)=>s(t,async()=>{let l=await o(t);try{await s(t,()=>l.upload(r,i))}catch(p){if(!(p instanceof e)||!["not_found","file_not_found"].includes(p.code))throw p;await l.raw(n("import os,sys; os.makedirs(os.path.dirname(sys.argv[1]),exist_ok=True)",r)),await l.upload(r,i)}}),stat:(t,r)=>s(t,async()=>{let{g:i,value:l}=await f(t,r,"stat");return u(i,l)}),list:(t,r)=>s(t,async()=>{let{g:i,value:l}=await f(t,r,"list");if(!Array.isArray(l))throw c(i,"Invalid directory listing");return l.map((p)=>u(i,p))}),mkdir:(t,r)=>s(t,async()=>{await(await o(t)).raw(n("import os,sys; os.makedirs(sys.argv[1],exist_ok=True)",r))}),remove:(t,r,i)=>s(t,async()=>{await(await o(t)).raw(n(`import os,sys,shutil
|
|
55
|
-
p=sys.argv[1]
|
|
56
|
-
if os.path.isdir(p) and not os.path.islink(p):
|
|
57
|
-
if sys.argv[2]=='true': shutil.rmtree(p)
|
|
58
|
-
else: os.rmdir(p)
|
|
59
|
-
else: os.unlink(p)`,r,String(i.recursive)))})}}
|
|
60
|
-
export{a,n,d,h};
|