Skip to main content
Automate machine learning (ML) research iteration with a large language model (LLM) agent. The agent reads your training script, proposes targeted code changes, and validates each change in an isolated sandbox. The loop follows Karpathy’s autoresearch (March 2026) and runs unattended. Each accepted modification becomes the new baseline, so the agent builds on what it has already learned.

How it works

Each iteration runs 6 steps, from calibration to the next proposal:
  1. Calibrate: The baseline training script runs in a sandbox to establish a starting validation loss.
  2. Propose: The agent reads the current best script and experiment history, then proposes N candidate modifications (with increasing temperature for diversity).
  3. Race: All N candidates run in parallel Tensorlake sandboxes for a fixed step budget.
  4. Evaluate: The loop parses val_loss from each sandbox’s stdout. The candidate with the lowest loss wins the round.
  5. Hill-climb: The loop accepts the winner only if it beats the current best, then updates the baseline script and history.
  6. Repeat: The loop continues until the iteration budget runs out.

Why sandboxes are required

The agent emits complete, self-contained Python scripts. Running untrusted LLM-generated training code in your host process would be unsafe. The model could write arbitrary filesystem operations or import unexpected packages. Each candidate runs in an isolated sandbox with a fixed memory ceiling, and the sandbox terminates automatically when the step budget completes.

Prerequisites

You need Python, the packages below, and API keys for Tensorlake and OpenAI:
Create a .env file in your project root. The script calls load_dotenv(), and both the Tensorlake SDK and the OpenAI client read the keys from the environment:

TypeScript SDK starter

The Node.js version follows the same core loop: propose candidates, race them in parallel sandboxes, parse val_loss, and keep the winner.
Generate each candidate script from the OpenAI response, then append every experiment, accepted or rejected, to your history as the Python version below does.

Full example

The script below runs the whole loop: calibrate the baseline, propose candidates, race them, keep the winner, and repeat. Pass --smoke for a proof-of-concept run with 3 iterations, 2 candidates, and 150 training steps, about 5 minutes. The full run uses 8 iterations, 3 candidates, and 300 steps, about 20 minutes.

What happens step-by-step

Each iteration has 6 components, from calibration to the next prompt:

Key design decisions

Four choices shape the search: rising temperature across candidates, history as memory, a locked step budget, and greedy acceptance.

Increasing temperature across candidates

The agent proposes each candidate at a slightly higher temperature (0.9 + candidate_idx * 0.1). The first candidate is a focused, conservative change. Later candidates are more exploratory. This covers both the safe and speculative ends of the search space in a single iteration.

Experiment history as agent memory

The agent receives a rolling window of the last 8 experiments, accepted and rejected, each annotated with val_loss and Δ. It therefore doesn’t re-propose changes that already failed, and it explores new directions without an external memory store.

Fixed STEPS budget enforced in program.md

The guidance marks the STEPS constant as off-limits. Without this constraint, the agent could lower val_loss by running more training steps. That is reward hacking, and it would make comparisons between candidates meaningless.

Greedy hill-climbing over rollout

The loop uses greedy acceptance (accept if Δval_loss > 0) rather than beam search or rollout. For an overnight research loop where each experiment costs real CPU time, greedy hill-climbing maximizes the number of validated improvements within the time budget.

What to build next

RL Training with GSPO

Train a model directly with RL using sandboxes as the reward oracle, a complementary approach to autoresearch.

Agentic Swarm Intelligence

Dispatch parallel sandboxes across a swarm of specialized worker agents.