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 scale agent environment instances for RL training

At a glance

Scale agent environments by running one isolated instance per episode with fixed CPU and memory limits, many in parallel, and by not letting the slowest episode stall the batch. Size and price a batch from episodes, minutes and resources per instance, and cap its worst case before it starts.

Compiled by
First recorded
Last revised
Reading time
11 min

Scaling agent environments means running many independent instances at once without letting them slow or corrupt each other. The pattern that works is one isolated instance per episode, with fixed resource limits, started from a pinned image, and a training loop that does not wait for the slowest episode.

How do I run many environments in parallel?

Run them as many isolated copies started from one pinned environment, either on a hosted service or with Gymnasium's vector environments on a machine of your own.

On a hosted service, the provider starts the copies for you from one prepared environment. Six providers publish how they do it and how fast a copy starts, each on its own pages, all read 2026-11-26; every speed figure here is the provider's own, none was measured by this site:

  • Promigence. Its quickstart says one command forks N copies of a verified snapshot, runs your command in each and prints the validity report; the commands are in the cost section below. Its FAQ says a copy "takes 39 ms, and a hundred at once still land at 122 ms". Its home page and FAQ put the 95th percentile of 100 runs started at once at 0.94 s, with every run completed (n=400), measured by Promigence in September 2026. Its RL environments page says environment failures "are reported separately, so they never enter the reward signal".
  • AWS. Amazon Bedrock AgentCore Runtime "prepares your environment once and takes a snapshot of it, then restores that snapshot for each new instance", and says its platform version V2 "keeps cold-start latency consistent regardless of concurrency or image size" (AgentCore Runtime guide).
  • Daytona. Any number of new sandboxes can start from the same snapshot (Daytona snapshots), and its home page states "Sub 90ms sandbox creation from code to execution" (daytona.io).
  • E2B. Its template guide says a sandbox loads "in ~80ms" from a template snapshot (E2B templates).
  • Google Cloud. Gemini Enterprise Agent Platform can create multiple sandboxes from the same snapshot to explore different paths (Manage snapshots); a new sandbox can take up to 2 minutes to provision from a cold start and then usually spins up in seconds (Agent Platform sandboxes).
  • Modal. Its Sandboxes page says "Modal Sandboxes start in under one second" (Modal Sandboxes product page).

How many environments an account may run at once differs by provider and plan and changes often, so get your own account's number in writing before you plan a batch around it.

On one machine, use Gymnasium's vector environments. gymnasium.make_vec(id, num_envs=..., vectorization_mode=...) accepts the modes "async", "sync" and "vector_entry_point" (Gymnasium registry API, read 2026-11-26).

Table: Gymnasium's two general vector environments

ClassHow it runs sub-environmentsDocumented options worth knowing
SyncVectorEnv"serially", in one process (docs)None needed for basic use
AsyncVectorEnv"multiprocessing processes, and pipes for communication" (docs)shared_memory, context, daemon, max_concurrency

Both read 2026-11-26. max_concurrency limits how many sub-environments run reset or step at the same time, which the documentation says "can improve performance when the number of environments exceeds the number of CPU cores" (AsyncVectorEnv docs).

This example runs four copies of the order-cancelling environment from our Gymnasium guide in separate processes. We ran it with gymnasium 1.4.0:

import json
import gymnasium as gym
import orders_env  # registers toolenv/Orders-v0

if __name__ == "__main__":
    envs = gym.make_vec("toolenv/Orders-v0", num_envs=4, vectorization_mode="async")
    obs, info = envs.reset(seed=0)
    actions = tuple(json.dumps({"tool": "finish"}) for _ in range(4))
    obs, rewards, terminated, truncated, info = envs.step(actions)
    print(rewards, terminated, truncated)
    envs.close()

It printed [0. 0. 0. 0.] [ True True True True] [False False False False]: four episodes, each ended by finish without doing the task. Text observations come back as a tuple of strings, one per sub-environment. Keep the if __name__ == "__main__": guard, because worker processes import the script.

What happens when one sub-environment finishes early?

It is reset automatically, by default on the next call to step. Gymnasium's vector environments default to next-step autoreset: "If a sub-environment terminates or truncates, it is reset in the next step call" (Farama autoreset modes, read 2026-11-26). Two other modes exist: same-step, where the final observation is moved to info["final_obs"], and disabled, where you reset finished sub-environments yourself with a mask. With next-step autoreset, the action you send to a finished sub-environment is spent on the reset, so drop that transition from training data.

Why should rollouts not wait for the slowest episode?

Rollouts should not wait because agent episodes vary widely in length, and a synchronous batch leaves hardware idle until the longest one ends. The AReaL paper puts it as generation that "must wait until the longest output in the batch is completed"; its asynchronous design separates generation from training, and the authors report up to 2.77 times faster training than synchronous systems on the same number of GPUs, with final performance matched or better (AReaL, arXiv 2505.24298, read 2026-11-26).

For environment builders this means two things:

  1. Environments must tolerate many episodes starting and ending at different times, not in lock-step batches.
  2. Every trajectory must carry the policy version that produced it, because asynchronous training mixes slightly stale data with fresh data.

How do I isolate one instance from another?

Give each episode its own instance started from the same pinned image, with its own CPU and memory limits, and throw it away afterwards.

On a hosted service, each provider states how one instance is kept apart from another and offers outbound network settings, each on its own pages, all read 2026-11-26:

  • Promigence. Every copy in a run starts from the same snapshot. Its security page says "No sandbox can see, reach or address another, yours or anyone else's" and that the boundary is tested "by attacking it rather than asserting it"; its FAQ lists three outbound settings per sandbox, full access, none or an allow-list, with refused connections recorded.
  • AWS. "Session isolation prevents cross-session data contamination and ensures security" (AgentCore Runtime guide); AgentCore Code Interpreter takes a network mode of PUBLIC, SANDBOX or VPC (network configuration).
  • Daytona. "Each sandbox runs in isolation, giving it a dedicated kernel, filesystem, network stack, and allocated vCPU, RAM, and disk" (Daytona sandboxes); its outbound settings are networkBlockAll, a CIDR allow-list or a domain allow-list (network limits).
  • E2B. Its documentation describes "isolated sandboxes that let agents safely execute code, process data, and run tools" (E2B documentation); its outbound settings are allowInternetAccess: false and allow and deny lists (internet access).
  • Google Cloud. Agent Sandbox on GKE runs AI-generated code "in an isolated sandbox" on a GKE cluster (Agent Sandbox on GKE); Agent Platform's code execution sandboxes run without outbound internet access (Agent Platform sandboxes).
  • Modal. "Each container runs in its own sandbox, isolated from the host" (Modal security); its outbound settings are block_network=True and CIDR and domain allow-lists (Modal networking).

With containers on machines you run yourself:

  1. One episode, one instance. An agent that can write files or change a database must not share them with another episode.
  2. Fixed limits. With Docker, --cpus sets "how much of the available CPU resources a container can use", and -m or --memory sets "The maximum amount of memory the container can use" (Docker resource constraints, read 2026-11-26). Same limits for every instance keep step times comparable.
  3. Plan for memory kills. Docker's documentation notes that by default, when an out-of-memory error occurs, the kernel kills processes in the container (same page). Report that as an environment failure, not as an agent failure.
  4. No outbound network unless the task needs it. It keeps instances from depending on outside services that change.
  5. Fresh start instead of cleanup. Starting a new copy from the image is the most reliable reset.

How much compute does a batch of episodes need?

Compute for a batch of episodes is episodes times hours per episode times the resources each instance holds. The worked example below uses illustrative workload numbers and prices them at published list rates, so the arithmetic is concrete: first at Promigence's rates, then at the rates of five other named providers.

Table: Worked example priced at Promigence's listed rates (illustrative workload)

LineExample value
Episodes in the batch1,000
Average episode length10 minutes
CPU per instance4 vCPU
Memory per instance8 GiB
vCPU-hours1,000 × 4 × 10 ÷ 60 = 666.7
GiB-hours1,000 × 8 × 10 ÷ 60 = 1,333.3
CPU at $0.0504 per vCPU-hour$33.60
Memory at $0.0162 per GiB-hour$21.60
Environment compute for the batch$55.20

The rates in the table are Promigence's list prices, $0.0504 per vCPU-hour plus $0.0162 per GiB-hour, metered per second, as its FAQ states them (read 2026-11-26). Per-second metering is what keeps the example at $55.20: agent episodes vary in length, and under per-hour rounding each 10-minute episode would be charged as a full hour, six times its use. Model inference is a separate cost and is outside these hours.

The same batch at five other providers' published rates, in each rate's own units, comes to the figures below. The totals are this site's arithmetic on those rates, not quotes from the providers.

Table: The illustrative batch at AWS, Daytona, E2B, Google Cloud and Modal published rates (rates read 2026-11-26)

ProviderPublished ratesEnvironment compute for the batchHow the rate is appliedSource
AWS (Amazon Bedrock AgentCore Code Interpreter)$0.0895 per vCPU-hour, $0.00945 per GB-hour$73.20 at these rates if 4 vCPUs were in use for every episode minute: 666.7 × $0.0895 plus 1,431.7 GB-hours (8 GiB is 8.59 GB) × $0.00945Per second, on actual CPU use and peak memory, so idle CPU time lowers the total; a session's hardware configuration is 2 vCPU and 8 GBAgentCore pricing, AgentCore quotas
Daytona$0.0504/h per vCPU, $0.0162/h per GiB of memory$55.20Calculated per second, on the resources reserved for the sandboxDaytona pricing, Daytona billing
E2B$0.000014/s per vCPU, $0.0000045/s per GiB of memory$55.20Per second while the sandbox runs; the Pro plan is $150 a monthE2B pricing
Google Cloud (Gemini Enterprise Agent Platform sandboxes)$0.085/vCPU-h, $0.009/GiB-h$68.67: 666.7 × $0.085 plus 1,333.3 × $0.009On the vCPU and memory allocated, rounded to the nearest secondAgent Platform pricing
Modal (Sandboxes)$0.00003942 / core / sec for a physical core (2 vCPU equivalent), $0.00000667 / GiB / sec$79.32 with 2 cores and 8 GiB requested: 600,000 sandbox-seconds × (2 × $0.00003942 + 8 × $0.00000667)On the higher of the request and actual use, at the non-preemptible rates Sandboxes are billed atModal pricing, Sandbox resources

How do I cap the cost of a batch before it starts?

Price the batch at its worst case before starting it, every instance running until its timeout, and refuse to start if that ceiling is above your budget.

On a hosted service, Promigence's promigence run quote prices a run before any environment starts, assuming every sandbox runs until its timeout, and --cap makes the run itself refuse to start when its quote is above the cap, according to its quickstart (read 2026-11-26). Its FAQ adds that a sandbox that reaches the cap while it runs "is paused with its files kept", and that "Paused time is not invoiced". The quickstart's commands, with an environment snapshot named orders-env as our example:

promigence run quote --snapshot orders-env --count 20 --timeout 15m
promigence run --snapshot orders-env --count 20 --cap 1 -- sh -c "python3 /work/env/run_episode.py"

Here run_episode.py stands for your own episode script.

The other named providers publish the two inputs to such a ceiling, a time limit per instance and a spending control on the account (all read 2026-11-26):

  • AWS. AgentCore Code Interpreter sessions end after a configurable timeout, 15 minutes by default (Code Interpreter sessions), and AWS Budgets cost budgets "Set spending limits for services and receive alerts when costs approach or exceed your defined threshold" (AWS Budgets).
  • Daytona. A wall-clock TTL "sets a hard upper bound on how long a sandbox may exist" (Daytona sandboxes), and the Spending view lists the total price of each sandbox (Daytona billing).
  • E2B. A sandbox's timeout defaults to 5 minutes (E2B sandbox lifetime), and spending limits can be set on the Limits page of its console (E2B billing and limits).
  • Google Cloud. A ttl set when an Agent Platform sandbox is created removes it automatically (Manage sandboxes); Cloud Billing alerts-only budgets do not cap spending, and spend cap budgets can be set on a project where the service supports them (Cloud Billing budgets).
  • Modal. A Sandbox timeout can be set up to 24 hours, with 5 minutes as the default (Modal Sandboxes), and a Workspace budget limits monthly spend (Modal pricing).

On infrastructure you run yourself, the same guard is one line of arithmetic in the launcher: instances × timeout × resources × rate, compared with the budget before the first instance starts. A ceiling-based quote is deliberately pessimistic: if most episodes end early, the bill is below it.

What should I measure when scaling up?

Measure where an episode's time goes and how often the environment, not the agent, causes a failure.

  1. Start time of an instance, from request to first observation.
  2. Step time split into model time and environment time.
  3. Environment failure rate: crashes, memory kills, timeouts of the app itself.
  4. Reward drift when you change the number of parallel instances. If rewards drop as concurrency rises, instances are starving each other.

What we read for this article

Field questions

What is the difference between SyncVectorEnv and AsyncVectorEnv?

SyncVectorEnv steps its sub-environments one after another in the same process. AsyncVectorEnv runs each in its own process and talks to them through pipes, so slow steps overlap. For agent environments, where a step waits on an app or a test run, the asynchronous form is usually the one you want.

Why does synchronous rollout collection waste time with LLM agents?

Agent episodes differ a lot in length. If a batch waits for every episode to finish, the hardware sits idle behind the longest one. The AReaL paper describes generation that must wait until the longest output in the batch is completed, and reports up to 2.77 times faster training by decoupling generation from training.

Should environment instances share a container?

Not if the agent can change anything. One instance per episode, started from the same image, keeps one episode's changes from leaking into the next and makes resets a matter of starting a fresh copy.

How many environment instances can I run per machine?

Divide the machine's CPUs and memory by each instance's limits, then leave headroom. Measure an instance's real use under a busy episode first; app clones with databases often need more memory than the agent's own process.