RL Workloads (RLVR, GRPO, DAPO & Flywheel)
Run verifiable RLVR rollouts, Serverless Batch .map() grading, GRPO/DAPO/GSPO training, and GPU Flywheels with stateset-agents on StateSet Sandboxes.
RL Workloads (stateset-agents on StateSet Sandboxes)
Run **RLVR (Reinforcement Learning with Verifiable Rewards)**, **GRPO / DAPO / GSPO** multi-turn rollouts, **Serverless Batch .map()** reward grading, and **GPU SFT / Flywheel** training inside isolated gVisor and NVIDIA GPU StateSet Sandboxes — with parity across **Python**, **TypeScript SDK**, **CLI**, **MCP Server**, and the **Dashboard RL Workloads Studio** (/dashboard/rl).
Architecture Overview
| Layer | Primitive | What It Gives You |
|---|---|---|
| **Rollout Isolation** | SnapshotTemplate + SandboxRolloutPool | Build one golden sandbox, take a Copy-on-Write CSI snapshot, pause the base sandbox, and fork parallel rollouts with bounded concurrency and guaranteed cleanup |
| **Verifiable Rewards (RLVR)** | SandboxPytestReward, SandboxPatchReward, SandboxCommandReward, SandboxMultiCheckReward | Deterministic grading with <think> stripping, anti-tampering write order (candidate before hidden tests), forbidden-path patch checks, and binary or fractional scoring |
| **Serverless Scale-Out RLVR** | SandboxBatchMapReward (POST /api/v1/batch/map) | Fan out 64–1,000+ completions per RL step server-side with Spot CPU/GPU capacity, automatic preemption fallback to On-Demand, CoW Repo Caches, and controller-enforced budget_max_usd caps |
| **Multi-Turn Environments** | SandboxCodingEnvironment, SandboxShellEnvironment, coding_rlvr_benchmark | Wave-chunked lockstep run_episodes_batched, hidden test injection only at grade time, protected paths, and path containment |
| **GPU Training & Flywheel** | SandboxRemoteExecutor + Dockerfile.sandbox-rl | Run sft, harvest, and rl jobs across all **11 stateset-agents objectives** (grpo, dr_grpo, bnpo, dapo, gspo, gspo_token, gepo, rloo, reinforce_pp_baseline, cispo, ppo) with pre-flight + controller USD budget caps and Model-Weight CSI Caches (model_cache_id) |
1. Python Package (stateset-agents-sandbox)
Install alongside stateset-sandbox and stateset-agents:
pip install stateset-agents-sandbox stateset-sandbox stateset-agents
export STATESET_API_KEY="YOUR_STATESET_API_KEY"Multi-Turn RLVR Rollouts + GRPO / DAPO
import asyncio
from stateset_agents_sandbox import (
SandboxCodingEnvironment,
SandboxPytestReward,
SandboxRolloutPool,
SandboxRolloutRunner,
SandboxSpec,
coding_rlvr_benchmark,
)
async def main() -> None:
pool = SandboxRolloutPool(
SandboxSpec(cpus="2", memory="2Gi", timeout_seconds=300),
max_concurrency=8,
)
env = SandboxCodingEnvironment(pool=pool)
scorer = SandboxPytestReward(pool=pool, score_mode="fractional")
runner = SandboxRolloutRunner(group_size=4, drop_zero_variance=True)
scenarios = coding_rlvr_benchmark()[:4]
batch = await runner.collect_groups(env=env, scenarios=scenarios, policy=my_policy, scorer=scorer)
print(batch.summary())
batch.export_verified_sft_jsonl("verified_sft.jsonl")
await pool.aclose()
asyncio.run(main())Serverless Batch .map() RLVR (64–1,000+ Rollouts / Step)
Offload large-batch RLVR reward grading to StateSet's controller-native parallel fleet with Spot preemption recovery, CoW Repo Build Caches, and hard USD budget kill-switches:
from stateset_sandbox import StateSetSandbox
from stateset_agents_sandbox import (
BatchMapItemSpec,
BatchMapVerificationConfig,
SandboxBatchMapReward,
ensure_model_cache,
)
client = StateSetSandbox(
base_url="https://api.sandbox.stateset.app",
auth_token="YOUR_STATESET_API_KEY",
)
model_cache = ensure_model_cache(client, preset="qwen-2.5-coder-7b", warm=True)
verifier = SandboxBatchMapReward(
client,
config=BatchMapVerificationConfig(
compute_sku="cpu-standard",
spot=True,
fallback_to_ondemand=True,
max_concurrency=64,
budget_max_usd=2.50,
repo_cache_id="rc_your_repo_cache",
score_mode="binary",
),
)
result = verifier.verify_batch_sync(
items=[
BatchMapItemSpec(solution=cand, tests=hidden_tests, group_id=f"prompt-{idx // 8}")
for idx, cand in enumerate(completions)
],
compute_advantages=True,
)
print("Pass rate:", result.pass_rate, "Cost USD:", result.total_cost_usd)
print("DAPO kept groups:", result.dapo_kept_groups)GPU Training & Flywheel with Model-Weight CSI Caches
from stateset_agents_sandbox import SandboxRemoteExecutor, register_stateset_sandbox_executor
executor = SandboxRemoteExecutor(
image="stateset/sandbox-rl:latest",
default_gpu="nvidia-l4",
model_cache_id=model_cache.id,
preinstalled=True,
)
register_stateset_sandbox_executor(executor)2. TypeScript SDK (@stateset/sandbox-sdk)
Use the universal TypeScript helpers for single-rollout verification, bounded concurrent GRPO groups, or Serverless Batch .map() verification:
import {
StateSetSandbox,
RlSandboxVerifier,
verifyRlBatchWithBatchMap,
computeGrpoAdvantages,
estimateRlGpuCostUsd,
} from '@stateset/sandbox-sdk';
const client = new StateSetSandbox({
baseUrl: 'https://api.sandbox.stateset.app',
authToken: process.env.STATESET_API_KEY!,
});
// Single or small-group RLVR verification
const verifier = new RlSandboxVerifier(client, { scoringMode: 'fractional', concurrency: 4 });
const group = await verifier.scoreGroup({
candidates,
testCode: hiddenPytestSuite,
});
// High-throughput Serverless Batch `.map()` RLVR verification
const batchResult = await verifyRlBatchWithBatchMap(client, {
items: candidates.map((solutionCode, i) => ({
solutionCode,
testCode: hiddenPytestSuite,
groupId: `prompt-${Math.floor(i / 4)}`,
})),
computeSku: 'cpu-standard',
spot: true,
fallbackToOndemand: true,
maxConcurrency: 32,
budgetMaxUsd: 1.5,
computeAdvantages: true,
});
console.log({
passRate: batchResult.passRate,
costUsd: batchResult.totalCostUsd,
dapoKeptGroups: batchResult.dapoKeptGroups,
estimatedL4HourUsd: estimateRlGpuCostUsd('nvidia-l4', 1, 3600),
sampleAdvantages: computeGrpoAdvantages([1, 0, 1, 0]),
});3. CLI (@stateset/sandbox-cli)
Inspect presets, estimate GPU budgets, verify candidate solutions, and compute GRPO / DAPO group metrics from any shell or CI pipeline:
stateset rl presets --json
stateset rl estimate --gpu nvidia-l4 --gpu-count 2 --timeout 1800 --max-cost-usd 5
stateset rl verify --file solution.py --test test_solution.py --scoring-mode fractional --json
stateset rl score-group --candidates candidates.jsonl --test test_solution.py --concurrency 4 --json
stateset rl verify-batch --candidates candidates.jsonl --test test_solution.py --max-concurrency 32 --budget-max-usd 2 --json4. MCP Tools (@stateset/sandbox-mcp)
Give Antigravity, Claude Code, Cursor, or any MCP client native RLVR & GRPO tools:
| MCP Tool | Purpose |
|---|---|
rl_list_presets | List the 5 canonical RL workload presets, 11 stateset-agents RL objectives, and GPU hourly rates |
rl_estimate_cost | Estimate worst-case USD spend for a GPU RL/SFT/Flywheel job with hard budget cap validation |
rl_verify_solution | Run isolated pytest RLVR verification (binary or fractional) inside a StateSet Sandbox |
rl_score_group | Compute zero-mean unit-variance GRPO advantages and DAPO dynamic sampling keep/drop decisions |
rl_verify_batch | Fan out 1–1,000 RLVR verifications server-side via Batch .map() with Spot preemption recovery, hard USD budget caps, and inline GRPO/DAPO scoring |
5. Dashboard RL Workloads Studio
Open **RL Workloads Studio** (⌘K -> **RL Workloads**) to:
- Browse all 5 canonical RL presets (
coding-rlvr-grpo,swe-patch-dapo,shell-sre-gspo,gpu-sft-lora,gpu-flywheel) with synchronized Python, TypeScript SDK, CLI, and MCP code snippets - Estimate worst-case GPU training spend across
nvidia-t4,nvidia-l4,nvidia-a100,nvidia-a100-80gb, andnvidia-h100with hard budget-cap enforcement - Run live isolated RLVR pytest verification directly against your workspace sandboxes
Related Resources
- Next-Gen Platform Pillars (v2.18.0) — Batch
.map(), Spot GPUs, Model-Weight CSI Caches, and CoW Repo Hot-Forks - MCP Server Guide — Hosted Streamable HTTP and local stdio setup
- Python SDK Guide — Core
SandboxandAsyncSandboxreference - RL Workloads Studio — Interactive presets, budget estimator, and live verifier
Ready to run this in a hardened gVisor sandbox?
Test live in the Playground with zero signup, or create a free workspace with $25 in trial credits.