PlayTrain: An Efficient Reinforcement Learning Framework for LLM-Generated Adaptable JavaScript Games

Ryan Truong, Lance Ying, Samuel J. Gershman, Kazuki IriearXiv 2026

TL;DR

PlayTrain is an innovative reinforcement learning (RL) framework that uses Large Language Models (LLMs) to automatically generate and modify 2D JavaScript game environments from simple natural language prompts. By executing these games browserless via an optimized headless backend (combining QuickJS, C++, and Rust), PlayTrain achieves training speeds exceeding 1 million steps per second while remaining instantly playable in a browser for human evaluation.

What Problem Does This Paper Address?

Video game environments (VGEs) are the bedrock of reinforcement learning research, serving as the training grounds for developing intelligent agents. However, creating new environments or modifying existing ones to test an agent's generalization limits is a slow, laborious process that requires extensive hand-coding—typically in C++ or Python.

Furthermore, researchers face a frustrating trade-off between playability (how easily a human can interact with and test the game) and efficiency (how fast an RL agent can run through training steps). JavaScript (JS) is an ideal language for rapid game development and is natively supported by browsers, making it highly playable and easy for LLMs to generate. However, running JS inside a standard browser introduces massive overhead, making it historically far too slow for practical RL training loops. PlayTrain solves this efficiency bottleneck.

Methods

PlayTrain bridges the gap between LLM code generation and high-speed RL execution through a two-part pipeline:

  1. LLM-Driven Generation & Validation: A user provides a short natural language prompt specifying a game's mechanics. An LLM (Google's Gemini 3.1 Pro) uses a structured Markdown template to generate a single, self-contained JS file built on the popular p5.js library. PlayTrain then runs an automated validation script to ensure the game complies with the standard Gymnasium API and maintains bit-identical determinism across separate runs.
  2. Headless JS-to-Gym Backend: To eliminate browser-based slowdowns, PlayTrain runs the JS games completely browserless. It embeds QuickJS (a lightweight JavaScript engine written in C) directly into the training process. The authors rewrote a subset of the p5.js library in C++ to intercept drawing calls, which are then rendered directly into a shared observation buffer using a custom, ultra-fast rasterizer written in Rust.

To maximize training throughput, PlayTrain runs environments on multiple threads within the same process as the trainer (eliminating slow memory copying) and utilizes double buffering to parallelize environment stepping and agent inference.

Datasets

Rather than using a static dataset, the authors evaluated PlayTrain by generating a diverse suite of 24 game environments:

  • Classic Clones: 8 Arcade Learning Environment (Atari) games and 16 ProcGen games cloned into clean JavaScript.
  • Custom Variants: Modified versions of these games designed to test agent adaptability, split into parametric variants (altering variables like gravity or speed), structural variants (changing map layouts, such as qbert.bigmap), and visual/thematic variants (e.g., transforming frostbite into a jungle theme).
  • Novel Games: Entirely new environments built from scratch based on popular indie concepts (VVVVVV and Downwell).

Key Insights and Ideas

  • Capitalizing on LLM Strengths: LLMs are exceptionally proficient at writing JavaScript compared to lower-level languages like C++. PlayTrain leverages this by making JS the universal interface for environment design.
  • The Browser is the Bottleneck, Not JS: The paper shatters the assumption that JavaScript is too slow for serious RL. By stripping away the browser's heavy Document Object Model (DOM) and rendering machinery, lightweight JS engines can execute game logic fast enough to outpace native C++ environments.
  • Symmetric Human-Agent Testing: Because the environment is just a standard JS file, the exact same code can be hosted on a webpage for human playtesting and compiled into the headless backend for RL training. This enables perfectly fair, seed-matched human-agent performance comparisons.

Key Results

  • Pure Environment Speed: On a single CPU core without a trainer attached, PlayTrain's JS replicas outpaced the original C++ implementations of Atari (ALE) by 12.62× and ProcGen by 2.19× on geometric average.
  • End-to-End Training Throughput: When training pixel-based agents end-to-end using the IMPALA algorithm on a single node (4x H100 GPUs), PlayTrain achieved an average of 1.07 million agent-steps per second across the 24-game suite.
  • Human Baseline Benchmarking: The authors easily deployed the generated games to 20 human participants to establish a baseline. While RL agents beat human averages on 6 out of 8 games within 100 million steps, they completely failed to learn structurally complex games like the gravity-flipping platformer VVVVVV.
Human performance vs RL agent training efficiency across eight PlayTrain environments.

Limitations and Future Work

  • 2D Only: The framework currently focuses strictly on 2D environments, though the authors note that 3D rendering support is actively in progress.
  • LLM Scale Limits: Current LLMs cannot reliably generate massive, full-fidelity modern console games (like The Legend of Zelda) in a single pass, limiting PlayTrain to mechanically simpler arcade-style games.
  • Computation Bottlenecks: Speed degrades if a game requires an excessive number of individual drawing commands per frame (e.g., massive panning maps) or highly complex per-frame game logic loops.

Summary updated

BibTeX
@misc{truong2026playtrain,
  author = {Ryan Truong and Lance Ying and Samuel J. Gershman and Kazuki Irie},
  title = {{PlayTrain: An Efficient Reinforcement Learning Framework for LLM-Generated Adaptable JavaScript Games}},
  year = {2026},
  eprint = {2609.09059},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.09059},
}
Figure