@anvia/sandbox 0.3.7 → 0.4.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/dist/index.d.ts +75 -3
- package/dist/index.js +918 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -31,12 +31,27 @@ interface SandboxSession {
|
|
|
31
31
|
listFiles(path?: string): Promise<SandboxFileEntry[]>;
|
|
32
32
|
destroy(): Promise<void>;
|
|
33
33
|
}
|
|
34
|
+
interface SandboxPortSession extends SandboxSession {
|
|
35
|
+
readonly publishedPorts: readonly SandboxPublishedPort[];
|
|
36
|
+
waitForPort(containerPort: number, options?: SandboxWaitForPortOptions): Promise<SandboxPublishedPort>;
|
|
37
|
+
}
|
|
38
|
+
interface SandboxProcessSession extends SandboxSession {
|
|
39
|
+
startProcess(options: SandboxProcessStartOptions): Promise<SandboxProcessInfo>;
|
|
40
|
+
listProcesses(): Promise<SandboxProcessInfo[]>;
|
|
41
|
+
readProcessLogs(processId: string, options?: SandboxProcessLogsOptions): Promise<SandboxProcessLogs>;
|
|
42
|
+
stopProcess(processId: string, options?: SandboxProcessStopOptions): Promise<SandboxProcessInfo>;
|
|
43
|
+
}
|
|
44
|
+
interface DockerSandboxSession extends SandboxPortSession, SandboxProcessSession {
|
|
45
|
+
}
|
|
34
46
|
interface SandboxCreateSessionOptions {
|
|
35
47
|
id?: string;
|
|
36
48
|
workspace?: SandboxWorkspaceOptions;
|
|
37
49
|
manifest?: SandboxManifest;
|
|
38
50
|
metadata?: Record<string, string>;
|
|
39
51
|
}
|
|
52
|
+
interface DockerSandboxCreateSessionOptions extends SandboxCreateSessionOptions {
|
|
53
|
+
ports?: readonly number[];
|
|
54
|
+
}
|
|
40
55
|
interface SandboxManifest {
|
|
41
56
|
files?: Record<string, string | Uint8Array>;
|
|
42
57
|
directories?: string[];
|
|
@@ -49,6 +64,7 @@ interface SandboxLimits {
|
|
|
49
64
|
memoryMb?: number;
|
|
50
65
|
cpus?: number;
|
|
51
66
|
pidsLimit?: number;
|
|
67
|
+
maxProcesses?: number;
|
|
52
68
|
}
|
|
53
69
|
interface SandboxExecOptions {
|
|
54
70
|
command: string;
|
|
@@ -88,6 +104,46 @@ interface SandboxFileEntry {
|
|
|
88
104
|
type: SandboxFileType;
|
|
89
105
|
size?: number;
|
|
90
106
|
}
|
|
107
|
+
interface SandboxPublishedPort {
|
|
108
|
+
containerPort: number;
|
|
109
|
+
host: "127.0.0.1";
|
|
110
|
+
hostPort: number;
|
|
111
|
+
protocol: "tcp";
|
|
112
|
+
}
|
|
113
|
+
interface SandboxWaitForPortOptions {
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
intervalMs?: number;
|
|
116
|
+
signal?: AbortSignal;
|
|
117
|
+
}
|
|
118
|
+
interface SandboxProcessStartOptions {
|
|
119
|
+
command: string;
|
|
120
|
+
args?: string[];
|
|
121
|
+
cwd?: string;
|
|
122
|
+
env?: Record<string, string>;
|
|
123
|
+
}
|
|
124
|
+
type SandboxProcessStatus = "running" | "exited" | "stopped";
|
|
125
|
+
interface SandboxProcessInfo {
|
|
126
|
+
id: string;
|
|
127
|
+
command: string;
|
|
128
|
+
args: string[];
|
|
129
|
+
cwd?: string;
|
|
130
|
+
status: SandboxProcessStatus;
|
|
131
|
+
exitCode?: number;
|
|
132
|
+
startedAt: string;
|
|
133
|
+
endedAt?: string;
|
|
134
|
+
}
|
|
135
|
+
interface SandboxProcessLogsOptions {
|
|
136
|
+
tailBytes?: number;
|
|
137
|
+
}
|
|
138
|
+
interface SandboxProcessLogs {
|
|
139
|
+
stdout: string;
|
|
140
|
+
stderr: string;
|
|
141
|
+
stdoutTruncated: boolean;
|
|
142
|
+
stderrTruncated: boolean;
|
|
143
|
+
}
|
|
144
|
+
interface SandboxProcessStopOptions {
|
|
145
|
+
gracePeriodMs?: number;
|
|
146
|
+
}
|
|
91
147
|
interface DockerSandboxSecurityOptions {
|
|
92
148
|
readonlyRootfs?: boolean;
|
|
93
149
|
noNewPrivileges?: boolean;
|
|
@@ -141,8 +197,9 @@ interface SandboxToolsOptions {
|
|
|
141
197
|
exec?: SandboxExecToolPolicy;
|
|
142
198
|
readFile?: SandboxFileToolPolicy;
|
|
143
199
|
writeFile?: SandboxFileToolPolicy;
|
|
200
|
+
process?: SandboxProcessToolPolicy;
|
|
144
201
|
}
|
|
145
|
-
type SandboxToolName = "exec_command" | "read_file" | "write_file" | "list_files";
|
|
202
|
+
type SandboxToolName = "exec_command" | "read_file" | "write_file" | "list_files" | "list_ports" | "start_process" | "list_processes" | "read_process_logs" | "stop_process" | "wait_for_port";
|
|
146
203
|
interface SandboxExecToolPolicy {
|
|
147
204
|
allowedCommands?: string[];
|
|
148
205
|
blockedCommands?: string[];
|
|
@@ -152,8 +209,17 @@ interface SandboxExecToolPolicy {
|
|
|
152
209
|
interface SandboxFileToolPolicy {
|
|
153
210
|
maxBytes?: number;
|
|
154
211
|
}
|
|
212
|
+
interface SandboxProcessToolPolicy {
|
|
213
|
+
maxLogBytes?: number;
|
|
214
|
+
defaultWaitTimeoutMs?: number;
|
|
215
|
+
maxWaitTimeoutMs?: number;
|
|
216
|
+
stopGracePeriodMs?: number;
|
|
217
|
+
}
|
|
155
218
|
type SandboxToolsFactory = (session: SandboxSession, options?: SandboxToolsOptions) => AnyTool[];
|
|
156
219
|
|
|
220
|
+
declare function isSandboxPortSession(session: SandboxSession): session is SandboxPortSession;
|
|
221
|
+
declare function isSandboxProcessSession(session: SandboxSession): session is SandboxProcessSession;
|
|
222
|
+
|
|
157
223
|
declare class DockerSandbox implements Sandbox {
|
|
158
224
|
readonly provider = "docker";
|
|
159
225
|
private readonly image;
|
|
@@ -172,10 +238,12 @@ declare class DockerSandbox implements Sandbox {
|
|
|
172
238
|
static node(options?: DockerSandboxOptions): DockerSandbox;
|
|
173
239
|
static python(options?: DockerSandboxOptions): DockerSandbox;
|
|
174
240
|
static deno(options?: DockerSandboxOptions): DockerSandbox;
|
|
175
|
-
createSession(options?:
|
|
241
|
+
createSession(options?: DockerSandboxCreateSessionOptions): Promise<DockerSandboxSession>;
|
|
176
242
|
private ensureImage;
|
|
177
243
|
private createRunArgs;
|
|
178
244
|
private appendNetworkArgs;
|
|
245
|
+
private assertPortNetworkCompatible;
|
|
246
|
+
private inspectPublishedPorts;
|
|
179
247
|
private appendLimitArgs;
|
|
180
248
|
private appendSecurityArgs;
|
|
181
249
|
private cliOptions;
|
|
@@ -210,7 +278,11 @@ declare class SandboxFileSizeError extends SandboxError {
|
|
|
210
278
|
}
|
|
211
279
|
declare class SandboxToolPolicyError extends SandboxError {
|
|
212
280
|
}
|
|
281
|
+
declare class SandboxPortError extends SandboxError {
|
|
282
|
+
}
|
|
283
|
+
declare class SandboxProcessError extends SandboxError {
|
|
284
|
+
}
|
|
213
285
|
|
|
214
286
|
declare function createSandboxTools(session: SandboxSession, options?: SandboxToolsOptions): AnyTool[];
|
|
215
287
|
|
|
216
|
-
export { DockerSandbox, type DockerSandboxNetworkOptions, type DockerSandboxOptions, type DockerSandboxSecurityOptions, type Sandbox, type SandboxCreateSessionOptions, SandboxDockerCommandError, SandboxDockerUnavailableError, SandboxError, type SandboxExecEndEvent, type SandboxExecEvent, type SandboxExecOptions, type SandboxExecResult, type SandboxExecStreamEvent, type SandboxExecToolPolicy, type SandboxFileEntry, SandboxFileSizeError, type SandboxFileToolPolicy, type SandboxFileType, type SandboxFileWriteEvent, type SandboxHooks, type SandboxLifecycleOptions, type SandboxLimits, type SandboxManifest, type SandboxNetworkMode, SandboxPathError, type SandboxSession, SandboxSessionDestroyedError, type SandboxSessionEvent, SandboxTimeoutError, type SandboxToolName, SandboxToolPolicyError, type SandboxToolsFactory, type SandboxToolsOptions, type SandboxWorkspaceOptions, createSandboxTools };
|
|
288
|
+
export { DockerSandbox, type DockerSandboxCreateSessionOptions, type DockerSandboxNetworkOptions, type DockerSandboxOptions, type DockerSandboxSecurityOptions, type DockerSandboxSession, type Sandbox, type SandboxCreateSessionOptions, SandboxDockerCommandError, SandboxDockerUnavailableError, SandboxError, type SandboxExecEndEvent, type SandboxExecEvent, type SandboxExecOptions, type SandboxExecResult, type SandboxExecStreamEvent, type SandboxExecToolPolicy, type SandboxFileEntry, SandboxFileSizeError, type SandboxFileToolPolicy, type SandboxFileType, type SandboxFileWriteEvent, type SandboxHooks, type SandboxLifecycleOptions, type SandboxLimits, type SandboxManifest, type SandboxNetworkMode, SandboxPathError, SandboxPortError, type SandboxPortSession, SandboxProcessError, type SandboxProcessInfo, type SandboxProcessLogs, type SandboxProcessLogsOptions, type SandboxProcessSession, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStopOptions, type SandboxProcessToolPolicy, type SandboxPublishedPort, type SandboxSession, SandboxSessionDestroyedError, type SandboxSessionEvent, SandboxTimeoutError, type SandboxToolName, SandboxToolPolicyError, type SandboxToolsFactory, type SandboxToolsOptions, type SandboxWaitForPortOptions, type SandboxWorkspaceOptions, createSandboxTools, isSandboxPortSession, isSandboxProcessSession };
|