Skip to main content
Automate ML research iteration with an LLM agent that reads your training script, proposes targeted code changes, and validates each change by running it in an isolated sandbox. Inspired by Karpathy’s autoresearch (March 2026), the loop runs unattended — each accepted modification becomes the new baseline, and the agent builds on what it has already learned.

How it works

  1. Calibrate: Run the baseline training script 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: Parse val_loss from each sandbox’s stdout. The candidate with the lowest loss wins the round.
  5. Hill-climb: Accept the winner only if it beats the current best. Update the baseline script and history.
  6. Repeat: Loop until the iteration budget is exhausted.

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 is killed automatically when the step budget completes.

Prerequisites

Create a .env file in your project root:

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.
Use the OpenAI response to generate each candidate script, then keep appending accepted experiments to your history exactly like the Python version below.

Full example

Pass --smoke for a fast proof-of-concept run (3 iterations, 2 candidates, 150 training steps, ~5 minutes). The full run uses 8 iterations, 3 candidates, and 300 steps (~20 minutes).

What happens step-by-step


Key design decisions

Increasing temperature across candidates

Each candidate is proposed with 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 Δ. This prevents the agent from re-proposing changes that already failed and nudges it toward unexplored directions without any external memory store.

Fixed STEPS budget enforced in program.md

The STEPS constant is explicitly marked as off-limits in the guidance. Without this constraint, the agent could trivially reduce val_loss by running more training steps — a form of reward hacking that would make comparisons between candidates meaningless.

Greedy hill-climbing over rollout

The loop uses simple 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 maximises the number of validated improvements within the time budget.
This example uses python-dotenv to load your API keys. Create a .env file in your project root:
Both clients pick them up automatically.

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.