beetlebug▾
/

Run an agent in a VM

At the level vm, each command of the agent runs in a new Linux guest. The guest sees only the work folder, has no network unless --net, and ends after the command. This guide runs one agent at the level vm from the start to the report.

You need: Linux with KVM (/dev/kvm), a ztcl with the capability vm, and the guest image ztcl-guest.

1. Install the guest image

The image is the GitHub release vm-image-v1 of ztcl, signed. A release runner of ztcl downloads and installs it:

cat > fetch.tcl <<'TCL'
puts [ztcl::vm image fetch]
puts [ztcl::vm image list]
TCL
ztcl --allow vm,socket --net any fetch.tcl
name ztcl-guest counter 1 status current
{name ztcl-guest releases 1 current 1}

Note

A ztcl that you build from source with zig build has no download, and image fetch fails with ZTCL VM UNAVAILABLE: this program gives ztcl::vm no download. Use a release runner for the fetch, or build with -Dvm-fetch. The store of images is the same for each runner of the user.

2. Start the agent

jcode start --dir vm-demo --model us.amazon.ergo-1.0 --brief brief-vm.md \
    --isolation vm --run all --mem 256M --env GREETING=hi --check 'test=sh test.sh'
jcode wait a1 --timeout 600
a1
a1 done vm turns 6/40 tokens 16740 (in2774 out3089 cr7099 cw3778) us.amazon.ergo-1.0 vm-demo | the agent gave its report

The brief asked for a script, a test, and the output of two commands in the guest:

jcode read a1
11 tool: run {"command":"chmod +x wordfreq.sh test.sh && ./test.sh; echo \"test exit code: $?\""}
12 result: ok: exit 0 ok - counts and ordering ok - lower case and alphabetical tie-break test exit code: 0
13 tool: run {"command":"uname -r; echo \"$GREETING\""}
14 result: ok: exit 0 7.3.6 hi
16 tool: check {"name":"test"}
17 result: ok: exit 0 ok - counts and ordering ok - lower case and alphabetical tie-break

The run took 19 s and 6 model calls. A guest starts in less than one second, so the time of the tools is small next to the model calls.

What a command sees in the guest

Item In the guest
The work folder /mnt/share, the current folder of the command. A write there is a write on the host.
Programs busybox and its applets (sh, awk, sed, grep, sort, tr, and more) in /bin. No git, no compiler, no Python.
#!/bin/sh Works.
The rest of the root Read-only. /tmp is a tmpfs.
The user root of the guest.
Memory --mem, else 512 MB.
Network None. With --net, NAT to the network of the host.
Variables The variables of --env.
State between commands None, but the files of the work folder. Each command has a new guest.

Limits

Isolation has what the level protects.