@rivet-dev/agentos-sandbox 0.0.0-agentos-dylib-plugin.473700e
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 +4 -0
- package/dist/index.js +2 -0
- package/dist/toolkit.d.ts +14 -0
- package/dist/toolkit.js +191 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox toolkit exposing process management and command execution
|
|
3
|
+
* as host tools for agents running inside an agentOS VM.
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolKit } from "@rivet-dev/agentos-core";
|
|
6
|
+
import type { SandboxAgent } from "sandbox-agent";
|
|
7
|
+
export interface SandboxToolkitOptions {
|
|
8
|
+
/** A connected SandboxAgent client instance. */
|
|
9
|
+
client: SandboxAgent;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a ToolKit that exposes sandbox process management operations.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createSandboxToolkit(options: SandboxToolkitOptions): ToolKit;
|
package/dist/toolkit.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox toolkit exposing process management and command execution
|
|
3
|
+
* as host tools for agents running inside an agentOS VM.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
/** Host tool type alias for convenience. */
|
|
7
|
+
function hostTool(def) {
|
|
8
|
+
return def;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a ToolKit that exposes sandbox process management operations.
|
|
12
|
+
*/
|
|
13
|
+
export function createSandboxToolkit(options) {
|
|
14
|
+
const { client } = options;
|
|
15
|
+
return {
|
|
16
|
+
name: "sandbox",
|
|
17
|
+
description: "Execute commands and manage processes in a remote sandbox environment.",
|
|
18
|
+
tools: {
|
|
19
|
+
"run-command": hostTool({
|
|
20
|
+
description: "Run a command synchronously in the sandbox and return its stdout, stderr, and exit code.",
|
|
21
|
+
inputSchema: z.object({
|
|
22
|
+
command: z
|
|
23
|
+
.string()
|
|
24
|
+
.describe("The command to execute (e.g. 'ls', 'python3')."),
|
|
25
|
+
args: z
|
|
26
|
+
.array(z.string())
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Arguments to pass to the command."),
|
|
29
|
+
cwd: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("Working directory for the command."),
|
|
33
|
+
env: z
|
|
34
|
+
.record(z.string(), z.string())
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Additional environment variables."),
|
|
37
|
+
timeoutMs: z
|
|
38
|
+
.number()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Maximum execution time in milliseconds."),
|
|
41
|
+
}),
|
|
42
|
+
timeout: 120_000,
|
|
43
|
+
execute: async (input) => {
|
|
44
|
+
const result = await client.runProcess({
|
|
45
|
+
command: input.command,
|
|
46
|
+
args: input.args,
|
|
47
|
+
cwd: input.cwd,
|
|
48
|
+
env: input.env,
|
|
49
|
+
timeoutMs: input.timeoutMs,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
stdout: result.stdout,
|
|
53
|
+
stderr: result.stderr,
|
|
54
|
+
exitCode: result.exitCode,
|
|
55
|
+
timedOut: result.timedOut,
|
|
56
|
+
durationMs: result.durationMs,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
"create-process": hostTool({
|
|
61
|
+
description: "Start a long-running background process in the sandbox. Returns a process ID for later management.",
|
|
62
|
+
inputSchema: z.object({
|
|
63
|
+
command: z.string().describe("The command to execute."),
|
|
64
|
+
args: z
|
|
65
|
+
.array(z.string())
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("Arguments to pass to the command."),
|
|
68
|
+
cwd: z
|
|
69
|
+
.string()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe("Working directory for the process."),
|
|
72
|
+
env: z
|
|
73
|
+
.record(z.string(), z.string())
|
|
74
|
+
.optional()
|
|
75
|
+
.describe("Additional environment variables."),
|
|
76
|
+
}),
|
|
77
|
+
execute: async (input) => {
|
|
78
|
+
const proc = await client.createProcess({
|
|
79
|
+
command: input.command,
|
|
80
|
+
args: input.args,
|
|
81
|
+
cwd: input.cwd,
|
|
82
|
+
env: input.env,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
id: proc.id,
|
|
86
|
+
command: proc.command,
|
|
87
|
+
args: proc.args,
|
|
88
|
+
status: proc.status,
|
|
89
|
+
pid: proc.pid,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
"list-processes": hostTool({
|
|
94
|
+
description: "List all processes running in the sandbox.",
|
|
95
|
+
inputSchema: z.object({}),
|
|
96
|
+
execute: async () => {
|
|
97
|
+
const result = await client.listProcesses();
|
|
98
|
+
return {
|
|
99
|
+
processes: result.processes.map((p) => ({
|
|
100
|
+
id: p.id,
|
|
101
|
+
command: p.command,
|
|
102
|
+
args: p.args,
|
|
103
|
+
status: p.status,
|
|
104
|
+
exitCode: p.exitCode,
|
|
105
|
+
pid: p.pid,
|
|
106
|
+
})),
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
"stop-process": hostTool({
|
|
111
|
+
description: "Gracefully stop a running process in the sandbox.",
|
|
112
|
+
inputSchema: z.object({
|
|
113
|
+
id: z.string().describe("The process ID to stop."),
|
|
114
|
+
}),
|
|
115
|
+
execute: async (input) => {
|
|
116
|
+
const proc = await client.stopProcess(input.id);
|
|
117
|
+
return {
|
|
118
|
+
id: proc.id,
|
|
119
|
+
status: proc.status,
|
|
120
|
+
exitCode: proc.exitCode,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
"kill-process": hostTool({
|
|
125
|
+
description: "Forcefully kill a running process in the sandbox.",
|
|
126
|
+
inputSchema: z.object({
|
|
127
|
+
id: z.string().describe("The process ID to kill."),
|
|
128
|
+
}),
|
|
129
|
+
execute: async (input) => {
|
|
130
|
+
const proc = await client.killProcess(input.id);
|
|
131
|
+
return {
|
|
132
|
+
id: proc.id,
|
|
133
|
+
status: proc.status,
|
|
134
|
+
exitCode: proc.exitCode,
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
"get-process-logs": hostTool({
|
|
139
|
+
description: "Get stdout/stderr logs from a sandbox process.",
|
|
140
|
+
inputSchema: z.object({
|
|
141
|
+
id: z.string().describe("The process ID."),
|
|
142
|
+
stream: z
|
|
143
|
+
.enum(["stdout", "stderr", "combined"])
|
|
144
|
+
.optional()
|
|
145
|
+
.describe("Which output stream to read. Defaults to combined."),
|
|
146
|
+
tail: z
|
|
147
|
+
.number()
|
|
148
|
+
.optional()
|
|
149
|
+
.describe("Only return the last N log entries."),
|
|
150
|
+
}),
|
|
151
|
+
execute: async (input) => {
|
|
152
|
+
const result = await client.getProcessLogs(input.id, {
|
|
153
|
+
stream: input.stream,
|
|
154
|
+
tail: input.tail,
|
|
155
|
+
});
|
|
156
|
+
return {
|
|
157
|
+
logs: result.entries.map((e) => {
|
|
158
|
+
// The sandbox-agent SDK returns log data as base64. Decode it
|
|
159
|
+
// so callers receive plain text.
|
|
160
|
+
let text = e.data;
|
|
161
|
+
if (e.encoding === "base64") {
|
|
162
|
+
text = Buffer.from(e.data, "base64").toString("utf-8");
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
data: text,
|
|
166
|
+
stream: e.stream,
|
|
167
|
+
timestampMs: e.timestampMs,
|
|
168
|
+
};
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
}),
|
|
173
|
+
"send-input": hostTool({
|
|
174
|
+
description: "Send text input to an interactive sandbox process via stdin.",
|
|
175
|
+
inputSchema: z.object({
|
|
176
|
+
id: z.string().describe("The process ID."),
|
|
177
|
+
data: z.string().describe("The text to send to the process stdin."),
|
|
178
|
+
}),
|
|
179
|
+
execute: async (input) => {
|
|
180
|
+
// Encode the text as base64 for the sandbox-agent API.
|
|
181
|
+
const encoded = Buffer.from(input.data, "utf-8").toString("base64");
|
|
182
|
+
await client.sendProcessInput(input.id, {
|
|
183
|
+
data: encoded,
|
|
184
|
+
encoding: "base64",
|
|
185
|
+
});
|
|
186
|
+
return { sent: true };
|
|
187
|
+
},
|
|
188
|
+
}),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rivet-dev/agentos-sandbox",
|
|
3
|
+
"version": "0.0.0-agentos-dylib-plugin.473700e",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"check-types": "tsc --noEmit",
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@rivet-dev/agentos-core": "0.0.0-agentos-dylib-plugin.473700e",
|
|
25
|
+
"@secure-exec/sandbox": "0.3.0",
|
|
26
|
+
"sandbox-agent": "^0.4.2",
|
|
27
|
+
"zod": "^4.1.11"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@agent-os-pkgs/common": "0.0.0-split-runtime-preview.5d46b14",
|
|
31
|
+
"@types/node": "^22.10.2",
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^2.1.8"
|
|
34
|
+
}
|
|
35
|
+
}
|