mirror of
https://github.com/hanzoai/vm.git
synced 2026-10-01 00:47:56 +00:00
Crates keep their history: vm (lib, was shuru-vm), hanzo-vm (CLI package and binary, was shuru-cli), vm-guest, vm-proto, vm-proxy, vm-sdk, vm-store, vm-darwin, vm-linux; all at 0.1.0, Apache-2.0, hanzoai/vm. Config is vm.json, data lives in ~/.hanzo/vm (HANZO_VM_HOME), env vars are HANZO_VM_*, the guest runs as /usr/bin/vm-guest, and assets download from hanzoai/vm releases. The TypeScript SDK is @hanzo/vm. NOTICE credits shuru as the origin. prepare-rootfs.sh builds the image natively on arm64 Linux with mke2fs -d and re-execs in Docker only on macOS. Includes rustfmt over the tree and fixes for clippy 1.98 lints. Co-authored-by: Hanzo Dev <[email protected]>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { resolve } from "node:path";
|
|
import { Sandbox } from "../src/sandbox";
|
|
|
|
const HANZO_VM_BIN = resolve(import.meta.dir, "../../../target/debug/hanzo-vm");
|
|
|
|
async function main() {
|
|
console.log("starting sandbox...");
|
|
const sb = await Sandbox.start({ bin: HANZO_VM_BIN });
|
|
|
|
try {
|
|
// exec: run a command
|
|
const result = await sb.exec("echo 'hello from the VM!'");
|
|
console.log("exec stdout:", result.stdout.trim());
|
|
console.log("exec exit code:", result.exitCode);
|
|
|
|
// exec: get system info
|
|
const uname = await sb.exec("uname -a");
|
|
console.log("uname:", uname.stdout.trim());
|
|
|
|
// writeFile + readFile roundtrip
|
|
const msg = "written from the SDK\n";
|
|
await sb.writeFile("/tmp/example.txt", msg);
|
|
const read = await sb.readFile("/tmp/example.txt");
|
|
const content = new TextDecoder().decode(read);
|
|
console.log("file roundtrip:", content.trim());
|
|
|
|
// exec: verify the file from the shell side
|
|
const cat = await sb.exec("cat /tmp/example.txt");
|
|
console.log("cat from VM:", cat.stdout.trim());
|
|
|
|
console.log("all good!");
|
|
} finally {
|
|
await sb.stop();
|
|
console.log("sandbox stopped.");
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|