@hasna/sandboxes 0.1.25 → 0.1.27
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 +1 -1
- package/dist/index.js +43 -0
- package/dist/sdk.d.ts +32 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { BUILTIN_IMAGES, resolveImage, getBuiltinImageSetupScript } from "./lib/
|
|
|
15
15
|
export { getProvider } from "./providers/index.js";
|
|
16
16
|
export type { SandboxProvider, ProviderSandbox, CreateSandboxOpts, ExecOptions } from "./providers/types.js";
|
|
17
17
|
export { SandboxesSDK, createSandboxesSDK, } from "./sdk.js";
|
|
18
|
-
export type { ExecCommandResult, ProviderFactory, RunAgentOptions, SandboxesSDKOptions, WaitForSessionOptions, } from "./sdk.js";
|
|
18
|
+
export type { ExecCommandResult, ProviderFactory, RunAgentOptions, RunCommandInSandboxOptions, RunCommandInSandboxResult, RunCommandInSandboxUploadOptions, SandboxesSDKOptions, OneShotSandboxCleanup, WaitForSessionOptions, } from "./sdk.js";
|
|
19
19
|
export { createStreamCollector, addStreamListener, emitLifecycleEvent } from "./lib/stream.js";
|
|
20
20
|
export { getAgentDriver, listAgentDrivers } from "./lib/agents/index.js";
|
|
21
21
|
export type { AgentDriver } from "./lib/agents/types.js";
|
package/dist/index.js
CHANGED
|
@@ -11643,6 +11643,49 @@ class SandboxesSDK {
|
|
|
11643
11643
|
emitLifecycleEvent(sandbox.id, `uploaded ${localDir} -> ${remoteDir} (${result.bytes} bytes)`);
|
|
11644
11644
|
return result;
|
|
11645
11645
|
}
|
|
11646
|
+
async runCommandInSandbox(input) {
|
|
11647
|
+
const cleanupMode = input.cleanup ?? "delete";
|
|
11648
|
+
const sandbox = await this.createSandbox({
|
|
11649
|
+
provider: input.provider,
|
|
11650
|
+
name: input.name,
|
|
11651
|
+
image: input.image,
|
|
11652
|
+
timeout: input.sandboxTimeout,
|
|
11653
|
+
env_vars: input.sandboxEnvVars,
|
|
11654
|
+
config: input.config,
|
|
11655
|
+
project_id: input.projectId
|
|
11656
|
+
});
|
|
11657
|
+
let upload;
|
|
11658
|
+
let exec;
|
|
11659
|
+
try {
|
|
11660
|
+
if (input.upload) {
|
|
11661
|
+
upload = await this.uploadDir(sandbox.id, input.upload.localDir, input.upload.remoteDir, { exclude: input.upload.exclude });
|
|
11662
|
+
}
|
|
11663
|
+
exec = await this.execCommand(sandbox.id, input.command, {
|
|
11664
|
+
cwd: input.cwd ?? input.upload?.remoteDir,
|
|
11665
|
+
env: input.callEnvVars,
|
|
11666
|
+
timeout: input.commandTimeoutMs,
|
|
11667
|
+
onStdout: input.onStdout,
|
|
11668
|
+
onStderr: input.onStderr
|
|
11669
|
+
});
|
|
11670
|
+
} finally {
|
|
11671
|
+
if (cleanupMode === "delete") {
|
|
11672
|
+
await this.deleteSandbox(sandbox.id);
|
|
11673
|
+
} else if (cleanupMode === "stop") {
|
|
11674
|
+
await this.stopSandbox(sandbox.id);
|
|
11675
|
+
}
|
|
11676
|
+
}
|
|
11677
|
+
if (!exec) {
|
|
11678
|
+
throw new Error("Sandbox command did not produce an execution result");
|
|
11679
|
+
}
|
|
11680
|
+
return {
|
|
11681
|
+
sandbox,
|
|
11682
|
+
session: exec.session,
|
|
11683
|
+
result: exec.result,
|
|
11684
|
+
upload,
|
|
11685
|
+
remoteDir: input.upload?.remoteDir,
|
|
11686
|
+
cleanup: cleanupMode === "delete" ? "deleted" : cleanupMode === "stop" ? "stopped" : "kept"
|
|
11687
|
+
};
|
|
11688
|
+
}
|
|
11646
11689
|
async runAgent(sandboxId, opts) {
|
|
11647
11690
|
const sandbox = this.requireProviderSandbox(sandboxId);
|
|
11648
11691
|
const provider = await this.getProvider(sandbox.provider);
|
package/dist/sdk.d.ts
CHANGED
|
@@ -15,6 +15,37 @@ export interface ExecCommandResult {
|
|
|
15
15
|
session: SandboxSession;
|
|
16
16
|
result: ExecResult;
|
|
17
17
|
}
|
|
18
|
+
export type OneShotSandboxCleanup = "delete" | "stop" | "keep";
|
|
19
|
+
export interface RunCommandInSandboxUploadOptions {
|
|
20
|
+
localDir: string;
|
|
21
|
+
remoteDir: string;
|
|
22
|
+
exclude?: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface RunCommandInSandboxOptions {
|
|
25
|
+
command: string;
|
|
26
|
+
provider?: SandboxProviderName;
|
|
27
|
+
name?: string;
|
|
28
|
+
image?: string;
|
|
29
|
+
sandboxTimeout?: number;
|
|
30
|
+
commandTimeoutMs?: number;
|
|
31
|
+
projectId?: string;
|
|
32
|
+
config?: Record<string, unknown>;
|
|
33
|
+
sandboxEnvVars?: Record<string, string>;
|
|
34
|
+
callEnvVars?: Record<string, string>;
|
|
35
|
+
cwd?: string;
|
|
36
|
+
upload?: RunCommandInSandboxUploadOptions;
|
|
37
|
+
cleanup?: OneShotSandboxCleanup;
|
|
38
|
+
onStdout?: (data: string) => void;
|
|
39
|
+
onStderr?: (data: string) => void;
|
|
40
|
+
}
|
|
41
|
+
export interface RunCommandInSandboxResult {
|
|
42
|
+
sandbox: Sandbox;
|
|
43
|
+
session: SandboxSession;
|
|
44
|
+
result: ExecResult;
|
|
45
|
+
upload?: UploadDirResult;
|
|
46
|
+
remoteDir?: string;
|
|
47
|
+
cleanup: "deleted" | "stopped" | "kept";
|
|
48
|
+
}
|
|
18
49
|
export interface RunAgentOptions {
|
|
19
50
|
agentType: AgentType;
|
|
20
51
|
prompt: string;
|
|
@@ -54,6 +85,7 @@ export declare class SandboxesSDK {
|
|
|
54
85
|
glob?: string;
|
|
55
86
|
}): Promise<FileInfo[]>;
|
|
56
87
|
uploadDir(sandboxId: string, localDir: string, remoteDir: string, opts?: UploadDirOptions): Promise<UploadDirResult>;
|
|
88
|
+
runCommandInSandbox(input: RunCommandInSandboxOptions): Promise<RunCommandInSandboxResult>;
|
|
57
89
|
runAgent(sandboxId: string, opts: RunAgentOptions): Promise<SandboxSession>;
|
|
58
90
|
getSession(sessionId: string): SandboxSession;
|
|
59
91
|
waitForSession(sessionId: string, opts?: WaitForSessionOptions): Promise<SandboxSession>;
|