reset() and step() API, and your training loop talks to it over a WebSocket through an EnvClient. Environments ship as container images, for example on Hugging Face Spaces.
This page runs the OpenEnv Wordle environment in Superserve sandboxes. A model plays each game turn by turn from your machine, and the loop collects the reward for every turn. Each episode gets its own sandbox, so episodes run in parallel and never share state.
Setup
Install the Superserve SDK, the Anthropic SDK, and the client for OpenEnv’s TextArena environments, which include Wordle. The client needs Python 3.10 or later.How it works
- A template is built once from the environment’s container image.
- Each episode creates a sandbox from the template and starts the environment server in it.
- The server port is published as a private preview URL. The OpenEnv client connects to it with the preview token in a request header.
- The loop calls
reset(), then asks the model for a move and callsstep()until the episode is done. It records the reward for each turn. - The sandbox is killed when the episode ends.
Build the template
Save this file asbuild_template.py and run it once. It builds a template from the Wordle Space’s image and downloads the NLTK word lists that the server needs, so the server can start without network access.
build_template.py
An image’s
ENTRYPOINT and CMD do not run in a template-booted sandbox. To find the command that starts another OpenEnv environment’s server, look at the CMD in its Space’s Dockerfile.Run rollouts
Save this file asrollout.py. The highlighted lines are the Superserve calls: create a sandbox, start the server, publish its port, connect to it, and kill the sandbox.
rollout.py
commands.spawn in each sandbox, not as the template’s start command. A template’s snapshot captures the running process, so every sandbox restored from it would resume with the same random state and draw the same secret word.
The sandbox has no outbound network access: deny_out=["0.0.0.0/0"] blocks all egress, and the model runs on your machine. Inbound traffic reaches the server only through the private preview URL, which needs the preview token.
Rewards
result.reward is the episode reward. It is 1.0 when the model guesses the word, and 0.0 on the turns before. The episode also ends when the guesses run out, or on the second invalid move, such as a repeated guess or a word that is not in the word list. The reward is then a completion score from the latest feedback: each correct letter in the correct position counts 1, each correct letter in the wrong position counts 0.5, and the total is divided by the word length.
observation.info["reward_signals"] has per-turn signals that you can use to shape the reward:
Train a policy
To train, replacechoose_guess with a call to the model you train, and pass the turns and rewards from run_episode to your trainer. The rollout loop and the sandbox lifecycle stay the same. Increase the number of episodes in main to collect more rollouts in parallel.
Clean up
The script kills each sandbox when its episode ends. To remove the template, delete it in the console or with the CLI:Learn more
OpenEnv documentation
Read about OpenEnv environments, clients, and training integrations.
Wordle environment
See the Wordle environment’s Space and image.
Preview URLs
Publish sandbox ports and use private preview tokens.
Templates
Learn how Superserve builds and caches templates.