@agentuity/sandbox 3.0.12 → 3.1.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/AGENTS.md +3 -3
- package/dist/api-reference.d.ts +1221 -0
- package/dist/api-reference.d.ts.map +1 -0
- package/dist/api-reference.js +1046 -0
- package/dist/api-reference.js.map +1 -0
- package/dist/base64.d.ts +2 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +14 -0
- package/dist/base64.js.map +1 -0
- package/dist/client.d.ts +431 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +632 -0
- package/dist/client.js.map +1 -0
- package/dist/create.d.ts +203 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +235 -0
- package/dist/create.js.map +1 -0
- package/dist/destroy.d.ts +23 -0
- package/dist/destroy.d.ts.map +1 -0
- package/dist/destroy.js +30 -0
- package/dist/destroy.js.map +1 -0
- package/dist/disk-checkpoint.d.ts +108 -0
- package/dist/disk-checkpoint.d.ts.map +1 -0
- package/dist/disk-checkpoint.js +124 -0
- package/dist/disk-checkpoint.js.map +1 -0
- package/dist/events.d.ts +56 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +54 -0
- package/dist/events.js.map +1 -0
- package/dist/execute.d.ts +99 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +138 -0
- package/dist/execute.js.map +1 -0
- package/dist/execution.d.ts +150 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +120 -0
- package/dist/execution.js.map +1 -0
- package/dist/files.d.ts +283 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +471 -0
- package/dist/files.js.map +1 -0
- package/dist/get.d.ts +288 -0
- package/dist/get.d.ts.map +1 -0
- package/dist/get.js +256 -0
- package/dist/get.js.map +1 -0
- package/dist/getStatus.d.ts +23 -0
- package/dist/getStatus.d.ts.map +1 -0
- package/dist/getStatus.js +53 -0
- package/dist/getStatus.js.map +1 -0
- package/dist/index.d.ts +42 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/job.d.ts +227 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +109 -0
- package/dist/job.js.map +1 -0
- package/dist/list.d.ts +330 -0
- package/dist/list.d.ts.map +1 -0
- package/dist/list.js +209 -0
- package/dist/list.js.map +1 -0
- package/dist/pause.d.ts +39 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +48 -0
- package/dist/pause.js.map +1 -0
- package/dist/resolve.d.ts +75 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +76 -0
- package/dist/resolve.js.map +1 -0
- package/dist/resume.d.ts +23 -0
- package/dist/resume.d.ts.map +1 -0
- package/dist/resume.js +30 -0
- package/dist/resume.js.map +1 -0
- package/dist/run.d.ts +73 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +568 -0
- package/dist/run.js.map +1 -0
- package/dist/runtime.d.ts +94 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +82 -0
- package/dist/runtime.js.map +1 -0
- package/dist/snapshot-build.d.ts +48 -0
- package/dist/snapshot-build.d.ts.map +1 -0
- package/dist/snapshot-build.js +72 -0
- package/dist/snapshot-build.js.map +1 -0
- package/dist/snapshot.d.ts +596 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +612 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/types.d.ts +1010 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +853 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +296 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +234 -0
- package/dist/util.js.map +1 -0
- package/package.json +7 -2
- package/src/api-reference.ts +1094 -0
- package/src/base64.ts +14 -0
- package/src/client.ts +998 -0
- package/src/create.ts +273 -0
- package/src/destroy.ts +43 -0
- package/src/disk-checkpoint.ts +184 -0
- package/src/events.ts +72 -0
- package/src/execute.ts +167 -0
- package/src/execution.ts +152 -0
- package/src/files.ts +637 -0
- package/src/get.ts +291 -0
- package/src/getStatus.ts +72 -0
- package/src/index.ts +252 -18
- package/src/job.ts +161 -0
- package/src/list.ts +239 -0
- package/src/pause.ts +75 -0
- package/src/resolve.ts +96 -0
- package/src/resume.ts +41 -0
- package/src/run.ts +783 -0
- package/src/runtime.ts +106 -0
- package/src/snapshot-build.ts +94 -0
- package/src/snapshot.ts +791 -0
- package/src/types.ts +1033 -0
- package/src/util.ts +280 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,1033 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { StructuredError } from '@agentuity/core';
|
|
3
|
+
import { SortDirectionSchema } from '@agentuity/client';
|
|
4
|
+
import type { SandboxPauseResult } from './pause.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resource limits for a sandbox using Kubernetes-style units
|
|
8
|
+
*/
|
|
9
|
+
export const SandboxResourcesSchema = z.object({
|
|
10
|
+
/** Memory limit (e.g., "500Mi", "1Gi") */
|
|
11
|
+
memory: z.string().optional().describe('Memory limit (e.g., "500Mi", "1Gi")'),
|
|
12
|
+
/** CPU limit in millicores (e.g., "500m", "1000m") */
|
|
13
|
+
cpu: z.string().optional().describe('CPU limit in millicores (e.g., "500m", "1000m")'),
|
|
14
|
+
/** Disk limit (e.g., "500Mi", "1Gi") */
|
|
15
|
+
disk: z.string().optional().describe('Disk limit (e.g., "500Mi", "1Gi")'),
|
|
16
|
+
});
|
|
17
|
+
export type SandboxResources = z.infer<typeof SandboxResourcesSchema>;
|
|
18
|
+
|
|
19
|
+
/** Sandbox status */
|
|
20
|
+
export const SandboxStatusSchema = z.enum([
|
|
21
|
+
'creating',
|
|
22
|
+
'idle',
|
|
23
|
+
'running',
|
|
24
|
+
'paused',
|
|
25
|
+
'stopping',
|
|
26
|
+
'suspended',
|
|
27
|
+
'terminated',
|
|
28
|
+
'failed',
|
|
29
|
+
'deleted',
|
|
30
|
+
]);
|
|
31
|
+
export type SandboxStatus = z.infer<typeof SandboxStatusSchema>;
|
|
32
|
+
|
|
33
|
+
export const SandboxSortFieldSchema = z.enum([
|
|
34
|
+
'name',
|
|
35
|
+
'created',
|
|
36
|
+
'updated',
|
|
37
|
+
'status',
|
|
38
|
+
'mode',
|
|
39
|
+
'execution_count',
|
|
40
|
+
]);
|
|
41
|
+
export type SandboxSortField = z.infer<typeof SandboxSortFieldSchema>;
|
|
42
|
+
|
|
43
|
+
export const SnapshotSortFieldSchema = z.enum(['name', 'created', 'size', 'files']);
|
|
44
|
+
export type SnapshotSortField = z.infer<typeof SnapshotSortFieldSchema>;
|
|
45
|
+
|
|
46
|
+
export const RuntimeSortFieldSchema = z.enum(['name', 'created']);
|
|
47
|
+
export type RuntimeSortField = z.infer<typeof RuntimeSortFieldSchema>;
|
|
48
|
+
|
|
49
|
+
/** Runtime information for a sandbox */
|
|
50
|
+
export const SandboxRuntimeRequirementsSchema = z.object({
|
|
51
|
+
/** Memory requirement (e.g., "1Gi") */
|
|
52
|
+
memory: z.string().optional().describe('Memory requirement (e.g., "1Gi")'),
|
|
53
|
+
/** CPU requirement (e.g., "1") */
|
|
54
|
+
cpu: z.string().optional().describe('CPU requirement (e.g., "1")'),
|
|
55
|
+
/** Disk requirement (e.g., "500Mi") */
|
|
56
|
+
disk: z.string().optional().describe('Disk requirement (e.g., "500Mi")'),
|
|
57
|
+
/** Whether network access is enabled */
|
|
58
|
+
networkEnabled: z.boolean().describe('Whether network access is enabled'),
|
|
59
|
+
});
|
|
60
|
+
export type SandboxRuntimeRequirements = z.infer<typeof SandboxRuntimeRequirementsSchema>;
|
|
61
|
+
|
|
62
|
+
export const SandboxRuntimeSchema = z.object({
|
|
63
|
+
/** Unique runtime identifier */
|
|
64
|
+
id: z.string().describe('Unique runtime identifier'),
|
|
65
|
+
/** Runtime name (e.g., "bun:1", "python:3.14") */
|
|
66
|
+
name: z.string().describe('Runtime name (e.g., "bun:1", "python:3.14")'),
|
|
67
|
+
/** Optional description */
|
|
68
|
+
description: z.string().optional().describe('Optional description'),
|
|
69
|
+
/** URL for runtime icon */
|
|
70
|
+
iconUrl: z.string().optional().describe('URL for runtime icon'),
|
|
71
|
+
/** Brand color for the runtime (hex color code) */
|
|
72
|
+
brandColor: z.string().optional().describe('Brand color for the runtime (hex color code)'),
|
|
73
|
+
/** URL for runtime documentation or homepage */
|
|
74
|
+
url: z.string().optional().describe('URL for runtime documentation or homepage'),
|
|
75
|
+
/** Optional tags for categorization */
|
|
76
|
+
tags: z.array(z.string()).optional().describe('Optional tags for categorization'),
|
|
77
|
+
/** Runtime requirements (memory, cpu, disk, network) */
|
|
78
|
+
requirements: SandboxRuntimeRequirementsSchema.optional().describe(
|
|
79
|
+
'Runtime requirements (memory, cpu, disk, network)'
|
|
80
|
+
),
|
|
81
|
+
/** Readme content in markdown format */
|
|
82
|
+
readme: z.string().optional().describe('Readme content in markdown format'),
|
|
83
|
+
});
|
|
84
|
+
export type SandboxRuntime = z.infer<typeof SandboxRuntimeSchema>;
|
|
85
|
+
|
|
86
|
+
/** Runtime information included in sandbox responses */
|
|
87
|
+
export const SandboxRuntimeInfoSchema = z.object({
|
|
88
|
+
/** Unique runtime identifier */
|
|
89
|
+
id: z.string().describe('Unique runtime identifier'),
|
|
90
|
+
/** Runtime name (e.g., "bun:1", "python:3.14") */
|
|
91
|
+
name: z.string().describe('Runtime name (e.g., "bun:1", "python:3.14")'),
|
|
92
|
+
/** URL for runtime icon */
|
|
93
|
+
iconUrl: z.string().optional().describe('URL for runtime icon'),
|
|
94
|
+
/** Brand color for the runtime (hex color code) */
|
|
95
|
+
brandColor: z.string().optional().describe('Brand color for the runtime (hex color code)'),
|
|
96
|
+
/** Optional tags for categorization */
|
|
97
|
+
tags: z.array(z.string()).optional().describe('Optional tags for categorization'),
|
|
98
|
+
});
|
|
99
|
+
export type SandboxRuntimeInfo = z.infer<typeof SandboxRuntimeInfoSchema>;
|
|
100
|
+
|
|
101
|
+
/** Snapshot user information (for private snapshots) */
|
|
102
|
+
export const SandboxSnapshotUserInfoSchema = z.object({
|
|
103
|
+
/** User ID */
|
|
104
|
+
id: z.string().describe('User ID'),
|
|
105
|
+
/** User's first name */
|
|
106
|
+
firstName: z.string().optional().describe("User's first name"),
|
|
107
|
+
/** User's last name */
|
|
108
|
+
lastName: z.string().optional().describe("User's last name"),
|
|
109
|
+
});
|
|
110
|
+
export type SandboxSnapshotUserInfo = z.infer<typeof SandboxSnapshotUserInfoSchema>;
|
|
111
|
+
|
|
112
|
+
/** Snapshot org information (for public snapshots) */
|
|
113
|
+
export const SandboxSnapshotOrgInfoSchema = z.object({
|
|
114
|
+
/** Organization ID */
|
|
115
|
+
id: z.string().describe('Organization ID'),
|
|
116
|
+
/** Organization name */
|
|
117
|
+
name: z.string().describe('Organization name'),
|
|
118
|
+
/** Organization slug */
|
|
119
|
+
slug: z.string().optional().describe('Organization slug'),
|
|
120
|
+
});
|
|
121
|
+
export type SandboxSnapshotOrgInfo = z.infer<typeof SandboxSnapshotOrgInfoSchema>;
|
|
122
|
+
|
|
123
|
+
/** Base snapshot information */
|
|
124
|
+
const SandboxSnapshotInfoBaseSchema = z.object({
|
|
125
|
+
/** Unique snapshot identifier */
|
|
126
|
+
id: z.string().describe('Unique snapshot identifier'),
|
|
127
|
+
/** Snapshot name */
|
|
128
|
+
name: z.string().optional().describe('Snapshot name'),
|
|
129
|
+
/** Snapshot tag */
|
|
130
|
+
tag: z.string().optional().describe('Snapshot tag'),
|
|
131
|
+
/** Full name with org slug (@slug/name:tag) */
|
|
132
|
+
fullName: z.string().optional().describe('Full name with org slug (@slug/name:tag)'),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/** Public snapshot information - includes org info */
|
|
136
|
+
export const SandboxSnapshotInfoPublicSchema = SandboxSnapshotInfoBaseSchema.extend({
|
|
137
|
+
/** Public snapshot */
|
|
138
|
+
public: z.literal(true).describe('Public snapshot'),
|
|
139
|
+
/** Organization that owns the public snapshot */
|
|
140
|
+
org: SandboxSnapshotOrgInfoSchema.describe('Organization that owns the public snapshot'),
|
|
141
|
+
});
|
|
142
|
+
export type SandboxSnapshotInfoPublic = z.infer<typeof SandboxSnapshotInfoPublicSchema>;
|
|
143
|
+
|
|
144
|
+
/** Private snapshot information - includes user info */
|
|
145
|
+
export const SandboxSnapshotInfoPrivateSchema = SandboxSnapshotInfoBaseSchema.extend({
|
|
146
|
+
/** Private snapshot */
|
|
147
|
+
public: z.literal(false).describe('Private snapshot'),
|
|
148
|
+
/** User who created the private snapshot */
|
|
149
|
+
user: SandboxSnapshotUserInfoSchema.describe('User who created the private snapshot'),
|
|
150
|
+
});
|
|
151
|
+
export type SandboxSnapshotInfoPrivate = z.infer<typeof SandboxSnapshotInfoPrivateSchema>;
|
|
152
|
+
|
|
153
|
+
/** Snapshot information included in sandbox responses (discriminated union) */
|
|
154
|
+
export const SandboxSnapshotInfoSchema = z.discriminatedUnion('public', [
|
|
155
|
+
SandboxSnapshotInfoPublicSchema,
|
|
156
|
+
SandboxSnapshotInfoPrivateSchema,
|
|
157
|
+
]);
|
|
158
|
+
export type SandboxSnapshotInfo = z.infer<typeof SandboxSnapshotInfoSchema>;
|
|
159
|
+
|
|
160
|
+
/** Execution status */
|
|
161
|
+
export const ExecutionStatusSchema = z.enum([
|
|
162
|
+
'queued',
|
|
163
|
+
'running',
|
|
164
|
+
'completed',
|
|
165
|
+
'failed',
|
|
166
|
+
'timeout',
|
|
167
|
+
'cancelled',
|
|
168
|
+
]);
|
|
169
|
+
export type ExecutionStatus = z.infer<typeof ExecutionStatusSchema>;
|
|
170
|
+
|
|
171
|
+
export const JobStatusSchema = z.enum(['pending', 'running', 'completed', 'failed', 'cancelled']);
|
|
172
|
+
export type JobStatus = z.infer<typeof JobStatusSchema>;
|
|
173
|
+
|
|
174
|
+
export const JobSchema = z.object({
|
|
175
|
+
jobId: z.string().describe('Unique identifier for the job'),
|
|
176
|
+
sandboxId: z.string().describe('ID of the sandbox where the job is running'),
|
|
177
|
+
command: z.array(z.string()).describe('Command and arguments being executed'),
|
|
178
|
+
status: JobStatusSchema.describe('Current status of the job'),
|
|
179
|
+
exitCode: z.number().nullish().describe('Exit code of the job (set when completed)'),
|
|
180
|
+
startedAt: z.string().nullish().describe('ISO timestamp when the job started'),
|
|
181
|
+
completedAt: z.string().nullish().describe('ISO timestamp when the job completed'),
|
|
182
|
+
error: z.string().nullish().describe('Error message if the job failed'),
|
|
183
|
+
stdoutStreamUrl: z.string().nullish().describe('URL to stream stdout output'),
|
|
184
|
+
stderrStreamUrl: z.string().nullish().describe('URL to stream stderr output'),
|
|
185
|
+
});
|
|
186
|
+
export type Job = z.infer<typeof JobSchema>;
|
|
187
|
+
|
|
188
|
+
export const CreateJobOptionsSchema = z.object({
|
|
189
|
+
command: z.array(z.string()).describe('Command and arguments to execute'),
|
|
190
|
+
streams: z
|
|
191
|
+
.object({
|
|
192
|
+
stdout: z.string().optional().describe('Stream ID for stdout output'),
|
|
193
|
+
stderr: z.string().optional().describe('Stream ID for stderr output'),
|
|
194
|
+
})
|
|
195
|
+
.optional()
|
|
196
|
+
.describe('Stream configuration for output redirection'),
|
|
197
|
+
});
|
|
198
|
+
export type CreateJobOptions = z.infer<typeof CreateJobOptionsSchema>;
|
|
199
|
+
|
|
200
|
+
/** Read-only stream interface for consuming streams without write access */
|
|
201
|
+
export const StreamReaderSchema = z.object({
|
|
202
|
+
/** Unique stream identifier */
|
|
203
|
+
id: z.string().describe('Unique stream identifier'),
|
|
204
|
+
/** Public URL to access the stream */
|
|
205
|
+
url: z.string().describe('Public URL to access the stream'),
|
|
206
|
+
/** Indicates this is a read-only stream */
|
|
207
|
+
readonly: z.literal(true).describe('Indicates this is a read-only stream'),
|
|
208
|
+
/** Get a ReadableStream that streams from the URL */
|
|
209
|
+
getReader: z
|
|
210
|
+
.custom<() => ReadableStream<Uint8Array>>()
|
|
211
|
+
.describe('Get a ReadableStream that streams from the URL'),
|
|
212
|
+
});
|
|
213
|
+
export type StreamReader = z.infer<typeof StreamReaderSchema>;
|
|
214
|
+
|
|
215
|
+
/** Stream configuration for sandbox output */
|
|
216
|
+
export const SandboxStreamConfigSchema = z.object({
|
|
217
|
+
/** Stream ID for stdout (or "ignore" to discard) */
|
|
218
|
+
stdout: z.string().optional().describe('Stream ID for stdout (or "ignore" to discard)'),
|
|
219
|
+
/** Stream ID for stderr (or "ignore" to discard) */
|
|
220
|
+
stderr: z.string().optional().describe('Stream ID for stderr (or "ignore" to discard)'),
|
|
221
|
+
/** Stream ID for stdin input */
|
|
222
|
+
stdin: z.string().optional().describe('Stream ID for stdin input'),
|
|
223
|
+
/** Include timestamps in output (default: true) */
|
|
224
|
+
timestamps: z.boolean().optional().describe('Include timestamps in output (default: true)'),
|
|
225
|
+
});
|
|
226
|
+
export type SandboxStreamConfig = z.infer<typeof SandboxStreamConfigSchema>;
|
|
227
|
+
|
|
228
|
+
/** Represents a file to write to the sandbox */
|
|
229
|
+
export const FileToWriteSchema = z.object({
|
|
230
|
+
/** Path to the file relative to the sandbox workspace */
|
|
231
|
+
path: z.string().describe('Path to the file relative to the sandbox workspace'),
|
|
232
|
+
/** File content as bytes */
|
|
233
|
+
content: z.instanceof(Uint8Array).describe('File content as bytes'),
|
|
234
|
+
});
|
|
235
|
+
export type FileToWrite = z.infer<typeof FileToWriteSchema>;
|
|
236
|
+
|
|
237
|
+
/** Command to execute in a sandbox */
|
|
238
|
+
export const SandboxCommandSchema = z.object({
|
|
239
|
+
/** Command and arguments to execute */
|
|
240
|
+
exec: z.array(z.string()).describe('Command and arguments to execute'),
|
|
241
|
+
/** Files to create before execution */
|
|
242
|
+
files: z.array(FileToWriteSchema).optional().describe('Files to create before execution'),
|
|
243
|
+
/** Execution mode: "oneshot" auto-destroys sandbox on exit */
|
|
244
|
+
mode: z
|
|
245
|
+
.enum(['oneshot', 'interactive'])
|
|
246
|
+
.optional()
|
|
247
|
+
.describe('Execution mode: "oneshot" auto-destroys sandbox on exit'),
|
|
248
|
+
});
|
|
249
|
+
export type SandboxCommand = z.infer<typeof SandboxCommandSchema>;
|
|
250
|
+
|
|
251
|
+
/** Network configuration for sandbox */
|
|
252
|
+
export const SandboxNetworkConfigSchema = z.object({
|
|
253
|
+
/** Whether to enable outbound network access (default: false) */
|
|
254
|
+
enabled: z
|
|
255
|
+
.boolean()
|
|
256
|
+
.optional()
|
|
257
|
+
.describe('Whether to enable outbound network access (default: false)'),
|
|
258
|
+
/** Port to expose from the sandbox to the outside Internet (1024-65535) */
|
|
259
|
+
port: z
|
|
260
|
+
.number()
|
|
261
|
+
.optional()
|
|
262
|
+
.describe('Port to expose from the sandbox to the outside Internet (1024-65535)'),
|
|
263
|
+
});
|
|
264
|
+
export type SandboxNetworkConfig = z.infer<typeof SandboxNetworkConfigSchema>;
|
|
265
|
+
|
|
266
|
+
/** Timeout configuration for sandbox */
|
|
267
|
+
export const SandboxTimeoutConfigSchema = z.object({
|
|
268
|
+
/** Idle timeout before sandbox is reaped (e.g., "10m", "1h") */
|
|
269
|
+
idle: z
|
|
270
|
+
.string()
|
|
271
|
+
.optional()
|
|
272
|
+
.describe('Idle timeout before sandbox is reaped (e.g., "10m", "1h")'),
|
|
273
|
+
/** Maximum execution time per command (e.g., "5m", "1h") */
|
|
274
|
+
execution: z
|
|
275
|
+
.string()
|
|
276
|
+
.optional()
|
|
277
|
+
.describe('Maximum execution time per command (e.g., "5m", "1h")'),
|
|
278
|
+
/** Maximum duration a sandbox can remain paused before termination (e.g., "24h", "0" for infinite) */
|
|
279
|
+
paused: z
|
|
280
|
+
.string()
|
|
281
|
+
.optional()
|
|
282
|
+
.describe(
|
|
283
|
+
'Maximum duration a sandbox can remain paused before termination (e.g., "24h", "0" for infinite)'
|
|
284
|
+
),
|
|
285
|
+
});
|
|
286
|
+
export type SandboxTimeoutConfig = z.infer<typeof SandboxTimeoutConfigSchema>;
|
|
287
|
+
|
|
288
|
+
/** Options for creating a sandbox. */
|
|
289
|
+
export const SandboxCreateOptionsSchema = z.object({
|
|
290
|
+
/** Project ID to associate the sandbox with. */
|
|
291
|
+
projectId: z.string().optional().describe('Project ID to associate the sandbox with.'),
|
|
292
|
+
/** Runtime name (e.g., "bun:1", "python:3.14"). */
|
|
293
|
+
runtime: z.string().optional().describe('Runtime name (e.g., "bun:1", "python:3.14").'),
|
|
294
|
+
/** Runtime ID (e.g., "srt_xxx"). */
|
|
295
|
+
runtimeId: z.string().optional().describe('Runtime ID (e.g., "srt_xxx").'),
|
|
296
|
+
/** Optional sandbox name. */
|
|
297
|
+
name: z.string().optional().describe('Optional sandbox name.'),
|
|
298
|
+
/** Optional description for the sandbox. */
|
|
299
|
+
description: z.string().optional().describe('Optional description for the sandbox.'),
|
|
300
|
+
/** Resource limits */
|
|
301
|
+
resources: SandboxResourcesSchema.optional().describe('Resource limits'),
|
|
302
|
+
/** Environment variables */
|
|
303
|
+
env: z.record(z.string(), z.string()).optional().describe('Environment variables'),
|
|
304
|
+
/** Network configuration */
|
|
305
|
+
network: SandboxNetworkConfigSchema.optional().describe('Network configuration'),
|
|
306
|
+
/** Stream configuration for output */
|
|
307
|
+
stream: SandboxStreamConfigSchema.optional().describe('Stream configuration for output'),
|
|
308
|
+
/** Timeout configuration */
|
|
309
|
+
timeout: SandboxTimeoutConfigSchema.optional().describe('Timeout configuration'),
|
|
310
|
+
/** Command to execute (if provided, creates a sandbox with initial execution) */
|
|
311
|
+
command: SandboxCommandSchema.optional().describe(
|
|
312
|
+
'Command to execute (if provided, creates a sandbox with initial execution)'
|
|
313
|
+
),
|
|
314
|
+
/** Files to write to the sandbox workspace on creation. */
|
|
315
|
+
files: z
|
|
316
|
+
.array(FileToWriteSchema)
|
|
317
|
+
.optional()
|
|
318
|
+
.describe('Files to write to the sandbox workspace on creation.'),
|
|
319
|
+
/** Snapshot ID or tag to restore from when creating the sandbox. */
|
|
320
|
+
snapshot: z
|
|
321
|
+
.string()
|
|
322
|
+
.optional()
|
|
323
|
+
.describe('Snapshot ID or tag to restore from when creating the sandbox.'),
|
|
324
|
+
/** Apt packages to install when creating the sandbox. */
|
|
325
|
+
dependencies: z
|
|
326
|
+
.array(z.string())
|
|
327
|
+
.optional()
|
|
328
|
+
.describe('Apt packages to install when creating the sandbox.'),
|
|
329
|
+
/** npm/bun packages to install globally when creating the sandbox. */
|
|
330
|
+
packages: z
|
|
331
|
+
.array(z.string())
|
|
332
|
+
.optional()
|
|
333
|
+
.describe('npm/bun packages to install globally when creating the sandbox.'),
|
|
334
|
+
/** Optional user-defined metadata to associate with the sandbox. */
|
|
335
|
+
metadata: z
|
|
336
|
+
.record(z.string(), z.unknown())
|
|
337
|
+
.optional()
|
|
338
|
+
.describe('Optional user-defined metadata to associate with the sandbox.'),
|
|
339
|
+
/** Permission scopes for automatic service access (e.g., "services:read", "services:write"). */
|
|
340
|
+
scopes: z
|
|
341
|
+
.array(z.string())
|
|
342
|
+
.optional()
|
|
343
|
+
.describe(
|
|
344
|
+
'Permission scopes for automatic service access (e.g., "services:read", "services:write").'
|
|
345
|
+
),
|
|
346
|
+
});
|
|
347
|
+
export type SandboxCreateOptions = z.infer<typeof SandboxCreateOptionsSchema>;
|
|
348
|
+
|
|
349
|
+
/** A sandbox instance with methods for interaction */
|
|
350
|
+
export const SandboxSchema = z.object({
|
|
351
|
+
/** Unique sandbox identifier */
|
|
352
|
+
id: z.string().describe('Unique sandbox identifier'),
|
|
353
|
+
/** Current status */
|
|
354
|
+
status: SandboxStatusSchema.describe('Current status'),
|
|
355
|
+
/** Runtime information for this sandbox */
|
|
356
|
+
runtime: SandboxRuntimeSchema.optional().describe('Runtime information for this sandbox'),
|
|
357
|
+
/** Sandbox name */
|
|
358
|
+
name: z.string().optional().describe('Sandbox name'),
|
|
359
|
+
/** Sandbox description */
|
|
360
|
+
description: z.string().optional().describe('Sandbox description'),
|
|
361
|
+
/** Read-only stream for stdout. */
|
|
362
|
+
stdout: StreamReaderSchema.describe('Read-only stream for stdout.'),
|
|
363
|
+
/** Read-only stream for stderr. */
|
|
364
|
+
stderr: StreamReaderSchema.describe('Read-only stream for stderr.'),
|
|
365
|
+
/** True if stdout and stderr are using the same stream (interleaved output). */
|
|
366
|
+
interleaved: z
|
|
367
|
+
.boolean()
|
|
368
|
+
.describe('True if stdout and stderr are using the same stream (interleaved output).'),
|
|
369
|
+
/** Stream ID for the audit event stream (eBPF/Tetragon security events). */
|
|
370
|
+
auditStreamId: z
|
|
371
|
+
.string()
|
|
372
|
+
.optional()
|
|
373
|
+
.describe('Stream ID for the audit event stream (eBPF/Tetragon security events).'),
|
|
374
|
+
/** Execute a command in the sandbox */
|
|
375
|
+
execute: z
|
|
376
|
+
.custom<(options: ExecuteOptions) => Promise<Execution>>()
|
|
377
|
+
.describe('Execute a command in the sandbox'),
|
|
378
|
+
/** Write files to the sandbox workspace. */
|
|
379
|
+
writeFiles: z
|
|
380
|
+
.custom<(files: FileToWrite[]) => Promise<void>>()
|
|
381
|
+
.describe('Write files to the sandbox workspace.'),
|
|
382
|
+
/** Read a file from the sandbox workspace. */
|
|
383
|
+
readFile: z
|
|
384
|
+
.custom<(path: string) => Promise<ReadableStream<Uint8Array>>>()
|
|
385
|
+
.describe('Read a file from the sandbox workspace.'),
|
|
386
|
+
/** List files in the sandbox workspace. */
|
|
387
|
+
listFiles: z
|
|
388
|
+
.custom<(path?: string) => Promise<SandboxFileInfo[]>>()
|
|
389
|
+
.describe('List files in the sandbox workspace.'),
|
|
390
|
+
/** Create a directory in the sandbox workspace. */
|
|
391
|
+
mkDir: z
|
|
392
|
+
.custom<(path: string, recursive?: boolean) => Promise<void>>()
|
|
393
|
+
.describe('Create a directory in the sandbox workspace.'),
|
|
394
|
+
/** Remove a file from the sandbox workspace. Returns whether the file was found. */
|
|
395
|
+
rmFile: z
|
|
396
|
+
.custom<(path: string) => Promise<{ found: boolean }>>()
|
|
397
|
+
.describe('Remove a file from the sandbox workspace. Returns whether the file was found.'),
|
|
398
|
+
/** Remove a directory from the sandbox workspace. Returns whether the directory was found. */
|
|
399
|
+
rmDir: z
|
|
400
|
+
.custom<(path: string, recursive?: boolean) => Promise<{ found: boolean }>>()
|
|
401
|
+
.describe(
|
|
402
|
+
'Remove a directory from the sandbox workspace. Returns whether the directory was found.'
|
|
403
|
+
),
|
|
404
|
+
/** Set environment variables on the sandbox. Pass null to delete a variable. */
|
|
405
|
+
setEnv: z
|
|
406
|
+
.custom<(env: Record<string, string | null>) => Promise<Record<string, string>>>()
|
|
407
|
+
.describe('Set environment variables on the sandbox. Pass null to delete a variable.'),
|
|
408
|
+
/** Pause the sandbox, creating a checkpoint of its current state. */
|
|
409
|
+
pause: z
|
|
410
|
+
.custom<() => Promise<SandboxPauseResult>>()
|
|
411
|
+
.describe('Pause the sandbox, creating a checkpoint of its current state.'),
|
|
412
|
+
/** Resume the sandbox from a paused or evacuated state. */
|
|
413
|
+
resume: z
|
|
414
|
+
.custom<() => Promise<void>>()
|
|
415
|
+
.describe('Resume the sandbox from a paused or evacuated state.'),
|
|
416
|
+
/** Destroy the sandbox */
|
|
417
|
+
destroy: z.custom<() => Promise<void>>().describe('Destroy the sandbox'),
|
|
418
|
+
/** Create a new job in the sandbox */
|
|
419
|
+
createJob: z
|
|
420
|
+
.custom<(options: CreateJobOptions) => Promise<Job>>()
|
|
421
|
+
.describe('Create a new job in the sandbox'),
|
|
422
|
+
/** Get a job by ID */
|
|
423
|
+
getJob: z.custom<(jobId: string) => Promise<Job>>().describe('Get a job by ID'),
|
|
424
|
+
/** List jobs in the sandbox */
|
|
425
|
+
listJobs: z
|
|
426
|
+
.custom<(limit?: number) => Promise<{ jobs: Job[] }>>()
|
|
427
|
+
.describe('List jobs in the sandbox'),
|
|
428
|
+
/** Stop a running job */
|
|
429
|
+
stopJob: z
|
|
430
|
+
.custom<(jobId: string, force?: boolean) => Promise<Job>>()
|
|
431
|
+
.describe('Stop a running job'),
|
|
432
|
+
});
|
|
433
|
+
export type Sandbox = z.infer<typeof SandboxSchema>;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* File information returned by sandbox file operations.
|
|
437
|
+
* NOTE: This interface is structurally identical to FileInfo in ./files.ts.
|
|
438
|
+
* It is duplicated here to avoid circular type imports. Keep these in sync.
|
|
439
|
+
*/
|
|
440
|
+
export interface SandboxFileInfo {
|
|
441
|
+
/** File path relative to the listed directory */
|
|
442
|
+
path: string;
|
|
443
|
+
/** File size in bytes */
|
|
444
|
+
size: number;
|
|
445
|
+
/** Whether the entry is a directory */
|
|
446
|
+
isDir: boolean;
|
|
447
|
+
/** Whether the entry is a symbolic link */
|
|
448
|
+
isSymlink?: boolean;
|
|
449
|
+
/** Target path of the symbolic link */
|
|
450
|
+
linkTarget?: string;
|
|
451
|
+
/** Unix permissions as octal string (e.g., "0644") */
|
|
452
|
+
mode: string;
|
|
453
|
+
/** Modification time in RFC3339 format */
|
|
454
|
+
modTime: string;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** Information about a user who created the sandbox */
|
|
458
|
+
export const SandboxUserInfoSchema = z.object({
|
|
459
|
+
/** User ID */
|
|
460
|
+
id: z.string().describe('User ID'),
|
|
461
|
+
/** User's first name */
|
|
462
|
+
firstName: z.string().optional().describe("User's first name"),
|
|
463
|
+
/** User's last name */
|
|
464
|
+
lastName: z.string().optional().describe("User's last name"),
|
|
465
|
+
});
|
|
466
|
+
export type SandboxUserInfo = z.infer<typeof SandboxUserInfoSchema>;
|
|
467
|
+
|
|
468
|
+
/** Information about an agent associated with the sandbox */
|
|
469
|
+
export const SandboxAgentInfoSchema = z.object({
|
|
470
|
+
/** Agent ID */
|
|
471
|
+
id: z.string().describe('Agent ID'),
|
|
472
|
+
/** Agent name */
|
|
473
|
+
name: z.string().describe('Agent name'),
|
|
474
|
+
});
|
|
475
|
+
export type SandboxAgentInfo = z.infer<typeof SandboxAgentInfoSchema>;
|
|
476
|
+
|
|
477
|
+
/** Information about a project associated with the sandbox */
|
|
478
|
+
export const SandboxProjectInfoSchema = z.object({
|
|
479
|
+
/** Project ID */
|
|
480
|
+
id: z.string().describe('Project ID'),
|
|
481
|
+
/** Project name */
|
|
482
|
+
name: z.string().describe('Project name'),
|
|
483
|
+
});
|
|
484
|
+
export type SandboxProjectInfo = z.infer<typeof SandboxProjectInfoSchema>;
|
|
485
|
+
|
|
486
|
+
/** Information about an organization associated with the sandbox */
|
|
487
|
+
export const SandboxOrgInfoSchema = z.object({
|
|
488
|
+
/** Organization ID */
|
|
489
|
+
id: z.string().describe('Organization ID'),
|
|
490
|
+
/** Organization name */
|
|
491
|
+
name: z.string().describe('Organization name'),
|
|
492
|
+
});
|
|
493
|
+
export type SandboxOrgInfo = z.infer<typeof SandboxOrgInfoSchema>;
|
|
494
|
+
|
|
495
|
+
/** Information about a sandbox */
|
|
496
|
+
export const SandboxInfoSchema = z.object({
|
|
497
|
+
/** Unique sandbox identifier */
|
|
498
|
+
sandboxId: z.string().describe('Unique sandbox identifier'),
|
|
499
|
+
/** Short identifier used for DNS hostname */
|
|
500
|
+
identifier: z.string().optional().describe('Short identifier used for DNS hostname'),
|
|
501
|
+
/** Sandbox name */
|
|
502
|
+
name: z.string().optional().describe('Sandbox name'),
|
|
503
|
+
/** Sandbox description */
|
|
504
|
+
description: z.string().optional().describe('Sandbox description'),
|
|
505
|
+
/** Current status */
|
|
506
|
+
status: SandboxStatusSchema.describe('Current status'),
|
|
507
|
+
/** Sandbox mode (interactive or oneshot) */
|
|
508
|
+
mode: z.string().optional().describe('Sandbox mode (interactive or oneshot)'),
|
|
509
|
+
/** Creation timestamp (ISO 8601) */
|
|
510
|
+
createdAt: z.string().describe('Creation timestamp (ISO 8601)'),
|
|
511
|
+
/** Region where the sandbox is running */
|
|
512
|
+
region: z.string().optional().describe('Region where the sandbox is running'),
|
|
513
|
+
/** Runtime information */
|
|
514
|
+
runtime: SandboxRuntimeInfoSchema.optional().describe('Runtime information'),
|
|
515
|
+
/** Snapshot information */
|
|
516
|
+
snapshot: SandboxSnapshotInfoSchema.optional().describe('Snapshot information'),
|
|
517
|
+
/** Number of executions run in this sandbox */
|
|
518
|
+
executions: z.number().describe('Number of executions run in this sandbox'),
|
|
519
|
+
/** Exit code from the last execution (only available for terminated/failed sandboxes) */
|
|
520
|
+
exitCode: z
|
|
521
|
+
.number()
|
|
522
|
+
.optional()
|
|
523
|
+
.describe(
|
|
524
|
+
'Exit code from the last execution (only available for terminated/failed sandboxes)'
|
|
525
|
+
),
|
|
526
|
+
/** URL to the stdout output stream */
|
|
527
|
+
stdoutStreamUrl: z.string().optional().describe('URL to the stdout output stream'),
|
|
528
|
+
/** URL to the stderr output stream */
|
|
529
|
+
stderrStreamUrl: z.string().optional().describe('URL to the stderr output stream'),
|
|
530
|
+
/** ID of the audit event stream (eBPF/Tetragon security events) */
|
|
531
|
+
auditStreamId: z
|
|
532
|
+
.string()
|
|
533
|
+
.optional()
|
|
534
|
+
.describe('ID of the audit event stream (eBPF/Tetragon security events)'),
|
|
535
|
+
/** URL to the audit event stream (eBPF/Tetragon security events) */
|
|
536
|
+
auditStreamUrl: z
|
|
537
|
+
.string()
|
|
538
|
+
.optional()
|
|
539
|
+
.describe('URL to the audit event stream (eBPF/Tetragon security events)'),
|
|
540
|
+
/** Apt packages installed in the sandbox */
|
|
541
|
+
dependencies: z.array(z.string()).optional().describe('Apt packages installed in the sandbox'),
|
|
542
|
+
/** npm/bun packages installed globally in the sandbox */
|
|
543
|
+
packages: z
|
|
544
|
+
.array(z.string())
|
|
545
|
+
.optional()
|
|
546
|
+
.describe('npm/bun packages installed globally in the sandbox'),
|
|
547
|
+
/** User-defined metadata associated with the sandbox */
|
|
548
|
+
metadata: z
|
|
549
|
+
.record(z.string(), z.unknown())
|
|
550
|
+
.optional()
|
|
551
|
+
.describe('User-defined metadata associated with the sandbox'),
|
|
552
|
+
/** Resource limits for this sandbox */
|
|
553
|
+
resources: SandboxResourcesSchema.optional().describe('Resource limits for this sandbox'),
|
|
554
|
+
/** Total CPU time consumed in milliseconds (available when terminated) */
|
|
555
|
+
cpuTimeMs: z
|
|
556
|
+
.number()
|
|
557
|
+
.optional()
|
|
558
|
+
.describe('Total CPU time consumed in milliseconds (available when terminated)'),
|
|
559
|
+
/** Total memory usage in byte-seconds (available when terminated) */
|
|
560
|
+
memoryByteSec: z
|
|
561
|
+
.number()
|
|
562
|
+
.optional()
|
|
563
|
+
.describe('Total memory usage in byte-seconds (available when terminated)'),
|
|
564
|
+
/** Total network egress in bytes (available when terminated) */
|
|
565
|
+
networkEgressBytes: z
|
|
566
|
+
.number()
|
|
567
|
+
.optional()
|
|
568
|
+
.describe('Total network egress in bytes (available when terminated)'),
|
|
569
|
+
/** Whether network access is enabled for this sandbox */
|
|
570
|
+
networkEnabled: z
|
|
571
|
+
.boolean()
|
|
572
|
+
.optional()
|
|
573
|
+
.describe('Whether network access is enabled for this sandbox'),
|
|
574
|
+
/** Network port exposed from the sandbox (1024-65535) */
|
|
575
|
+
networkPort: z
|
|
576
|
+
.number()
|
|
577
|
+
.optional()
|
|
578
|
+
.describe('Network port exposed from the sandbox (1024-65535)'),
|
|
579
|
+
/** Public URL for the sandbox (only set if networkPort is configured) */
|
|
580
|
+
url: z
|
|
581
|
+
.string()
|
|
582
|
+
.optional()
|
|
583
|
+
.describe('Public URL for the sandbox (only set if networkPort is configured)'),
|
|
584
|
+
/** User who created the sandbox (if available) */
|
|
585
|
+
user: SandboxUserInfoSchema.optional().describe('User who created the sandbox (if available)'),
|
|
586
|
+
/** Agent associated with the sandbox (if available) */
|
|
587
|
+
agent: SandboxAgentInfoSchema.optional().describe(
|
|
588
|
+
'Agent associated with the sandbox (if available)'
|
|
589
|
+
),
|
|
590
|
+
/** Project associated with the sandbox (if available) */
|
|
591
|
+
project: SandboxProjectInfoSchema.optional().describe(
|
|
592
|
+
'Project associated with the sandbox (if available)'
|
|
593
|
+
),
|
|
594
|
+
/** Organization associated with the sandbox */
|
|
595
|
+
org: SandboxOrgInfoSchema.describe('Organization associated with the sandbox'),
|
|
596
|
+
/** Timeout configuration for this sandbox */
|
|
597
|
+
timeout: z
|
|
598
|
+
.object({
|
|
599
|
+
/** Idle timeout duration (e.g., "10m0s") */
|
|
600
|
+
idle: z.string().optional().describe('Idle timeout duration (e.g., "10m0s")'),
|
|
601
|
+
/** Execution timeout duration (e.g., "5m0s") */
|
|
602
|
+
execution: z.string().optional().describe('Execution timeout duration (e.g., "5m0s")'),
|
|
603
|
+
/** Paused timeout duration (e.g., "24h0s", "0s" for infinite) */
|
|
604
|
+
paused: z
|
|
605
|
+
.string()
|
|
606
|
+
.optional()
|
|
607
|
+
.describe('Paused timeout duration (e.g., "24h0s", "0s" for infinite)'),
|
|
608
|
+
})
|
|
609
|
+
.optional()
|
|
610
|
+
.describe('Timeout configuration for this sandbox'),
|
|
611
|
+
/** Startup command configured for this sandbox */
|
|
612
|
+
command: z
|
|
613
|
+
.object({
|
|
614
|
+
/** Command and arguments */
|
|
615
|
+
exec: z.array(z.string()).describe('Command and arguments'),
|
|
616
|
+
/** Execution mode */
|
|
617
|
+
mode: z.enum(['oneshot', 'interactive']).optional().describe('Execution mode'),
|
|
618
|
+
})
|
|
619
|
+
.optional()
|
|
620
|
+
.describe('Startup command configured for this sandbox'),
|
|
621
|
+
});
|
|
622
|
+
export type SandboxInfo = z.infer<typeof SandboxInfoSchema>;
|
|
623
|
+
|
|
624
|
+
/** Parameters for listing sandboxes */
|
|
625
|
+
export const ListSandboxesParamsSchema = z.object({
|
|
626
|
+
/** Filter by sandbox name */
|
|
627
|
+
name: z.string().optional().describe('Filter by sandbox name'),
|
|
628
|
+
/** Filter by sandbox mode */
|
|
629
|
+
mode: z.enum(['oneshot', 'interactive']).optional().describe('Filter by sandbox mode'),
|
|
630
|
+
/** Filter by project ID */
|
|
631
|
+
projectId: z.string().optional().describe('Filter by project ID'),
|
|
632
|
+
/** Filter by snapshot ID */
|
|
633
|
+
snapshotId: z.string().optional().describe('Filter by snapshot ID'),
|
|
634
|
+
/** Filter by status */
|
|
635
|
+
status: SandboxStatusSchema.optional().describe('Filter by status'),
|
|
636
|
+
/** Filter by live status. */
|
|
637
|
+
live: z.boolean().optional().describe('Filter by live status.'),
|
|
638
|
+
/** Maximum number of results (default: 50, max: 100) */
|
|
639
|
+
limit: z.number().optional().describe('Maximum number of results (default: 50, max: 100)'),
|
|
640
|
+
/** Pagination offset */
|
|
641
|
+
offset: z.number().optional().describe('Pagination offset'),
|
|
642
|
+
/** Field to sort by */
|
|
643
|
+
sort: SandboxSortFieldSchema.optional().describe('Field to sort by'),
|
|
644
|
+
/** Sort direction (default: desc) */
|
|
645
|
+
direction: SortDirectionSchema.optional().describe('Sort direction (default: desc)'),
|
|
646
|
+
});
|
|
647
|
+
export type ListSandboxesParams = z.infer<typeof ListSandboxesParamsSchema>;
|
|
648
|
+
|
|
649
|
+
/** Response from listing sandboxes */
|
|
650
|
+
export const ListSandboxesResponseSchema = z.object({
|
|
651
|
+
/** Array of sandbox information */
|
|
652
|
+
sandboxes: z.array(SandboxInfoSchema).describe('Array of sandbox information'),
|
|
653
|
+
/** Total count of sandboxes matching the filter */
|
|
654
|
+
total: z.number().describe('Total count of sandboxes matching the filter'),
|
|
655
|
+
});
|
|
656
|
+
export type ListSandboxesResponse = z.infer<typeof ListSandboxesResponseSchema>;
|
|
657
|
+
|
|
658
|
+
/** Parameters for listing sandbox runtimes */
|
|
659
|
+
export const ListRuntimesParamsSchema = z.object({
|
|
660
|
+
/** Maximum number of results (default: 50, max: 100) */
|
|
661
|
+
limit: z.number().optional().describe('Maximum number of results (default: 50, max: 100)'),
|
|
662
|
+
/** Pagination offset */
|
|
663
|
+
offset: z.number().optional().describe('Pagination offset'),
|
|
664
|
+
/** Field to sort by */
|
|
665
|
+
sort: RuntimeSortFieldSchema.optional().describe('Field to sort by'),
|
|
666
|
+
/** Sort direction (default: desc) */
|
|
667
|
+
direction: SortDirectionSchema.optional().describe('Sort direction (default: desc)'),
|
|
668
|
+
});
|
|
669
|
+
export type ListRuntimesParams = z.infer<typeof ListRuntimesParamsSchema>;
|
|
670
|
+
|
|
671
|
+
/** Response from listing sandbox runtimes */
|
|
672
|
+
export const ListRuntimesResponseSchema = z.object({
|
|
673
|
+
/** Array of runtime information */
|
|
674
|
+
runtimes: z.array(SandboxRuntimeSchema).describe('Array of runtime information'),
|
|
675
|
+
/** Total count of runtimes */
|
|
676
|
+
total: z.number().describe('Total count of runtimes'),
|
|
677
|
+
});
|
|
678
|
+
export type ListRuntimesResponse = z.infer<typeof ListRuntimesResponseSchema>;
|
|
679
|
+
|
|
680
|
+
/** Options for executing a command in a sandbox */
|
|
681
|
+
export const ExecuteOptionsSchema = z.object({
|
|
682
|
+
/** Command and arguments to execute */
|
|
683
|
+
command: z.array(z.string()).describe('Command and arguments to execute'),
|
|
684
|
+
/** Files to create/update before execution. */
|
|
685
|
+
files: z
|
|
686
|
+
.array(FileToWriteSchema)
|
|
687
|
+
.optional()
|
|
688
|
+
.describe('Files to create/update before execution.'),
|
|
689
|
+
/** Execution timeout (e.g., "5m") */
|
|
690
|
+
timeout: z.string().optional().describe('Execution timeout (e.g., "5m")'),
|
|
691
|
+
/** Stream configuration (can override sandbox defaults) */
|
|
692
|
+
stream: z
|
|
693
|
+
.object({
|
|
694
|
+
stdout: z.string().optional().describe('stdout stream id'),
|
|
695
|
+
stderr: z.string().optional().describe('stderr stream id'),
|
|
696
|
+
timestamps: z.boolean().optional().describe('include timestamps'),
|
|
697
|
+
})
|
|
698
|
+
.optional()
|
|
699
|
+
.describe('Stream configuration (can override sandbox defaults)'),
|
|
700
|
+
/** AbortSignal to cancel the operation */
|
|
701
|
+
signal: z.custom<AbortSignal>().optional().describe('AbortSignal to cancel the operation'),
|
|
702
|
+
});
|
|
703
|
+
export type ExecuteOptions = z.infer<typeof ExecuteOptionsSchema>;
|
|
704
|
+
|
|
705
|
+
/** An execution instance */
|
|
706
|
+
export const ExecutionSchema = z.object({
|
|
707
|
+
/** Unique execution identifier */
|
|
708
|
+
executionId: z.string().describe('Unique execution identifier'),
|
|
709
|
+
/** Current status */
|
|
710
|
+
status: ExecutionStatusSchema.describe('Current status'),
|
|
711
|
+
/** Exit code (set when completed or failed) */
|
|
712
|
+
exitCode: z.number().optional().describe('Exit code (set when completed or failed)'),
|
|
713
|
+
/** Duration in milliseconds (set when completed) */
|
|
714
|
+
durationMs: z.number().optional().describe('Duration in milliseconds (set when completed)'),
|
|
715
|
+
/** URL to stream stdout output for this execution */
|
|
716
|
+
stdoutStreamUrl: z
|
|
717
|
+
.string()
|
|
718
|
+
.optional()
|
|
719
|
+
.describe('URL to stream stdout output for this execution'),
|
|
720
|
+
/** URL to stream stderr output for this execution */
|
|
721
|
+
stderrStreamUrl: z
|
|
722
|
+
.string()
|
|
723
|
+
.optional()
|
|
724
|
+
.describe('URL to stream stderr output for this execution'),
|
|
725
|
+
/** Whether the captured output was truncated due to size limits */
|
|
726
|
+
outputTruncated: z
|
|
727
|
+
.boolean()
|
|
728
|
+
.optional()
|
|
729
|
+
.describe('Whether the captured output was truncated due to size limits'),
|
|
730
|
+
/** True if the sandbox was automatically resumed from a suspended state to execute this command */
|
|
731
|
+
autoResumed: z
|
|
732
|
+
.boolean()
|
|
733
|
+
.optional()
|
|
734
|
+
.describe(
|
|
735
|
+
'True if the sandbox was automatically resumed from a suspended state to execute this command'
|
|
736
|
+
),
|
|
737
|
+
});
|
|
738
|
+
export type Execution = z.infer<typeof ExecutionSchema>;
|
|
739
|
+
|
|
740
|
+
// ===== Snapshot Types =====
|
|
741
|
+
|
|
742
|
+
/** Information about a file in a snapshot */
|
|
743
|
+
export const SnapshotFileInfoSchema = z.object({
|
|
744
|
+
/** File path within the snapshot */
|
|
745
|
+
path: z.string().describe('File path within the snapshot'),
|
|
746
|
+
/** File size in bytes */
|
|
747
|
+
size: z.number().describe('File size in bytes'),
|
|
748
|
+
/** SHA256 hash of the file contents */
|
|
749
|
+
sha256: z.string().describe('SHA256 hash of the file contents'),
|
|
750
|
+
/** MIME type of the file */
|
|
751
|
+
contentType: z.string().describe('MIME type of the file'),
|
|
752
|
+
/** Unix file mode/permissions (e.g., 0o644) */
|
|
753
|
+
mode: z.number().describe('Unix file mode/permissions (e.g., 0o644)'),
|
|
754
|
+
});
|
|
755
|
+
export type SnapshotFileInfo = z.infer<typeof SnapshotFileInfoSchema>;
|
|
756
|
+
|
|
757
|
+
/** Organization information for snapshots */
|
|
758
|
+
export const SnapshotOrgInfoSchema = z.object({
|
|
759
|
+
/** Organization ID */
|
|
760
|
+
id: z.string().describe('Organization ID'),
|
|
761
|
+
/** Organization name */
|
|
762
|
+
name: z.string().describe('Organization name'),
|
|
763
|
+
/** Organization slug for building full name */
|
|
764
|
+
slug: z.string().nullish().describe('Organization slug for building full name'),
|
|
765
|
+
});
|
|
766
|
+
export type SnapshotOrgInfo = z.infer<typeof SnapshotOrgInfoSchema>;
|
|
767
|
+
|
|
768
|
+
/** User information for snapshots */
|
|
769
|
+
export const SnapshotUserInfoSchema = z.object({
|
|
770
|
+
/** User ID */
|
|
771
|
+
id: z.string().describe('User ID'),
|
|
772
|
+
/** User first name */
|
|
773
|
+
firstName: z.string().nullish().describe('User first name'),
|
|
774
|
+
/** User last name */
|
|
775
|
+
lastName: z.string().nullish().describe('User last name'),
|
|
776
|
+
});
|
|
777
|
+
export type SnapshotUserInfo = z.infer<typeof SnapshotUserInfoSchema>;
|
|
778
|
+
|
|
779
|
+
/** Detailed information about a snapshot */
|
|
780
|
+
export const SnapshotInfoSchema = z.object({
|
|
781
|
+
/** Unique identifier for the snapshot */
|
|
782
|
+
snapshotId: z.string().describe('Unique identifier for the snapshot'),
|
|
783
|
+
/** Runtime ID associated with this snapshot */
|
|
784
|
+
runtimeId: z.string().nullish().describe('Runtime ID associated with this snapshot'),
|
|
785
|
+
/** Display name for the snapshot */
|
|
786
|
+
name: z.string().describe('Display name for the snapshot'),
|
|
787
|
+
/** Full name with org slug for public snapshots (@slug/name:tag) */
|
|
788
|
+
fullName: z
|
|
789
|
+
.string()
|
|
790
|
+
.optional()
|
|
791
|
+
.describe('Full name with org slug for public snapshots (@slug/name:tag)'),
|
|
792
|
+
/** Description of the snapshot */
|
|
793
|
+
description: z.string().nullish().describe('Description of the snapshot'),
|
|
794
|
+
/** Build message for the snapshot */
|
|
795
|
+
message: z.string().nullish().describe('Build message for the snapshot'),
|
|
796
|
+
/** Tag for the snapshot (defaults to "latest") */
|
|
797
|
+
tag: z.string().nullish().describe('Tag for the snapshot (defaults to "latest")'),
|
|
798
|
+
/** Total size of the snapshot in bytes */
|
|
799
|
+
sizeBytes: z.number().describe('Total size of the snapshot in bytes'),
|
|
800
|
+
/** Number of files in the snapshot */
|
|
801
|
+
fileCount: z.number().describe('Number of files in the snapshot'),
|
|
802
|
+
/** ID of the parent snapshot (for incremental snapshots) */
|
|
803
|
+
parentSnapshotId: z
|
|
804
|
+
.string()
|
|
805
|
+
.nullish()
|
|
806
|
+
.describe('ID of the parent snapshot (for incremental snapshots)'),
|
|
807
|
+
/** Whether the snapshot is publicly accessible */
|
|
808
|
+
public: z.boolean().optional().describe('Whether the snapshot is publicly accessible'),
|
|
809
|
+
/** Organization name (for public snapshots) */
|
|
810
|
+
orgName: z.string().optional().describe('Organization name (for public snapshots)'),
|
|
811
|
+
/** Organization slug (for public snapshots) */
|
|
812
|
+
orgSlug: z.string().optional().describe('Organization slug (for public snapshots)'),
|
|
813
|
+
/** Organization details (for public snapshots) */
|
|
814
|
+
org: SnapshotOrgInfoSchema.nullish().describe('Organization details (for public snapshots)'),
|
|
815
|
+
/** User who pushed the snapshot (for private snapshots) */
|
|
816
|
+
user: SnapshotUserInfoSchema.nullish().describe(
|
|
817
|
+
'User who pushed the snapshot (for private snapshots)'
|
|
818
|
+
),
|
|
819
|
+
/** ISO timestamp when the snapshot was created */
|
|
820
|
+
createdAt: z.string().describe('ISO timestamp when the snapshot was created'),
|
|
821
|
+
/** URL to download the snapshot archive */
|
|
822
|
+
downloadUrl: z.string().optional().describe('URL to download the snapshot archive'),
|
|
823
|
+
/** List of files in the snapshot */
|
|
824
|
+
files: z.array(SnapshotFileInfoSchema).nullish().describe('List of files in the snapshot'),
|
|
825
|
+
/** User-defined metadata key-value pairs */
|
|
826
|
+
userMetadata: z
|
|
827
|
+
.record(z.string(), z.string())
|
|
828
|
+
.nullish()
|
|
829
|
+
.describe('User-defined metadata key-value pairs'),
|
|
830
|
+
});
|
|
831
|
+
export type SnapshotInfo = z.infer<typeof SnapshotInfoSchema>;
|
|
832
|
+
|
|
833
|
+
/** Options for creating a snapshot */
|
|
834
|
+
export const SnapshotCreateOptionsSchema = z.object({
|
|
835
|
+
/** Display name for the snapshot (letters, numbers, underscores, dashes only) */
|
|
836
|
+
name: z
|
|
837
|
+
.string()
|
|
838
|
+
.optional()
|
|
839
|
+
.describe('Display name for the snapshot (letters, numbers, underscores, dashes only)'),
|
|
840
|
+
/** Description of the snapshot */
|
|
841
|
+
description: z.string().optional().describe('Description of the snapshot'),
|
|
842
|
+
/** Tag for the snapshot (defaults to "latest") */
|
|
843
|
+
tag: z.string().optional().describe('Tag for the snapshot (defaults to "latest")'),
|
|
844
|
+
/** Make the snapshot publicly accessible */
|
|
845
|
+
public: z.boolean().optional().describe('Make the snapshot publicly accessible'),
|
|
846
|
+
/** Organization ID to use for CLI-authenticated requests */
|
|
847
|
+
orgId: z.string().optional().describe('Organization ID for CLI-authenticated requests'),
|
|
848
|
+
});
|
|
849
|
+
export type SnapshotCreateOptions = z.infer<typeof SnapshotCreateOptionsSchema>;
|
|
850
|
+
|
|
851
|
+
/** Parameters for listing snapshots */
|
|
852
|
+
export const SnapshotListParamsSchema = z.object({
|
|
853
|
+
/** Filter by sandbox ID */
|
|
854
|
+
sandboxId: z.string().optional().describe('Filter by sandbox ID'),
|
|
855
|
+
/** Maximum number of snapshots to return */
|
|
856
|
+
limit: z.number().optional().describe('Maximum number of snapshots to return'),
|
|
857
|
+
/** Number of snapshots to skip for pagination */
|
|
858
|
+
offset: z.number().optional().describe('Number of snapshots to skip for pagination'),
|
|
859
|
+
/** Field to sort by */
|
|
860
|
+
sort: SnapshotSortFieldSchema.optional().describe('Field to sort by'),
|
|
861
|
+
/** Sort direction (default: desc) */
|
|
862
|
+
direction: SortDirectionSchema.optional().describe('Sort direction (default: desc)'),
|
|
863
|
+
});
|
|
864
|
+
export type SnapshotListParams = z.infer<typeof SnapshotListParamsSchema>;
|
|
865
|
+
|
|
866
|
+
/** Response from listing snapshots */
|
|
867
|
+
export const SnapshotListResponseSchema = z.object({
|
|
868
|
+
/** List of snapshot entries */
|
|
869
|
+
snapshots: z.array(SnapshotInfoSchema).describe('List of snapshot entries'),
|
|
870
|
+
/** Total number of snapshots matching the query */
|
|
871
|
+
total: z.number().describe('Total number of snapshots matching the query'),
|
|
872
|
+
});
|
|
873
|
+
export type SnapshotListResponse = z.infer<typeof SnapshotListResponseSchema>;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Service for managing sandbox snapshots
|
|
877
|
+
*/
|
|
878
|
+
export interface SnapshotService {
|
|
879
|
+
create(sandboxId: string, options?: SnapshotCreateOptions): Promise<SnapshotInfo>;
|
|
880
|
+
get(snapshotId: string): Promise<SnapshotInfo>;
|
|
881
|
+
list(params?: SnapshotListParams): Promise<SnapshotListResponse>;
|
|
882
|
+
delete(snapshotId: string): Promise<void>;
|
|
883
|
+
tag(snapshotId: string, tag: string | null): Promise<SnapshotInfo>;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** Options for one-shot sandbox execution */
|
|
887
|
+
export const SandboxRunOptionsSchema = SandboxCreateOptionsSchema.omit({ command: true }).extend({
|
|
888
|
+
/** Command to execute (required for run) */
|
|
889
|
+
command: z.object({
|
|
890
|
+
exec: z.array(z.string()).describe('Command arguments to execute'),
|
|
891
|
+
files: z.array(FileToWriteSchema).optional().describe('Files to create before execution'),
|
|
892
|
+
}),
|
|
893
|
+
});
|
|
894
|
+
export type SandboxRunOptions = z.infer<typeof SandboxRunOptionsSchema>;
|
|
895
|
+
|
|
896
|
+
/** Result from one-shot sandbox execution */
|
|
897
|
+
export const SandboxRunResultSchema = z.object({
|
|
898
|
+
/** Sandbox ID */
|
|
899
|
+
sandboxId: z.string().describe('Sandbox ID'),
|
|
900
|
+
/** Exit code from the process */
|
|
901
|
+
exitCode: z.number().describe('Exit code from the process'),
|
|
902
|
+
/** Duration in milliseconds */
|
|
903
|
+
durationMs: z.number().describe('Duration in milliseconds'),
|
|
904
|
+
/** Stdout content (if captured) */
|
|
905
|
+
stdout: z.string().optional().describe('Stdout content (if captured)'),
|
|
906
|
+
/** Stderr content (if captured) */
|
|
907
|
+
stderr: z.string().optional().describe('Stderr content (if captured)'),
|
|
908
|
+
});
|
|
909
|
+
export type SandboxRunResult = z.infer<typeof SandboxRunResultSchema>;
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Sandbox service for creating and managing isolated execution environments
|
|
913
|
+
*/
|
|
914
|
+
export interface SandboxService {
|
|
915
|
+
run(options: SandboxRunOptions): Promise<SandboxRunResult>;
|
|
916
|
+
create(options?: SandboxCreateOptions): Promise<Sandbox>;
|
|
917
|
+
/** Get a full Sandbox instance for an existing sandbox by ID. */
|
|
918
|
+
connect(sandboxId: string): Promise<Sandbox>;
|
|
919
|
+
get(sandboxId: string): Promise<SandboxInfo>;
|
|
920
|
+
list(params?: ListSandboxesParams): Promise<ListSandboxesResponse>;
|
|
921
|
+
destroy(sandboxId: string): Promise<void>;
|
|
922
|
+
/** Pause a running sandbox, creating a checkpoint of its current state. */
|
|
923
|
+
pause(sandboxId: string): Promise<SandboxPauseResult>;
|
|
924
|
+
/** Resume a paused or evacuated sandbox from its checkpoint. */
|
|
925
|
+
resume(sandboxId: string): Promise<void>;
|
|
926
|
+
snapshot: SnapshotService;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// ===== API Reference Schemas =====
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* Request body for updating sandbox environment variables.
|
|
933
|
+
*/
|
|
934
|
+
export const SandboxEnvUpdateRequestSchema = z.object({
|
|
935
|
+
/** Key-value pairs. Set value to null to delete a variable. */
|
|
936
|
+
env: z
|
|
937
|
+
.record(z.string(), z.string().nullable())
|
|
938
|
+
.describe('Key-value pairs. Set value to null to delete a variable.'),
|
|
939
|
+
});
|
|
940
|
+
export type SandboxEnvUpdateRequest = z.infer<typeof SandboxEnvUpdateRequestSchema>;
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Response data for updating sandbox environment variables.
|
|
944
|
+
*/
|
|
945
|
+
export const SandboxEnvUpdateResponseSchema = z.object({
|
|
946
|
+
/** Current environment after update */
|
|
947
|
+
env: z.record(z.string(), z.string()).describe('Current environment after update'),
|
|
948
|
+
});
|
|
949
|
+
export type SandboxEnvUpdateResponse = z.infer<typeof SandboxEnvUpdateResponseSchema>;
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Response data for sandbox status check (mirrors private SandboxStatusDataSchema in getStatus.ts).
|
|
953
|
+
*/
|
|
954
|
+
export const SandboxStatusResponseDataSchema = z.object({
|
|
955
|
+
/** Unique identifier for the sandbox */
|
|
956
|
+
sandboxId: z.string().describe('Unique identifier for the sandbox.'),
|
|
957
|
+
/** Current status of the sandbox */
|
|
958
|
+
status: z.string().describe('Current status of the sandbox.'),
|
|
959
|
+
/** Exit code from the last execution, if terminated */
|
|
960
|
+
exitCode: z.number().optional().describe('Exit code from the last execution, if terminated.'),
|
|
961
|
+
});
|
|
962
|
+
export type SandboxStatusResponseData = z.infer<typeof SandboxStatusResponseDataSchema>;
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Request body for initializing a snapshot build (mirrors private _SnapshotBuildInitParamsSchema in snapshot.ts).
|
|
966
|
+
*/
|
|
967
|
+
export const SnapshotBuildInitRequestSchema = z.object({
|
|
968
|
+
/** Runtime identifier (name:tag or runtime ID) */
|
|
969
|
+
runtime: z.string().describe('Runtime identifier (name:tag or runtime ID)'),
|
|
970
|
+
/** Display name for the snapshot */
|
|
971
|
+
name: z.string().optional().describe('Display name for the snapshot'),
|
|
972
|
+
/** Tag for the snapshot */
|
|
973
|
+
tag: z.string().optional().describe('Tag for the snapshot'),
|
|
974
|
+
/** Description of the snapshot */
|
|
975
|
+
description: z.string().optional().describe('Description of the snapshot'),
|
|
976
|
+
/** SHA-256 hash of snapshot content for change detection */
|
|
977
|
+
contentHash: z
|
|
978
|
+
.string()
|
|
979
|
+
.optional()
|
|
980
|
+
.describe('SHA-256 hash of snapshot content for change detection'),
|
|
981
|
+
/** Force rebuild even if content is unchanged */
|
|
982
|
+
force: z.boolean().optional().describe('Force rebuild even if content is unchanged'),
|
|
983
|
+
/** Request encryption for the snapshot archive */
|
|
984
|
+
encrypt: z.boolean().optional().describe('Request encryption for the snapshot archive'),
|
|
985
|
+
/** Make snapshot public (enables virus scanning, disables encryption) */
|
|
986
|
+
public: z
|
|
987
|
+
.boolean()
|
|
988
|
+
.optional()
|
|
989
|
+
.describe('Make snapshot public (enables virus scanning, disables encryption)'),
|
|
990
|
+
});
|
|
991
|
+
export type SnapshotBuildInitRequest = z.infer<typeof SnapshotBuildInitRequestSchema>;
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Request body for finalizing a snapshot build (mirrors private _SnapshotBuildFinalizeParamsSchema in snapshot.ts).
|
|
995
|
+
*/
|
|
996
|
+
export const SnapshotBuildFinalizeRequestSchema = z.object({
|
|
997
|
+
/** Total size of the snapshot in bytes */
|
|
998
|
+
sizeBytes: z.number().describe('Total size of the snapshot in bytes'),
|
|
999
|
+
/** Number of files in the snapshot */
|
|
1000
|
+
fileCount: z.number().describe('Number of files in the snapshot'),
|
|
1001
|
+
/** Array of file metadata */
|
|
1002
|
+
files: z.array(SnapshotFileInfoSchema).describe('Array of file metadata'),
|
|
1003
|
+
/** List of apt packages to install */
|
|
1004
|
+
dependencies: z.array(z.string()).optional().describe('List of apt packages to install'),
|
|
1005
|
+
/** List of npm/bun packages to install globally */
|
|
1006
|
+
packages: z
|
|
1007
|
+
.array(z.string())
|
|
1008
|
+
.optional()
|
|
1009
|
+
.describe('List of npm/bun packages to install globally'),
|
|
1010
|
+
/** Environment variables to set */
|
|
1011
|
+
env: z.record(z.string(), z.string()).optional().describe('Environment variables to set'),
|
|
1012
|
+
/** User-defined metadata key-value pairs */
|
|
1013
|
+
metadata: z
|
|
1014
|
+
.record(z.string(), z.string())
|
|
1015
|
+
.optional()
|
|
1016
|
+
.describe('User-defined metadata key-value pairs'),
|
|
1017
|
+
});
|
|
1018
|
+
export type SnapshotBuildFinalizeRequest = z.infer<typeof SnapshotBuildFinalizeRequestSchema>;
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Request body for updating a snapshot tag.
|
|
1022
|
+
*/
|
|
1023
|
+
export const SnapshotTagUpdateRequestSchema = z.object({
|
|
1024
|
+
/** New tag or null to remove tag */
|
|
1025
|
+
tag: z.string().nullable().describe('New tag or null to remove tag'),
|
|
1026
|
+
});
|
|
1027
|
+
export type SnapshotTagUpdateRequest = z.infer<typeof SnapshotTagUpdateRequestSchema>;
|
|
1028
|
+
|
|
1029
|
+
/** Structured error for sandbox operations */
|
|
1030
|
+
export const SandboxError = StructuredError('SandboxError')<{
|
|
1031
|
+
sandboxId?: string;
|
|
1032
|
+
executionId?: string;
|
|
1033
|
+
}>();
|