agentkernel 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -29,6 +29,21 @@ interface CreateSandboxOptions {
29
29
  vcpus?: number;
30
30
  memory_mb?: number;
31
31
  profile?: SecurityProfile;
32
+ /** Git repository URL to clone into the sandbox. */
33
+ source_url?: string;
34
+ /** Git ref to checkout after cloning. */
35
+ source_ref?: string;
36
+ /** Volume mounts (slug:/path or slug:/path:ro). Create volumes via CLI first. */
37
+ volumes?: string[];
38
+ }
39
+ /** Options for executing a command in a sandbox. */
40
+ interface ExecOptions {
41
+ /** Environment variables (KEY=VALUE). */
42
+ env?: string[];
43
+ /** Working directory inside the container. */
44
+ workdir?: string;
45
+ /** Run as root. */
46
+ sudo?: boolean;
32
47
  }
33
48
  /** Output from a command execution. */
34
49
  interface RunOutput {
@@ -73,16 +88,125 @@ interface BatchResult {
73
88
  interface BatchRunResponse {
74
89
  results: BatchResult[];
75
90
  }
91
+ /** Result of a batch file write. */
92
+ interface BatchFileWriteResponse {
93
+ written: number;
94
+ }
95
+ /** Status of a detached command. */
96
+ type DetachedStatus = "running" | "completed" | "failed";
97
+ /** A detached (background) command running in a sandbox. */
98
+ interface DetachedCommand {
99
+ id: string;
100
+ sandbox: string;
101
+ command: string[];
102
+ pid: number;
103
+ status: DetachedStatus;
104
+ exit_code: number | null;
105
+ started_at: string;
106
+ }
107
+ /** Response from detached command logs. */
108
+ interface DetachedLogsResponse {
109
+ stdout?: string;
110
+ stderr?: string;
111
+ }
76
112
  /** API response wrapper. */
77
113
  interface ApiResponse<T> {
78
114
  success: boolean;
79
115
  data?: T;
80
116
  error?: string;
81
117
  }
118
+ /** Response from extending a sandbox's TTL. */
119
+ interface ExtendTtlResponse {
120
+ expires_at?: string;
121
+ }
122
+ /** Options for extending TTL. */
123
+ interface ExtendTtlOptions {
124
+ /** Duration string like "1h", "30m", "2d". */
125
+ by: string;
126
+ }
127
+ /** Metadata for a sandbox snapshot. */
128
+ interface SnapshotMeta {
129
+ name: string;
130
+ sandbox: string;
131
+ image_tag: string;
132
+ backend: string;
133
+ base_image?: string;
134
+ vcpus?: number;
135
+ memory_mb?: number;
136
+ created_at: string;
137
+ }
138
+ /** Options for taking a snapshot. */
139
+ interface TakeSnapshotOptions {
140
+ /** Name of the sandbox to snapshot. */
141
+ sandbox: string;
142
+ /** Optional snapshot name (auto-generated if not provided). */
143
+ name?: string;
144
+ }
145
+ /** A link extracted from a web page. */
146
+ interface PageLink {
147
+ text: string;
148
+ href: string;
149
+ }
150
+ /** Result of navigating to a web page. */
151
+ interface PageResult {
152
+ /** Page title. */
153
+ title: string;
154
+ /** Final URL after redirects. */
155
+ url: string;
156
+ /** Page body text (truncated to ~8KB). */
157
+ text: string;
158
+ /** First 50 links on the page. */
159
+ links: PageLink[];
160
+ }
82
161
 
83
- type ExecFn = (name: string, command: string[]) => Promise<RunOutput>;
162
+ /**
163
+ * Browser session for orchestrating headless browsers in sandboxes.
164
+ *
165
+ * Each method generates a self-contained Python/Playwright script,
166
+ * runs it inside the sandbox, and parses the JSON result.
167
+ */
168
+
169
+ type RunInSandboxFn = (name: string, command: string[]) => Promise<RunOutput>;
170
+ type RemoveSandboxFn = (name: string) => Promise<void>;
171
+ /** Command to install Playwright + Chromium inside the sandbox. */
172
+ declare const BROWSER_SETUP_CMD: string[];
173
+ /**
174
+ * A sandboxed headless browser controlled from outside.
175
+ *
176
+ * The browser (Chromium via Playwright) runs inside an agentkernel sandbox.
177
+ * You call high-level methods; the SDK generates and runs scripts internally.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * await using browser = await client.browser("my-browser");
182
+ * const page = await browser.goto("https://example.com");
183
+ * console.log(page.title, page.links);
184
+ * ```
185
+ */
186
+ declare class BrowserSession implements AsyncDisposable {
187
+ readonly name: string;
188
+ private _removed;
189
+ private _lastUrl;
190
+ private readonly _run;
191
+ private readonly _remove;
192
+ /** @internal */
193
+ constructor(name: string, runFn: RunInSandboxFn, removeFn: RemoveSandboxFn);
194
+ /** Navigate to a URL and return page data (title, text, links). */
195
+ goto(url: string): Promise<PageResult>;
196
+ /** Take a PNG screenshot. Returns a base64-encoded string. */
197
+ screenshot(url?: string): Promise<string>;
198
+ /** Run a JavaScript expression on a page and return the result. */
199
+ evaluate(expression: string, url?: string): Promise<unknown>;
200
+ /** Remove the sandbox. Idempotent. */
201
+ remove(): Promise<void>;
202
+ /** Auto-cleanup for `await using`. */
203
+ [Symbol.asyncDispose](): Promise<void>;
204
+ }
205
+
206
+ type ExecFn = (name: string, command: string[], opts?: ExecOptions) => Promise<RunOutput>;
84
207
  type RemoveFn = (name: string) => Promise<void>;
85
208
  type GetFn = (name: string) => Promise<SandboxInfo>;
209
+ type WriteFilesFn = (name: string, files: Record<string, string>) => Promise<BatchFileWriteResponse>;
86
210
  /**
87
211
  * A sandbox session that auto-removes the sandbox on dispose.
88
212
  *
@@ -102,12 +226,15 @@ declare class SandboxSession implements AsyncDisposable {
102
226
  private readonly _execInSandbox;
103
227
  private readonly _removeSandbox;
104
228
  private readonly _getSandbox;
229
+ private readonly _writeFiles;
105
230
  /** @internal */
106
- constructor(name: string, execInSandbox: ExecFn, removeSandbox: RemoveFn, getSandbox: GetFn);
231
+ constructor(name: string, execInSandbox: ExecFn, removeSandbox: RemoveFn, getSandbox: GetFn, writeFiles: WriteFilesFn);
107
232
  /** Run a command in this sandbox. */
108
- run(command: string[]): Promise<RunOutput>;
233
+ run(command: string[], opts?: ExecOptions): Promise<RunOutput>;
109
234
  /** Get sandbox info. */
110
235
  info(): Promise<SandboxInfo>;
236
+ /** Write multiple files in one request. */
237
+ writeFiles(files: Record<string, string>): Promise<BatchFileWriteResponse>;
111
238
  /** Remove the sandbox. Idempotent. */
112
239
  remove(): Promise<void>;
113
240
  /** Auto-cleanup for `await using`. */
@@ -153,7 +280,7 @@ declare class AgentKernel {
153
280
  /** Remove a sandbox. */
154
281
  removeSandbox(name: string): Promise<void>;
155
282
  /** Run a command in an existing sandbox. */
156
- execInSandbox(name: string, command: string[]): Promise<RunOutput>;
283
+ execInSandbox(name: string, command: string[], opts?: ExecOptions): Promise<RunOutput>;
157
284
  /** Read a file from a sandbox. */
158
285
  readFile(name: string, path: string): Promise<FileReadResponse>;
159
286
  /** Write a file to a sandbox. */
@@ -162,8 +289,20 @@ declare class AgentKernel {
162
289
  deleteFile(name: string, path: string): Promise<string>;
163
290
  /** Get audit log entries for a sandbox. */
164
291
  getSandboxLogs(name: string): Promise<Record<string, unknown>[]>;
292
+ /** Write multiple files to a sandbox in one request. */
293
+ writeFiles(name: string, files: Record<string, string>): Promise<BatchFileWriteResponse>;
165
294
  /** Run multiple commands in parallel. */
166
295
  batchRun(commands: BatchCommand[]): Promise<BatchRunResponse>;
296
+ /** Start a detached (background) command in a sandbox. */
297
+ execDetached(name: string, command: string[], opts?: ExecOptions): Promise<DetachedCommand>;
298
+ /** Get the status of a detached command. */
299
+ detachedStatus(name: string, cmdId: string): Promise<DetachedCommand>;
300
+ /** Get logs from a detached command. */
301
+ detachedLogs(name: string, cmdId: string, stream?: "stdout" | "stderr"): Promise<DetachedLogsResponse>;
302
+ /** Kill a detached command. */
303
+ detachedKill(name: string, cmdId: string): Promise<string>;
304
+ /** List detached commands in a sandbox. */
305
+ detachedList(name: string): Promise<DetachedCommand[]>;
167
306
  /**
168
307
  * Create a sandbox session with automatic cleanup.
169
308
  *
@@ -178,6 +317,35 @@ declare class AgentKernel {
178
317
  * ```
179
318
  */
180
319
  sandbox(name: string, opts?: CreateSandboxOptions): Promise<SandboxSession>;
320
+ /**
321
+ * Create a sandboxed browser session with automatic cleanup.
322
+ *
323
+ * Creates a sandbox with Chromium pre-installed via Playwright.
324
+ * Use `goto()`, `screenshot()`, and `evaluate()` to interact with web pages.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * await using browser = await client.browser("my-browser");
329
+ * const page = await browser.goto("https://example.com");
330
+ * console.log(page.title, page.links);
331
+ * // sandbox auto-removed when scope exits
332
+ * ```
333
+ */
334
+ browser(name: string, opts?: {
335
+ memory_mb?: number;
336
+ }): Promise<BrowserSession>;
337
+ /** Extend a sandbox's TTL. Returns the new expiry time. */
338
+ extendTtl(name: string, opts: ExtendTtlOptions): Promise<ExtendTtlResponse>;
339
+ /** List all snapshots. */
340
+ listSnapshots(): Promise<SnapshotMeta[]>;
341
+ /** Take a snapshot of a sandbox. */
342
+ takeSnapshot(opts: TakeSnapshotOptions): Promise<SnapshotMeta>;
343
+ /** Get info about a snapshot. */
344
+ getSnapshot(name: string): Promise<SnapshotMeta>;
345
+ /** Delete a snapshot. */
346
+ deleteSnapshot(name: string): Promise<void>;
347
+ /** Restore a sandbox from a snapshot. */
348
+ restoreSnapshot(name: string): Promise<SandboxInfo>;
181
349
  private headers;
182
350
  private fetch;
183
351
  private request;
@@ -216,4 +384,4 @@ declare class StreamError extends AgentKernelError {
216
384
  constructor(message?: string);
217
385
  }
218
386
 
219
- export { AgentKernel, AgentKernelError, type AgentKernelOptions, type ApiResponse, AuthError, type CreateSandboxOptions, NetworkError, NotFoundError, type RunOptions, type RunOutput, type SandboxInfo, SandboxSession, type SandboxStatus, type SecurityProfile, ServerError, StreamError, type StreamEvent, type StreamEventType, ValidationError };
387
+ export { AgentKernel, AgentKernelError, type AgentKernelOptions, type ApiResponse, AuthError, BROWSER_SETUP_CMD, type BatchFileWriteResponse, BrowserSession, type CreateSandboxOptions, type DetachedCommand, type DetachedLogsResponse, type DetachedStatus, type ExecOptions, type ExtendTtlOptions, type ExtendTtlResponse, NetworkError, NotFoundError, type PageLink, type PageResult, type RunOptions, type RunOutput, type SandboxInfo, SandboxSession, type SandboxStatus, type SecurityProfile, ServerError, type SnapshotMeta, StreamError, type StreamEvent, type StreamEventType, type TakeSnapshotOptions, ValidationError };
package/dist/index.d.ts CHANGED
@@ -29,6 +29,21 @@ interface CreateSandboxOptions {
29
29
  vcpus?: number;
30
30
  memory_mb?: number;
31
31
  profile?: SecurityProfile;
32
+ /** Git repository URL to clone into the sandbox. */
33
+ source_url?: string;
34
+ /** Git ref to checkout after cloning. */
35
+ source_ref?: string;
36
+ /** Volume mounts (slug:/path or slug:/path:ro). Create volumes via CLI first. */
37
+ volumes?: string[];
38
+ }
39
+ /** Options for executing a command in a sandbox. */
40
+ interface ExecOptions {
41
+ /** Environment variables (KEY=VALUE). */
42
+ env?: string[];
43
+ /** Working directory inside the container. */
44
+ workdir?: string;
45
+ /** Run as root. */
46
+ sudo?: boolean;
32
47
  }
33
48
  /** Output from a command execution. */
34
49
  interface RunOutput {
@@ -73,16 +88,125 @@ interface BatchResult {
73
88
  interface BatchRunResponse {
74
89
  results: BatchResult[];
75
90
  }
91
+ /** Result of a batch file write. */
92
+ interface BatchFileWriteResponse {
93
+ written: number;
94
+ }
95
+ /** Status of a detached command. */
96
+ type DetachedStatus = "running" | "completed" | "failed";
97
+ /** A detached (background) command running in a sandbox. */
98
+ interface DetachedCommand {
99
+ id: string;
100
+ sandbox: string;
101
+ command: string[];
102
+ pid: number;
103
+ status: DetachedStatus;
104
+ exit_code: number | null;
105
+ started_at: string;
106
+ }
107
+ /** Response from detached command logs. */
108
+ interface DetachedLogsResponse {
109
+ stdout?: string;
110
+ stderr?: string;
111
+ }
76
112
  /** API response wrapper. */
77
113
  interface ApiResponse<T> {
78
114
  success: boolean;
79
115
  data?: T;
80
116
  error?: string;
81
117
  }
118
+ /** Response from extending a sandbox's TTL. */
119
+ interface ExtendTtlResponse {
120
+ expires_at?: string;
121
+ }
122
+ /** Options for extending TTL. */
123
+ interface ExtendTtlOptions {
124
+ /** Duration string like "1h", "30m", "2d". */
125
+ by: string;
126
+ }
127
+ /** Metadata for a sandbox snapshot. */
128
+ interface SnapshotMeta {
129
+ name: string;
130
+ sandbox: string;
131
+ image_tag: string;
132
+ backend: string;
133
+ base_image?: string;
134
+ vcpus?: number;
135
+ memory_mb?: number;
136
+ created_at: string;
137
+ }
138
+ /** Options for taking a snapshot. */
139
+ interface TakeSnapshotOptions {
140
+ /** Name of the sandbox to snapshot. */
141
+ sandbox: string;
142
+ /** Optional snapshot name (auto-generated if not provided). */
143
+ name?: string;
144
+ }
145
+ /** A link extracted from a web page. */
146
+ interface PageLink {
147
+ text: string;
148
+ href: string;
149
+ }
150
+ /** Result of navigating to a web page. */
151
+ interface PageResult {
152
+ /** Page title. */
153
+ title: string;
154
+ /** Final URL after redirects. */
155
+ url: string;
156
+ /** Page body text (truncated to ~8KB). */
157
+ text: string;
158
+ /** First 50 links on the page. */
159
+ links: PageLink[];
160
+ }
82
161
 
83
- type ExecFn = (name: string, command: string[]) => Promise<RunOutput>;
162
+ /**
163
+ * Browser session for orchestrating headless browsers in sandboxes.
164
+ *
165
+ * Each method generates a self-contained Python/Playwright script,
166
+ * runs it inside the sandbox, and parses the JSON result.
167
+ */
168
+
169
+ type RunInSandboxFn = (name: string, command: string[]) => Promise<RunOutput>;
170
+ type RemoveSandboxFn = (name: string) => Promise<void>;
171
+ /** Command to install Playwright + Chromium inside the sandbox. */
172
+ declare const BROWSER_SETUP_CMD: string[];
173
+ /**
174
+ * A sandboxed headless browser controlled from outside.
175
+ *
176
+ * The browser (Chromium via Playwright) runs inside an agentkernel sandbox.
177
+ * You call high-level methods; the SDK generates and runs scripts internally.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * await using browser = await client.browser("my-browser");
182
+ * const page = await browser.goto("https://example.com");
183
+ * console.log(page.title, page.links);
184
+ * ```
185
+ */
186
+ declare class BrowserSession implements AsyncDisposable {
187
+ readonly name: string;
188
+ private _removed;
189
+ private _lastUrl;
190
+ private readonly _run;
191
+ private readonly _remove;
192
+ /** @internal */
193
+ constructor(name: string, runFn: RunInSandboxFn, removeFn: RemoveSandboxFn);
194
+ /** Navigate to a URL and return page data (title, text, links). */
195
+ goto(url: string): Promise<PageResult>;
196
+ /** Take a PNG screenshot. Returns a base64-encoded string. */
197
+ screenshot(url?: string): Promise<string>;
198
+ /** Run a JavaScript expression on a page and return the result. */
199
+ evaluate(expression: string, url?: string): Promise<unknown>;
200
+ /** Remove the sandbox. Idempotent. */
201
+ remove(): Promise<void>;
202
+ /** Auto-cleanup for `await using`. */
203
+ [Symbol.asyncDispose](): Promise<void>;
204
+ }
205
+
206
+ type ExecFn = (name: string, command: string[], opts?: ExecOptions) => Promise<RunOutput>;
84
207
  type RemoveFn = (name: string) => Promise<void>;
85
208
  type GetFn = (name: string) => Promise<SandboxInfo>;
209
+ type WriteFilesFn = (name: string, files: Record<string, string>) => Promise<BatchFileWriteResponse>;
86
210
  /**
87
211
  * A sandbox session that auto-removes the sandbox on dispose.
88
212
  *
@@ -102,12 +226,15 @@ declare class SandboxSession implements AsyncDisposable {
102
226
  private readonly _execInSandbox;
103
227
  private readonly _removeSandbox;
104
228
  private readonly _getSandbox;
229
+ private readonly _writeFiles;
105
230
  /** @internal */
106
- constructor(name: string, execInSandbox: ExecFn, removeSandbox: RemoveFn, getSandbox: GetFn);
231
+ constructor(name: string, execInSandbox: ExecFn, removeSandbox: RemoveFn, getSandbox: GetFn, writeFiles: WriteFilesFn);
107
232
  /** Run a command in this sandbox. */
108
- run(command: string[]): Promise<RunOutput>;
233
+ run(command: string[], opts?: ExecOptions): Promise<RunOutput>;
109
234
  /** Get sandbox info. */
110
235
  info(): Promise<SandboxInfo>;
236
+ /** Write multiple files in one request. */
237
+ writeFiles(files: Record<string, string>): Promise<BatchFileWriteResponse>;
111
238
  /** Remove the sandbox. Idempotent. */
112
239
  remove(): Promise<void>;
113
240
  /** Auto-cleanup for `await using`. */
@@ -153,7 +280,7 @@ declare class AgentKernel {
153
280
  /** Remove a sandbox. */
154
281
  removeSandbox(name: string): Promise<void>;
155
282
  /** Run a command in an existing sandbox. */
156
- execInSandbox(name: string, command: string[]): Promise<RunOutput>;
283
+ execInSandbox(name: string, command: string[], opts?: ExecOptions): Promise<RunOutput>;
157
284
  /** Read a file from a sandbox. */
158
285
  readFile(name: string, path: string): Promise<FileReadResponse>;
159
286
  /** Write a file to a sandbox. */
@@ -162,8 +289,20 @@ declare class AgentKernel {
162
289
  deleteFile(name: string, path: string): Promise<string>;
163
290
  /** Get audit log entries for a sandbox. */
164
291
  getSandboxLogs(name: string): Promise<Record<string, unknown>[]>;
292
+ /** Write multiple files to a sandbox in one request. */
293
+ writeFiles(name: string, files: Record<string, string>): Promise<BatchFileWriteResponse>;
165
294
  /** Run multiple commands in parallel. */
166
295
  batchRun(commands: BatchCommand[]): Promise<BatchRunResponse>;
296
+ /** Start a detached (background) command in a sandbox. */
297
+ execDetached(name: string, command: string[], opts?: ExecOptions): Promise<DetachedCommand>;
298
+ /** Get the status of a detached command. */
299
+ detachedStatus(name: string, cmdId: string): Promise<DetachedCommand>;
300
+ /** Get logs from a detached command. */
301
+ detachedLogs(name: string, cmdId: string, stream?: "stdout" | "stderr"): Promise<DetachedLogsResponse>;
302
+ /** Kill a detached command. */
303
+ detachedKill(name: string, cmdId: string): Promise<string>;
304
+ /** List detached commands in a sandbox. */
305
+ detachedList(name: string): Promise<DetachedCommand[]>;
167
306
  /**
168
307
  * Create a sandbox session with automatic cleanup.
169
308
  *
@@ -178,6 +317,35 @@ declare class AgentKernel {
178
317
  * ```
179
318
  */
180
319
  sandbox(name: string, opts?: CreateSandboxOptions): Promise<SandboxSession>;
320
+ /**
321
+ * Create a sandboxed browser session with automatic cleanup.
322
+ *
323
+ * Creates a sandbox with Chromium pre-installed via Playwright.
324
+ * Use `goto()`, `screenshot()`, and `evaluate()` to interact with web pages.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * await using browser = await client.browser("my-browser");
329
+ * const page = await browser.goto("https://example.com");
330
+ * console.log(page.title, page.links);
331
+ * // sandbox auto-removed when scope exits
332
+ * ```
333
+ */
334
+ browser(name: string, opts?: {
335
+ memory_mb?: number;
336
+ }): Promise<BrowserSession>;
337
+ /** Extend a sandbox's TTL. Returns the new expiry time. */
338
+ extendTtl(name: string, opts: ExtendTtlOptions): Promise<ExtendTtlResponse>;
339
+ /** List all snapshots. */
340
+ listSnapshots(): Promise<SnapshotMeta[]>;
341
+ /** Take a snapshot of a sandbox. */
342
+ takeSnapshot(opts: TakeSnapshotOptions): Promise<SnapshotMeta>;
343
+ /** Get info about a snapshot. */
344
+ getSnapshot(name: string): Promise<SnapshotMeta>;
345
+ /** Delete a snapshot. */
346
+ deleteSnapshot(name: string): Promise<void>;
347
+ /** Restore a sandbox from a snapshot. */
348
+ restoreSnapshot(name: string): Promise<SandboxInfo>;
181
349
  private headers;
182
350
  private fetch;
183
351
  private request;
@@ -216,4 +384,4 @@ declare class StreamError extends AgentKernelError {
216
384
  constructor(message?: string);
217
385
  }
218
386
 
219
- export { AgentKernel, AgentKernelError, type AgentKernelOptions, type ApiResponse, AuthError, type CreateSandboxOptions, NetworkError, NotFoundError, type RunOptions, type RunOutput, type SandboxInfo, SandboxSession, type SandboxStatus, type SecurityProfile, ServerError, StreamError, type StreamEvent, type StreamEventType, ValidationError };
387
+ export { AgentKernel, AgentKernelError, type AgentKernelOptions, type ApiResponse, AuthError, BROWSER_SETUP_CMD, type BatchFileWriteResponse, BrowserSession, type CreateSandboxOptions, type DetachedCommand, type DetachedLogsResponse, type DetachedStatus, type ExecOptions, type ExtendTtlOptions, type ExtendTtlResponse, NetworkError, NotFoundError, type PageLink, type PageResult, type RunOptions, type RunOutput, type SandboxInfo, SandboxSession, type SandboxStatus, type SecurityProfile, ServerError, type SnapshotMeta, StreamError, type StreamEvent, type StreamEventType, type TakeSnapshotOptions, ValidationError };