TL;DR
Before you click a sketchy button on a website, your brain simulates what might happen next; most AI agents just click blindly and hope for the best. Code2World gives GUI agents human-like foresight by acting as a virtual sandbox that predicts the next screen—not by hallucinating blurry pixels or vague text descriptions, but by writing clean HTML code and rendering it. Plugging this 8B-parameter simulator into existing AI agents dramatically boosts their ability to navigate real-world apps without making irreversible mistakes.
What Problem Does This Paper Address?
Digital AI agents—models designed to use phones and computers on our behalf—operate mostly on impulse. Without the ability to mentally simulate the consequences of their actions, one wrong tap can lead to costly multi-step recovery or catastrophic, irreversible errors (like accidentally confirming a payment or deleting a file).
To give agents foresight, they need a world model: an internal simulator that predicts the next screen given the current screen and a proposed action. Existing attempts fall into two camps, and both hit a wall:
- Text-based models predict the next state in plain English. They capture semantic intent, but strip away crucial spatial layouts and visual cues.
- Pixel-based models use diffusion to paint the next screenshot directly. While visually rich, diffusion models struggle with discrete UI state jumps and notoriously garble fine-grained text and structural layouts.
The authors ask a simple, clever question: since user interfaces are natively built out of code, why not predict the next screen as renderable HTML? Symbolic code guarantees crisp text and structural control, while a standard browser engine turns it into a high-fidelity image for free.
Methods
Building Code2World (adapted from a Qwen3-VL-8B backbone) required bridging the gap between raw text tokens and rendered visual reality through a two-stage training pipeline, followed by a plug-and-play deployment setup.
- Cold-Start Supervised Fine-Tuning (SFT): Standard token-prediction training teaches the Vision-Language Model (VLM) basic HTML syntax and layout formatting. However, SFT alone is "blind" to what the code actually looks like once rendered.
- Render-Aware Reinforcement Learning (RARL): This is the core training innovation. Using Group Relative Policy Optimization (GRPO), the model generates multiple HTML candidates, renders them via a browser, and gets scored by a "VLM-as-a-Judge" on two fronts:
- Visual Semantic Reward ($R_{\text{sem}}$): Evaluates structural layout alignment against the ground truth (using a VLM rather than brittle pixel metrics like CLIP, so placeholder boxes for raw image assets aren't unfairly penalized).
- Action Consistency Reward ($R_{\text{act}}$): Verifies that the visual transition logically reflects the user's intended action (e.g., tapping a search bar actually opens a search view).
- Deployment ("Propose, Simulate, Select"): At test time, Code2World wraps around any existing GUI agent. If the agent isn't confident (no single action proposal exceeds a 0.9 confidence threshold), it proposes $K$ candidate actions, simulates the resulting screens via Code2World, and uses a VLM scorer to pick the best path forward.
Datasets
- AndroidCode (Newly Introduced): Because paired screenshot-to-HTML trajectory datasets didn't exist at scale, the authors synthesized over 80K high-quality screen-action pairs derived from AndroidControl. They used GPT-5 to translate screenshots into self-contained HTML (using inline SVGs and
[IMG: description]placeholders). Crucially, if a rendered image scored below 0.9 on SigLIP similarity against the real screenshot, it triggered a visual-feedback loop where GPT-5 inspected its own rendered mistakes and fixed the code. - Evaluation Benchmarks: Next-UI prediction was tested on unseen apps in AndroidControl (in-domain) and GUI Odyssey (out-of-distribution, cross-app/device). Live, multi-step agent navigation was tested online in AndroidWorld.
Key Insights and Ideas
- Visual rewards alone cause "reward hacking": In ablation studies, optimizing only for visual similarity ($R_{\text{sem}}$) made the UIs look prettier, but caused functional logic to stagnate—the model prioritized superficial visual matching over learning how actions actually change state. Pairing it with action consistency ($R_{\text{act}}$) was essential.
- Emergent temporal awareness: Because Code2World learns true environmental dynamics rather than just copying pixels, it organically learned to simulate the passage of time—such as incrementing the phone's top-bar system clock from
5:46to5:47during a state transition! - Agent confidence can be a trap: As shown in their pipeline analysis, an agent's highest-confidence instinct isn't always the right move. Visualizing the future lets a verifier catch bad plans before they happen.
Key Results
- Next-UI Prediction: Despite having only 8B parameters, Code2World outperforms open-source VLMs over $10\times$ its size (like GLM-4.6V-106B and Qwen2.5-VL-72B) and rivals proprietary giants like GPT-5 and Gemini-3-Pro-Image. On AndroidControl, it hits 94.28% in Action Adherence (beating GPT-5's 94.02%) and 70.32% in Layout Integrity. On out-of-distribution GUI Odyssey tasks, it maintains 92.73% Action Adherence while open-source baselines collapse.
- Qualitative Leap: Where pixel-based Gemini-3-Pro-Image gets stuck in the original screen's layout geometry and smaller VLMs output garbled layouts, Code2World cleanly renders brand-new screens (like popping up a keyboard and trending search tags).
- Live Agent Boost: Acting as a plug-and-play simulator on AndroidWorld, Code2World boosts task success rates across every tested agent: Gemini-2.5-Flash jumps by +9.5 percentage points (from 41.38% to 50.86%, a +22.9% relative gain), Qwen3-VL-8B improves from 31.03% to 37.93%, and GPT-4o climbs from 37.93% to 43.97%.
Limitations and Future Work
While a dedicated limitations section is not included in the main text, two practical constraints are noted in the methodology:
- Asset Abstraction: Because generating raw photographic assets in HTML is infeasible, Code2World abstracts complex images and icons into text boxes (e.g.,
[IMG: Red Shoe]) and basic inline SVGs, sacrificing photographic texture for structural accuracy. - Inference Overhead: Generating and rendering multiple HTML worlds takes time and compute, which the authors currently mitigate by gating the simulator—only invoking Code2World when the base agent's confidence drops below 0.9.
Future work is not explicitly discussed in the main text of the paper.
Summary updated