Language-model agents that work in a command line fail mostly on mundane things. In realistic repository tasks, 65% of agent failures come from environment setup and dependency resolution rather than from high-level reasoning (GitTaskBench). Yet the standard way to train these agents is to imitate logged trajectories: copy the command an expert typed, given everything the terminal printed so far. The model is never asked what a command will do, meaning which files it creates, which packages it installs, what it breaks. We propose to ask exactly that. We replay verified trajectories inside the reproducible Docker containers that produced them, snapshot the filesystem and package state after every step, and train the agent on an extra objective. Some of those consequences are hidden, and the model must reconstruct them. A schedule controls how many consecutive steps' consequences are hidden at once.
The two input directions play different roles here. Curriculum masking means changing, during training, how much or what kind of input is hidden. It supplies the learning signal and a live scientific question. Reproducible execution environments supply something logged text lacks: exact, re-derivable per-step state changes that can serve as prediction targets. They also impose a constraint, because only steps that replay deterministically can be used. Put in two sentences, the model is trained to predict what hidden commands did to a real container, and the span of hidden steps grows or shrinks over training. We test whether this makes terminal agents better at the setup-heavy tasks where they currently fail.
Core Claim
Next-token imitation on terminal trajectories teaches a model which command to type. It does not teach the model to track the machine's state. Two things should close part of that gap. The first is an auxiliary objective whose targets are per-step container state diffs: the files, packages and environment variables that changed, plus the command output. The second is block masking over several consecutive steps, so the model cannot solve the task by copying the previous observation. We expect the gain to concentrate on setup and configuration failures. We also claim that the direction of the schedule is an open empirical question in this domain, and that answering it is useful for anyone designing masked objectives for agents. The schedule can move from short hidden spans to long ones, or from long to short.
Relation to Prior Work
The closest work is CurrMask. It masks contiguous blocks of state–action pairs in offline robot-control trajectories and picks block size and mask ratio with an EXP3 bandit, a method that adaptively chooses among fixed configurations. It reports a 32% skill-prompting gain over the non-curriculum masked baseline MaskDP, at 4.7% compute overhead. We reuse its central insight that consecutive states are redundant, so block masking is needed. We also use its bandit as one scheduling arm. We differ in three ways. Our states are symbolic filesystem and package states, not continuous vectors. Our targets are computed by re-execution rather than read from a replay buffer. Our masked objective is auxiliary to an agent policy, not a standalone pretraining task.
Two terminal data pipelines motivate the proposal and supply our data and baselines. TerminalTraj builds 32,325 Docker images and 50,733 verified trajectories, then trains by plain supervised fine-tuning. On Data Engineering for Scaling LLM Terminal Capabilities studies filtering, data-level curricula and context extension for Nemotron-Terminal. Neither hides or predicts environment consequences. Both treat the container only as a generator and verifier of text logs. We turn the container into a source of training targets that the logs do not contain.
CodeExecutor is the nearest precedent for predicting execution state. It trains a model to output line-by-line variable states for mutated single-file Python programs, using a fixed three-corpus staging, and reaches 48.06% output accuracy on CodeNetMut. We move from variable dictionaries in toy scripts to operating-system state in real containers, and from fixed data staging to a masking schedule. AOSpec trains an observation predictor and uses copy-on-write container forks to speculate at serving time. That shows terminal observations are predictable enough to be useful, but it is a latency system and not a training objective. Our copy-on-write replay borrows its sandbox technique. BRIDGE shows that masked, shuffled reconstruction of reasoning steps helps small models learn causal order in math. It only masks text, with no environment to ground the targets.
The directionality literature constrains our design. Dynamic Masking Rate Schedules for MLM Pretraining finds that for BERT a decreasing masking rate beats constant and increasing ones, with a 1.89x speedup to baseline GLUE accuracy. DailyMAE, Wang et al. and Hu et al. argue for increasing schedules in images, medical imaging and graphs. Terminal traces mix formal syntax with long, semi-structured output, so neither result transfers by default. We therefore treat direction as something to measure, not assume.
Research Program
The first component is a replay-and-snapshot pipeline built on the TerminalTraj images and the Harbor sandbox from Terminal-Bench. Each verified trajectory is re-executed step by step in a copy-on-write fork. After each command we record a normalized state diff: added, removed and modified paths with content hashes or short content for small text files, the package-manager state for apt, pip and npm, the environment variables, and the exit code. The flaky-test literature (A Qualitative Study on the Sources, Impacts, and Mitigation Strategies of Flaky Tests) tells us where non-determinism comes from: time, network, randomness and ordering. So every trajectory is replayed twice. Steps whose diffs disagree between the two replays are marked non-deterministic and never used as prediction targets. The replay-agreement rate is itself a reported result, because it bounds how much of the data this method can use.
The second component is the objective, which is made compatible with a decoder-only model. For a trajectory, we choose a start step $t$ and a block length $k$. We delete the observations for steps $t$ through $t+k-1$ from the context, keeping the commands. At the end of the block we append a special segment in which the model must generate the cumulative state diff and the final exit code and output. The training loss is
$$ L = L_{\text{act}} + \lambda \, L_{\text{state}}(k), $$
where $L_{\text{act}}$ is the usual cross-entropy on the agent's commands given full, unmasked context, and $L_{\text{state}}(k)$ is cross-entropy on the hidden-block diff segment for block length $k$. The weight $\lambda$ trades off the two. We never train commands under hidden observations, so the policy is not taught to act blindly. Hiding only affects the auxiliary prediction.
The third component is the schedule over $k$ and over the fraction of trajectories that receive a masked block. We compare an increasing schedule (k from 1 to 8), a decreasing schedule (8 to 1), a constant schedule at the mean block length, and a CurrMask-style EXP3 bandit. The bandit is rewarded by reduction in held-out state-prediction loss, and we log its overhead. All schedules see the same number of masked targets.
Baselines
The naive reference point is the base Qwen2.5-Coder backbone, unmodified, run with the neutral Terminus 2 scaffold. This measures how much any fine-tuning buys.
The strongest competitor is TerminalTraj-style supervised fine-tuning on the same trajectories. That paper reports that TerminalTraj-32B reaches 22.00% on Terminal-Bench 2.0 and 35.30% on Terminal-Bench 1.0 (TerminalTraj). Nemotron-Terminal-32B reports 27.4% on Terminal-Bench 2.0 with a different, larger data mix. These published numbers are anchors only, because data, scaffolds and budgets differ. The fair comparison is our own reproduction: supervised fine-tuning with the same backbone (7B and 32B), the same trajectories, the same total training tokens and optimizer steps, and the same hyperparameter search budget, evaluated with the same harness and seeds. Because the auxiliary segments add tokens, the baseline gets extra action-imitation tokens to equalize compute. Beating it means a gain on Terminal-Bench 2.0 that exceeds the seed-to-seed spread across at least three training seeds, together with a measurable reduction in the share of GitTaskBench failures attributed to environment setup.
Three ablations isolate the proposal's ingredients. The first uses the same objective with only command-output text as the target and no container-derived diff. This tells us whether re-execution adds anything beyond what the logs already contain. The second uses constant block length. This isolates the curriculum. The third uses block length fixed at one step, which is single-step next-observation prediction as in a world-model loss. This isolates block masking, which is CurrMask's key ingredient.
Why not just…?
Why not just do supervised fine-tuning on more trajectories? This is the most serious threat. TerminalTraj and Nemotron-Terminal show that data scale alone moves Terminal-Bench a lot. Our compute-matched baseline gives supervised fine-tuning the extra tokens our auxiliary loss consumes. If the extra tokens help as much as state prediction, we will report that plainly, and the idea loses. What favors state prediction is GitTaskBench's finding that the dominant failure is setup. Imitation data contain the right setup commands but never teach the model to check what they did. The failure-attribution analysis tests exactly that.
Why not just paste the state diffs into the context as extra text? Showing the model diffs at training time, with no hiding, is cheaper and needs no curriculum. It is a strong alternative, and we run it as a baseline. It also changes the test-time input format unless diffs are computed at inference, which is possible inside a container. So we evaluate it both ways, and the comparison tells us whether the value lies in predicting consequences or merely in seeing them.
Why not just use a fixed masking rate, since fixed rates work for BERT and MAE? The evidence from Dynamic Masking Rate Schedules for MLM Pretraining is that schedules beat constants, but the gains there were modest (+0.46 GLUE for BERT-base), so a constant schedule may well suffice here. The constant-length ablation settles this. If it matches the scheduled versions, we will say the container-grounded targets carry the effect and the curriculum does not. That is a useful negative result for the curriculum literature.
Why not just train with reinforcement learning on pass/fail outcomes? Outcome rewards are sparse on tasks where a single evaluation can take up to two hours (Terminal-Bench). Dense state-prediction targets are cheap by comparison, since each replay yields a target at every step. We do not claim this replaces reinforcement learning. The two are complementary, and we test whether a state-prediction warm start improves a subsequent outcome-reward stage, following BRIDGE's structure of a masked-reconstruction warm-up before reinforcement learning.
Proposed Experiments
The main evaluation is Terminal-Bench 2.0 and 1.0 pass rate under Terminus 2, reported with pass@1 over repeated runs. We add GitTaskBench (the QuantaAlpha/GitTaskBench suite), with failures re-attributed into setup versus logic categories using the paper's protocol. We also report a held-out intrinsic metric: exact-match and path-level F1 of predicted state diffs on TerminalTraj domains excluded from training, broken down by block length.
The first decisive check is whether intrinsic state-prediction accuracy on held-out containers correlates with downstream Terminal-Bench gains across our variants. If models that predict diffs better do not act better, the mechanism is wrong regardless of headline numbers. The second is the directionality experiment at matched compute: increasing, decreasing, constant and bandit schedules, at two model sizes. A consistent winner across sizes would resolve for this domain the tension between Dynamic Masking Rate Schedules for MLM Pretraining and the vision and graph results. The third is the failure-category shift on GitTaskBench. Our hypothesis predicts gains concentrated in setup and dependency failures, and a gain spread evenly across categories would point to a generic regularization effect instead.
Finally, we report replay agreement and the fraction of steps discarded as non-deterministic. The method's reach is limited by how reproducible the environments really are, and that limit should be stated rather than hidden.
References
- GitTaskBench: A Benchmark for Code Agents Solving Real-World Tasks Through Code Repository Leveraging
- Learning Versatile Skills with Curriculum Masking
- Large-Scale Terminal Agentic Trajectory Generation from Dockerized Environments
- On Data Engineering for Scaling LLM Terminal Capabilities
- Code Execution with Pre-trained Language Models
- AOSpec: Action and Observation Co-Speculation for Low-Latency Agent Serving
- Curriculum Learning for Efficient Chain-of-Thought Distillation via Structure-Aware Masking and GRPO
- Dynamic Masking Rate Schedules for MLM Pretraining
- DailyMAE: Towards Pretraining Masked Autoencoders in One Day
- MPS-AMS: Masked Patches Selection and Adaptive Masking Strategy Based Self-Supervised Medical Image Segmentation
- Bridging the User-side Knowledge Gap in Knowledge-aware Recommendations with Large Language Models
- Terminal-Bench: Benchmarking Agents on Hard, Realistic Tasks in Command Line Interfaces
- A Qualitative Study on the Sources, Impacts, and Mitigation Strategies of Flaky Tests