Skip to the entry
AgenticRLEnvironments.com

How to build environments for training and testing AI agents with RL: state and actions, app clones, task generators, graders, rewards and versioning.

How to clone a web app as an RL environment for agents

At a glance

Clone a web app as an agent environment by self-hosting an open-source app of the same kind in a container image, loading seeded synthetic data, replacing outside services with local fakes, fixing the clock, and reading rewards from its database. Then pin the image and check two runs match.

Compiled by
First recorded
Last revised
Reading time
5 min

To clone a web app as an RL environment, you build a copy you fully control: the same kind of software, realistic data that you generated, no calls to the outside world, and a way to read its state after the agent is done. The clone does not have to be pixel-identical to the real product; it has to present the same tasks and be checkable.

What does a cloned web app environment contain?

A cloned web app environment contains five things: the app, its data, fakes for outside services, a controlled clock, and a reward reader.

Table: The parts of a cloned web app environment

PartWhat it isWhy it matters
AppOpen-source software of the same category, in a container imageYou can run, reset and inspect it
DataSynthetic or sampled records, generated from a seedTasks need realistic content; the seed makes it repeatable
FakesLocal versions of payment, email, maps or login providersNo real side effects, same answers every run
ClockA fixed or offset time the app seesDates in tasks and data stay valid
Reward readerA database query or API call after the episodeThe reward checks what happened, not what was shown

WebArena is the best-documented example of this approach. Its authors "leveraged open-source libraries relevant to each category to build our own versions" of each site, then "imported sampled data from their real-world counterparts", deployed the sites "in separate Docker images", and provide "scripts to reset the environment to a deterministic initial state" (WebArena paper, arXiv 2307.13854, read 2026-11-26). Its reward functions "programmatically examine the intermediate states", for example through a database query or the site's own API (same source).

Step 1: How do I choose the app to clone?

Choose an open-source app whose workflows match the tasks you want the agent to learn, not the app whose look is closest.

  1. List the tasks the agent must do: "refund an order", "move a ticket to done", "invite a user".
  2. Pick an open-source application in the same category that supports those workflows through its interface and has an API or a database you can query.
  3. Check its licence allows the use you plan, including redistribution of the image if you share the environment.
  4. Build it into a container image from a pinned base, so the environment is one artefact.

Step 2: How do I fill it with data?

Fill it with data generated from a seed, so every copy of the environment starts the same.

  1. Write a loader that creates users, records and history through the app's API or database, using a seeded generator.
  2. With the Faker library, call Faker.seed(4321) for the shared generator or fake.seed_instance(4321) for one instance. Its documentation warns that its datasets change over time, so results can differ across patch versions: pin Faker to an exact version (Faker documentation, read 2026-11-26).
  3. Add the edge cases the tasks need: a pending order among shipped ones, a duplicate customer, an expired coupon.
  4. Bake the loaded state into the image, or keep it as a database dump next to the image, so loading is not repeated for every episode.

Step 3: How do I replace outside services?

Replace every outside service with a local fake that the clone calls instead.

  1. List every outbound call the app makes: payments, email, maps, single sign-on, analytics, update checks.
  2. Point each one at a small local HTTP service that returns fixed, valid answers. Record what it received, because a grader may need it: "an email was sent to the customer" is checked in the fake mail service.
  3. Block all other outbound traffic from the environment, so a forgotten call fails loudly instead of reaching the internet.
  4. Turn off the app's telemetry and update checks in its configuration.

Step 4: How do I control time?

Control time by giving the app a fixed starting date, because tasks such as "orders from last week" depend on it.

The libfaketime library "intercepts various system calls that programs use to retrieve the current date and time" and reports a faked time to one program without changing the system clock. It is loaded with LD_PRELOAD and set with FAKETIME; a value with @, such as FAKETIME="@2020-12-24 20:30:00", starts the clock at that date and lets it run, while a value without @ freezes it. Its documentation notes it does not work with statically linked binaries or setuid programs (libfaketime repository, read 2026-11-26). Prefer a start date to a frozen clock: apps that measure elapsed time misbehave when the clock stops.

Step 5: How do I read the reward from the clone?

Read the reward from the app's state after the episode, through its database or API.

  1. For each task, write the query that shows success: the order's status, the ticket's column, the user's role.
  2. Also query what must not have changed. AppWorld's state-based tests check for "collateral damage" as well as success (AppWorld, arXiv 2407.18901, read 2026-11-26).
  3. Run the grader against the hidden state, never against the agent's last message. See writing a grader.

Step 6: How do I prove the clone is reproducible?

Prove it by starting two copies from the same image digest and seed, running the same scripted actions in both, and comparing the database afterwards.

  1. Pin the image by digest, not by tag. Docker's documentation says pulling by digest lets you "specify exactly which version of an image to pull" and that this "pins" an image to a specific version in time (docker image pull, read 2026-11-26).
  2. Start two copies, run a fixed script of actions, and dump the tables the graders read.
  3. Diff the dumps. Any difference is non-determinism to remove before training: an unseeded generator, the real clock, an outside call, or a background job.

Resetting between episodes is the other half of the job; the simplest reliable method is to throw the copy away and start a new one from the image. Versioning the clone over time is covered in versioning agent environments.

What we read for this article

Field questions

Why not train agents on the live website?

A live site changes, cannot be reset, may forbid automated use, and makes every mistake real. A self-hosted clone can be reset to a known state, run many times in parallel, and inspected directly to compute a reward.

Do I have to rebuild the app from scratch?

Usually not. Published environments start from open-source software of the same category and add data. WebArena's authors used open-source libraries for each kind of site and imported data sampled from real counterparts.

How do I make a cloned app deterministic?

Seed every random generator that creates data, freeze or offset the clock the app sees, replace outside services with fakes that answer the same way each time, and pin the image by digest. Then check it by building twice from one seed and comparing the database.

Where should the reward come from in a cloned web app?

From the app's state: a database query or an API call after the episode. Reading the page the agent saw is weaker, because a page can show success that did not happen.