File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 "tools" : " node --import tsx src/tools.ts" ,
1616 "agent-session" : " node --import tsx src/agent-session.ts" ,
1717 "sandbox" : " node --import tsx src/sandbox.ts" ,
18+ "nodejs" : " node --import tsx src/nodejs.ts" ,
19+ "python" : " node --import tsx src/python.ts" ,
20+ "bash" : " node --import tsx src/bash.ts" ,
1821 "s3-filesystem" : " node --import tsx src/s3-filesystem.ts"
1922 },
2023 "dependencies" : {
2528 "@rivet-dev/agent-os-git" : " link:../../registry/software/git" ,
2629 "@rivet-dev/agent-os-pi" : " link:../../registry/agent/pi" ,
2730 "@rivet-dev/agent-os-s3" : " link:../../registry/file-system/s3" ,
31+ "pyodide" : " ^0.28.3" ,
2832 "zod" : " ^3.25.0"
2933 },
3034 "devDependencies" : {
Original file line number Diff line number Diff line change 1+ // Run shell commands inside the VM.
2+
3+ import { AgentOs } from "@rivet-dev/agent-os-core" ;
4+ import common from "@rivet-dev/agent-os-common" ;
5+
6+ const vm = await AgentOs . create ( { software : [ common ] } ) ;
7+
8+ // Simple commands
9+ const echo = await vm . exec ( "echo 'Hello from the shell!'" ) ;
10+ console . log ( echo . stdout ) ;
11+
12+ // Pipes
13+ const piped = await vm . exec ( "echo 'hello world' | tr a-z A-Z" ) ;
14+ console . log ( "Piped:" , piped . stdout . trim ( ) ) ;
15+
16+ // File manipulation
17+ await vm . exec ( "echo 'line 1' > /tmp/test.txt" ) ;
18+ await vm . exec ( "echo 'line 2' >> /tmp/test.txt" ) ;
19+ await vm . exec ( "echo 'line 3' >> /tmp/test.txt" ) ;
20+
21+ const cat = await vm . exec ( "cat /tmp/test.txt" ) ;
22+ console . log ( "File contents:" ) ;
23+ console . log ( cat . stdout ) ;
24+
25+ // grep
26+ const grep = await vm . exec ( "grep '2' /tmp/test.txt" ) ;
27+ console . log ( "Grep result:" , grep . stdout . trim ( ) ) ;
28+
29+ console . log ( "Exit code:" , grep . exitCode ) ;
30+
31+ await vm . dispose ( ) ;
Original file line number Diff line number Diff line change 1+ // Run a Node.js script inside the VM that does filesystem operations.
2+
3+ import { AgentOs } from "@rivet-dev/agent-os-core" ;
4+ import common from "@rivet-dev/agent-os-common" ;
5+
6+ const vm = await AgentOs . create ( { software : [ common ] } ) ;
7+
8+ await vm . writeFile (
9+ "/tmp/demo.mjs" ,
10+ `
11+ import fs from "fs";
12+ import path from "path";
13+
14+ // Create a directory and write files
15+ fs.mkdirSync("/project/src", { recursive: true });
16+ fs.writeFileSync("/project/src/index.js", 'console.log("hello");');
17+ fs.writeFileSync("/project/README.md", "# My Project");
18+
19+ // Read them back
20+ const files = fs.readdirSync("/project", { recursive: true });
21+ console.log("Files:", files);
22+
23+ const content = fs.readFileSync("/project/src/index.js", "utf8");
24+ console.log("index.js:", content);
25+
26+ const stat = fs.statSync("/project/README.md");
27+ console.log("README size:", stat.size, "bytes");
28+ ` ,
29+ ) ;
30+
31+ const result = await vm . exec ( "node /tmp/demo.mjs" ) ;
32+ console . log ( result . stdout ) ;
33+ console . log ( "Exit code:" , result . exitCode ) ;
34+
35+ await vm . dispose ( ) ;
Original file line number Diff line number Diff line change 1+ // Run a Python script inside the VM that does filesystem operations.
2+
3+ import { AgentOs } from "@rivet-dev/agent-os-core" ;
4+ import common from "@rivet-dev/agent-os-common" ;
5+
6+ const vm = await AgentOs . create ( { software : [ common ] } ) ;
7+
8+ await vm . writeFile (
9+ "/tmp/demo.py" ,
10+ `
11+ import os
12+ import json
13+
14+ # Create a directory and write files
15+ os.makedirs("/project/src", exist_ok=True)
16+
17+ with open("/project/src/main.py", "w") as f:
18+ f.write("print('hello')")
19+
20+ with open("/project/README.md", "w") as f:
21+ f.write("# My Project")
22+
23+ # Read them back
24+ files = os.listdir("/project")
25+ print("Files:", files)
26+
27+ with open("/project/src/main.py") as f:
28+ print("main.py:", f.read())
29+
30+ stat = os.stat("/project/README.md")
31+ print("README size:", stat.st_size, "bytes")
32+ ` ,
33+ ) ;
34+
35+ const result = await vm . exec ( "python /tmp/demo.py" ) ;
36+ console . log ( result . stdout ) ;
37+ console . log ( "Exit code:" , result . exitCode ) ;
38+
39+ await vm . dispose ( ) ;
You can’t perform that action at this time.
0 commit comments