Skip to main content
An environment is a small Python module that packages everything Flash needs to teach and grade your model: the data it practices on, how it interacts, and how its answers are scored. It is the single source of truth for what the model learns and what counts as good.

What an environment packages

Every environment bundles three things behind one load_environment() entrypoint:

A dataset

The prompts your model practices on, with optional gold answers. Authored as input/output records. See Datasets.

An interaction model

How the model engages: a single prompt and response, or a multi-turn exchange. This is the environment class you subclass.

A reward

score_response looks at an answer and returns a RewardResult score. This score is the GRPO signal.
The same environment drives SFT (learn from gold answers), GRPO (learn from reward scores), OPD (practice on the prompts while a managed teacher scores the model’s tokens), and eval. Swap one line in the config; the environment stays put. For SFT, each row’s output is the gold completion Flash trains on, appended after the environment’s initial episode so system prompts and tool transcripts stay part of the example. See Datasets for the output shapes (a scalar answer, or a message trajectory for multi-turn and tool-use imitation).

The one thing you write

You write environment.py; Flash owns the rest of the loop. The quality of the environment’s dataset and reward sets the ceiling on what training can achieve. See How Flash works for the full split of responsibilities.

Where it sits in the training loop

The environment supplies two of the loop’s steps:
1

Flash samples a prompt

The training loop pulls a prompt from your environment’s dataset.
2

The model produces a rollout

The current model attempts an answer, following your environment’s interaction model (single response, or several turns).
3

Your reward scores it

score_response returns a RewardResult. That score is the signal the GRPO algorithm learns from. OPD uses the same prompt/interaction loop, but its learning signal comes from the managed teacher instead of your reward.
See How Flash works for the algorithm side of the loop.

Single-turn and multi-turn

The base class you subclass sets the interaction model:
  • EnvironmentSingleTurn: prompt in, completion out, reward computed. Most tasks start here. If your prompt messages do not include a system message, the SDK prepends the run’s prompt text as one.
  • EnvironmentMultiTurn: for conversations or tool use, where the model takes several steps before the whole sequence (its trajectory) is scored. You implement the episode hooks — start_episode (opening messages), step_episode (react to each action and decide whether the episode continues), max_episode_turns (the bound), and score_episode (reward the trajectory). See Multi-turn environments for the full loop, an action protocol, and the stateless-step pattern.
See Environments for the full SDK: prompt builders, loading dataset files, parameters, and secrets. With thinking = true, response_text is the answer text by default. It also exposes the separated reasoning trace and raw output when a reward needs them (see Environments).

From local file to managed run

You author an environment locally, but it must be reachable by id when training runs on managed infrastructure. The lifecycle has four steps:
1

Author it locally

Write environment.py with a load_environment() that returns a Freesolo environment.
2

Publish it

flash env push --name my-env . packages the folder and uploads it to the managed Environments Hub, which versions it and prints an id (your-org/my-env).
3

Reference it by id

Put that id in your config’s [environment] id. Optional [environment.params] are passed to load_environment(**params).
4

Flash loads it at run time

The worker installs your published environment, imports environment.py, and calls load_environment(**params) to drive the run.

Next

Build an environment

The full SDK: author a dataset and reward, then publish it.

Datasets

Package task records and data files inside an environment.

Explore the directory

Where the environment lives on disk and what Flash reads.

How Flash works

The full run loop the environment plugs into.