// Run shell commands inside the VM. import { AgentOs } from "@rivet-dev/agentos-core"; const vm = await AgentOs.create(); // Simple commandsconst echo = await vm.exec("echo 'Hello from the shell!'");console.log(echo.stdout); // Pipesconst piped = await vm.exec("echo 'hello world' | tr a-z A-Z");console.log("Piped:", piped.stdout.trim()); // File manipulationawait vm.exec("echo 'line 1' > /tmp/test.txt");await vm.exec("echo 'line 2' >> /tmp/test.txt");await vm.exec("echo 'line 3' >> /tmp/test.txt"); const cat = await vm.exec("cat /tmp/test.txt");console.log("File contents:");console.log(cat.stdout); // grepconst grep = await vm.exec("grep '2' /tmp/test.txt");console.log("Grep result:", grep.stdout.trim()); console.log("Exit code:", grep.exitCode); await vm.dispose();
// Run shell commands inside the VM.
import { AgentOs } from "@rivet-dev/agentos-core";
const vm = await AgentOs.create();
// Simple commands
const echo = await vm.exec("echo 'Hello from the shell!'");
console.log(echo.stdout);
// Pipes
const piped = await vm.exec("echo 'hello world' | tr a-z A-Z");
console.log("Piped:", piped.stdout.trim());
// File manipulation
await vm.exec("echo 'line 1' > /tmp/test.txt");
await vm.exec("echo 'line 2' >> /tmp/test.txt");
await vm.exec("echo 'line 3' >> /tmp/test.txt");
const cat = await vm.exec("cat /tmp/test.txt");
console.log("File contents:");
console.log(cat.stdout);
// grep
const grep = await vm.exec("grep '2' /tmp/test.txt");
console.log("Grep result:", grep.stdout.trim());
console.log("Exit code:", grep.exitCode);
await vm.dispose();