How to build a resettable desktop VM environment for agents, the way OSWorld does
The gist
An OSWorld-style environment is a desktop VM image with a small HTTP server inside, a named snapshot of the clean desktop, and a per-task setup config. The harness restores the snapshot, runs setup, lets the agent act, then a script checks the VM's final state.
Words: VMForAI editors / Out / Fixed up / 7 min
An OSWorld-style environment is a resettable desktop computer that a harness drives over the network: a virtual machine image, a control server inside it, a clean snapshot, and a task format that says how to set up the desktop and how to check the result. OSWorld's repository is the clearest public example of the pattern, and its design choices answer most of the questions you meet when building your own. This page is about building the environment, not about the benchmark's tasks or scores.
What are the parts of a resettable desktop environment?
A resettable desktop environment has five parts.
Table: Parts of an OSWorld-style environment, with OSWorld's choices
| Part | What it is | OSWorld's choice |
|---|---|---|
| VM image | A desktop OS with the task applications installed | An Ubuntu desktop image, plus optional Windows |
| Control server | An HTTP service inside the VM that the harness calls | A Flask app started at boot as a system service |
| Clean snapshot | The saved state every task starts from | Snapshot named init_state by default |
| Task config | Setup steps for one task, and how to grade it | Download files, open files or tabs, change window size; then an evaluation function |
| Harness | Code outside the VM that restores, sets up, loops and grades | DesktopEnv, with reset() and step() |
Sources: OSWorld repository, desktop_env.py, server README and the OSWorld paper, read 2026-11-26.
Why put the desktop in a virtual machine?
Put the desktop in a VM for safety, reset and scale. The paper says a "Virtual machine offers a safe isolated environment", "The snapshot feature also enables efficient reset of the virtual environment", and "Multiple virtual machines can run simultaneously on a single host machine, thereby parallelizing training and evaluation" (OSWorld paper, section 2.2, read 2026-11-26).
For good speed, the host needs hardware virtualisation. The repository's check is egrep -c '(vmx|svm)' /proc/cpuinfo: "If the return value is greater than zero, the processor should be able to support" it (OSWorld repository, read 2026-11-26).
What should the server inside the VM expose?
The server inside the VM should expose everything the harness and the grader need, and nothing else. OSWorld's server is a useful checklist (server main.py, read 2026-11-26):
Table: Control server endpoints in OSWorld's VM server (selection)
| Need | Endpoint |
|---|---|
| Observe | GET /screenshot (PNG, with the cursor drawn), GET /accessibility (tree as XML), POST /screen_size, GET /cursor_position |
| Act and set up | POST /execute, POST /run_python, POST /run_bash_script, POST /setup/launch, POST /setup/open_file, POST /setup/activate_window, POST /setup/close_window |
| Files | POST /setup/upload, POST /setup/download_file, POST /file, POST /list_directory |
| Record | POST /start_recording, POST /end_recording (FFmpeg) |
Source: OSWorld server main.py, read 2026-11-26.
On Linux the server takes screenshots with pyautogui.screenshot() and pastes the cursor image on top; agents act through pyautogui, OSWorld's default action space. An endpoint that runs arbitrary commands is a full remote shell, so the server's port must be reachable only from the harness. OSWorld's defaults are port 5000 for the server, 9222 for the browser's debugging port, 8006 for VNC and 8080 for a media player (desktop_env.py, read 2026-11-26).
How should the VM image be prepared?
Prepare the image once, with every setting that would otherwise vary between runs fixed. OSWorld's server README lists its steps (read 2026-11-26):
- Install the server files and their packages; the README lists
python3-tk,python3-dev,gnome-screenshot,wmctrl,ffmpeg,socatandxclip, plus the Python requirements. - Install it as a system service that "automatically starts at boot time".
- Set the screen: "The required screen resolution for the virtual machine is 1920x1080 in OSWorld."
- Switch the session from Wayland to Xorg, and check with
echo $XDG_SESSION_TYPE. - Turn on automatic login for the desktop user.
- Set screen blank to never and automatic suspend to off.
Then shut down and take the snapshot. Each of these steps removes a way for the same task to start differently: a lock screen, a sleeping display, a different screen size or an input tool that cannot reach a Wayland session.
How does reset work between tasks?
Reset works by reverting the VM to its named snapshot before each task. In OSWorld's harness, DesktopEnv takes snapshot_name (default "init_state"), and reset() reverts only "if environment has been used (step/setup)", an optimisation the code says is "especially important for cloud providers". The code also notes that setup "may mutate the guest before failing", so a failed setup must still trigger a restore before the next attempt (desktop_env.py, read 2026-11-26).
The order for each task:
- Restore the clean snapshot (or skip if the VM is still clean).
- Run the task's setup: the paper describes downloading files or scripts, then running commands to "open files or tabs, change the window size, etc." (section 2.2.2).
- Run the agent loop: screenshot, model, action, pause. OSWorld's
stepwaits two seconds after each action by default (pause=2). - Post-process: the paper's task manager does "file saving, or reopening certain apps" before grading.
- Grade with a script that reads the VM's final state through the server.
How do I run many environments at once?
Run many environments by giving each its own VM, server port and snapshot, and limiting how many run per host. OSWorld's parallel example runs its multi-environment script with --num_envs 10 (OSWorld repository, read 2026-11-26). The constraint is the host's memory and processors: each VM needs the full memory of a desktop, and our resource sizing page has the figures to start from.
What goes wrong when building one, and how is it guarded against?
Most of what goes wrong is a mismatch between the saved image and the harness code, and the guard is to save a clean state only after a check passes on it.
Promigence is a worked example of that guard for its snapshots: you declare a container image, setup steps and a verify command, the snapshot is stored only if verification passes, and it is named by a hash of its contents, so a later run can start from exactly the same state (Promigence FAQ and quickstart, read 2026-11-26). The same check can run again as each task starts: --verify-each will "Re-run the snapshot's verify command in each sandbox before CMD runs", and the FAQ adds that a snapshot "is kept until you delete it" (Promigence CLI reference and FAQ, read 2026-11-26).
Other hosted services decide in their own ways when a prepared state is saved, and how long it is kept (read 2026-11-26):
- AWS: Amazon Bedrock AgentCore Runtime V2 "takes the snapshot when your agent's health check first passes", and if the health check does not pass in time, "the create or update fails with a health check error" (AgentCore Runtime documentation).
- Daytona: a snapshot's base image "must include either a tag or a digest", with the
latest,ltsandstabletags not supported, and a snapshot whose creation or build fails is marked Error or Build Failed (Daytona snapshots documentation). - E2B: a template's ready command "is executed in an infinite loop until it returns a successful exit code 0", and only then is the snapshot created (E2B start and ready command documentation).
- Google Cloud: a Pod snapshot for Agent Sandbox on GKE is taken by a manual trigger or when "the sandboxed application itself signals when it's ready to be saved", and GKE "restores a Pod only from a snapshot that's ready" (GKE Pod snapshots documentation).
- Modal: a snapshot is taken when your code asks for one; filesystem snapshots are kept for 30 days by default unless you set another TTL, and memory snapshots, an experimental feature, expire 7 days after creation (Modal Sandbox snapshots guide).
In a do-it-yourself desktop VM, the same check is a call to the in-VM server's version endpoint plus one screenshot with the pointer in it, run before the snapshot is taken. It catches these mismatches:
- A stale server in the image. The OSWorld README warns that the published Ubuntu image "may contain an older guest server than this checkout" and that updating the host code "does not update the guest screenshot handler". Version the image and the harness together.
- A missing cursor. A comment in the server notes that on virtual machines "the cursor is not captured", which is why it pastes the cursor image itself. Check a screenshot for the pointer before trusting the image.
- A dirty start. Skipping the restore after a failed setup leaves half-done changes in the next task.
What we read for this article
- OSWorld repository, read 2026-11-26
- OSWorld desktop_env.py, read 2026-11-26
- OSWorld server README, read 2026-11-26
- OSWorld server main.py, read 2026-11-26
- OSWorld paper (arXiv 2404.07972), read 2026-11-26
- Promigence FAQ, https://www.promigence.ai/faq, read 2026-11-26
- Promigence quickstart, https://www.promigence.ai/docs/quickstart, read 2026-11-26
- Promigence CLI reference, https://www.promigence.ai/docs/cli, read 2026-11-26
- Amazon Bedrock AgentCore Runtime documentation, read 2026-11-26
- Daytona snapshots documentation, read 2026-11-26
- E2B start and ready command documentation, read 2026-11-26
- GKE Pod snapshots documentation, read 2026-11-26
- Modal Sandbox snapshots guide, read 2026-11-26
Asked
What does the server inside the VM do?
It is the harness's only way in. In OSWorld it returns screenshots, the accessibility tree and the screen size, runs commands and scripts, uploads and downloads files, opens and activates windows, and starts and stops screen recording, all over HTTP.
How is the VM reset between tasks?
By reverting to a named snapshot of the clean desktop. OSWorld's default snapshot is called init_state, and its reset skips the revert when the environment has not been used since the last one.
Why use a VM instead of a container for a desktop agent?
A VM can run any desktop operating system, including Windows, and gives a full machine to break and restore. The OSWorld paper names safety, reset by snapshot and running several VMs on one host as its reasons.
What screen settings does the OSWorld image use?
Its server README says the required resolution is 1920x1080, the session must use Xorg rather than Wayland, the user logs in automatically, and screen blanking and automatic suspend are turned off.