Run AI Agents in Disposable Ubuntu VMs
Combine VMRelay with agent-sudo when a trusted coding or administration agent needs root in a test environment. VMRelay manages the remote KVM guest; agent-sudo issues temporary root grants inside that guest. Use a fresh Ubuntu VM for each experiment and keep production credentials out of it.
Standalone tools. Apache licensed and free for commercial use. No SimpleHelp licence required.
What boundary does this create?
The VM separates guest operating-system changes from your workstation and host. The token belongs inside the guest, so it does not grant root on the KVM host. This is a workflow using two separate tools, not a built-in agent sandbox or an automatic guarantee of containment.
Decide what the guest may reach before launching the agent. Libvirt’s default NAT permits outbound access, potentially including internal services. Use an approved network policy for the experiment. Do not attach production disks, broad credentials, shared home directories or workstation service mappings that the task does not need.
What should I prepare?
- A tested VMRelay host and workstation, with capacity for a separate test guest.
- Ubuntu 24.04 or 26.04 amd64 installation media for an x86-64 KVM host. The guest must use systemd and a supported local sudo policy for agent-sudo.
- A normal administrator account inside the guest and a separate existing non-root account for the agent. Keep the administrator connection available.
- Test-only project files and narrowly scoped, disposable credentials where the task needs external access. The agent runtime and any model service are configured separately.
How do I run the experiment?
- Follow the remote KVM guide. In VMRelay, create a new Ubuntu guest and install the guest OS through its browser console.
- Inside the guest, create the accounts required by your normal Linux administration process. Install the agent runtime there and copy in only the files needed for the test.
- Install agent-sudo inside the guest using its canonical instructions. Do not grant access on your workstation or KVM host for a guest task.
- As the guest administrator, run
agent-sudo agent 10, using the guest’s existing recipient account. Privately deliver the resulting handoff to the agent running as that account. - Have the agent test
agent-sudo run -- /usr/bin/id </dev/nullusing the hidden token prompt, or a correctly configured trusted launcher. Review the planned work before allowing it to proceed. - After the task, revoke the grant and verify that a fresh privileged command is refused. Review the result and export only files you intend to keep.
Expected result: privileged changes take place inside the disposable guest. Root access remains full root there, including the ability to create persistence during the grant.
How do I clean up after the test?
- Review exported files and changes before copying them into a trusted working tree. Treat guest-generated scripts and binaries as untrusted until reviewed.
- Revoke test credentials or API tokens used by the experiment. Revoking an agent-sudo token does not revoke external credentials.
- Stop the VM and remove the disposable guest and its unwanted disks through the VM management controls. Check what is being deleted before confirming.
- For the next experiment, create a fresh VM from trusted installation media or an independently maintained clean baseline. Do not assume a reboot removes guest persistence.
There is no automatic reset in this procedure. VMRelay’s private/shared visibility metadata is not a security boundary against host users with broad sudo or libvirt access. Keep the host and virtualisation stack maintained.
What if the agent cannot use its token?
- Confirm that it runs as the granted account inside the correct guest. Tokens are bound to account, machine and current boot.
- Check whether the grant expired or the VM rebooted. Issue a fresh grant only after reviewing why it is needed.
- If the runtime has no terminal, use a launcher that supports private file-descriptor token delivery. Do not paste tokens into command arguments or environment variables.
Your questions, answered
Does VMRelay automatically sandbox an AI coding agent?
No. It creates and manages VMs. You choose where the agent runs, what data enters the guest and what networks and credentials it can use.
Does token expiry stop everything the agent started?
No. It blocks new root command admissions through agent-sudo. Existing root processes and persistent changes can remain, so review the work and discard the test environment afterwards.
Related guides and tools
Manage Remote KVM VMs from macOS or Linux
Manage KVM virtual machines on an existing Ubuntu or Debian server from macOS or Linux. Use VMRelay over SSH, with browser consoles and no web admin port.
Read guideGive AI Coding Agents Temporary Root Access
Give a trusted AI coding agent temporary root access on Ubuntu without sharing an admin password. Grant, check and revoke tokens with agent-sudo.
Read guideVMRelay documentation and downloads · agent-sudo documentation and downloads