# Rust and Cargo teams: setting up the coding agent's test loop on its own machine

> cargo test is fast once the crate is compiled, and slow on a cold target directory. How a Rust team can give each coding agent its own cloud machine so the toolchain and target/ persist: what to put in the template, the single-test commands, and what to leave for the full suite.

cargo test is fast once the crate is compiled, and slow on a cold target directory. How a Rust team can give each coding agent its own cloud machine so the toolchain and target/ persist: what to put in the template, the single-test commands, and what to leave for the full suite.

December 2, 2026 · 4 min read · The Sandscale team

A Rust service or CLI is a good fit for a coding agent, and a poor fit for a laptop that several agents share. The first `cargo test` in a crate downloads crates, compiles a graph of dependencies and then compiles the tests. Later runs reuse `target/` and are much cheaper. Two agents sharing one `target/` directory will fight over it; two agents sharing one laptop will fight over memory and CPU while a release-sized compile is in progress.

This post is about setting up one agent’s machine for a Cargo workspace so the edit-test loop stays on that machine. Cargo behaviour comes from the [`cargo test` command reference](https://doc.rust-lang.org/cargo/commands/cargo-test.html), read on 2 December 2026. Sandscale commands are from CLI 1.4.1. We do not show test output, because it depends on your crate.

## Why a machine per agent suits Cargo

Three properties of a Rust build matter for agents:

- **A cold `target/` is expensive.** `cargo test` compiles the package and its tests into a special executable, then runs it. The work is written into `target/`. The next run in the same directory reuses that work.
- **The default profile is already aimed at feedback.** The Cargo documentation says `cargo test` uses the `test` profile by default, “which enables some optimizations and disables debugging information for fast feedback.” Switch to `--profile=debug` only when someone needs to debug a test.
- **Workspace layout is easy to get wrong.** In a virtual workspace, with no package selected, `cargo test` tests all members. In a non-virtual workspace it tests the root crate. An agent that runs `cargo test` from the wrong directory can compile more than the change needs, or miss the package it just edited.

A Sandscale [workspace](https://sandscale.dev/workspaces) is a persistent cloud machine with its own disk, CPU and memory, per agent. The disk survives stops and starts, so the Rust toolchain, the crate cache and `target/` are still there next time. The first build is the slow one.

## What goes in the template

Ask whoever administers your workspace templates to put these in once, so no agent installs them on the fly:

- A pinned Rust toolchain, the same rustc and Cargo versions your CI uses. `rust-toolchain.toml` in the repository is the usual way to pin the channel; the template should have `rustup` so the pin can be applied.
- `git`, and `clang` or another C compiler if any of your crates use a `build.rs` that compiles C or C++.
- Whatever else the tests call (a database client, for instance).

Then each engineer creates a machine for the task:

```sh
sandscale workspace create --name rust-4412-parser --template-id TEMPLATE_ID --ttl-seconds 28800
sandscale workspace ssh rust-4412-parser
```

Whether the machine can reach crates.io or your internal registry depends on your plan and your organization’s network policy. If the first `cargo test` or `cargo fetch` cannot download, that is the first place to look.

## Warm the cache once

Before handing the agent a task, fetch and compile once on the machine so the agent does not pay for a cold start in its first loop:

```sh
cargo fetch
cargo test --workspace --no-run
```

`cargo test --no-run` is from the documentation: it compiles the tests but does not run them. `--workspace` tests all members. Treat this as a warm-up, not a guarantee that every later command is offline; a new dependency still needs the network.

## The loop: one test, not the workspace

An agent that reruns `cargo test --workspace` after every edit will be slow on any machine. Teach it the narrow forms first. All of these are standard Cargo options:

```sh
cargo test -p parse --lib
cargo test -p parse --lib slice_bounds
cargo test -p parse --test integration
```

`-p parse` (the same as `--package parse`) selects one workspace member. `--lib` runs the library unit tests. A bare name after the options, `slice_bounds` here, is passed through to libtest and filters to tests whose names contain that string, as the Cargo documentation describes. `--test integration` runs one integration test target by its name.

Doctests run by default. If they are slow or not useful in the loop, the agent can skip them with `--doc` left out and `--lib` or `--test` used instead; do not invent a flag. Check the options against `cargo test --help` on the toolchain you pinned.

If a test is failing and the agent is about to add `-- --test-threads 1` or `--no-fail-fast`, that is fine for diagnosis. It should not change the crate’s default test settings to hide a failure.

## The AGENTS.md block

```markdown
## Build and test (Rust)
- Use the repository's rust-toolchain.toml. Do not rustup override or install a
  different toolchain.
- While working, run only the package and tests you changed:
  cargo test -p <package> --lib <test_name>
- Before committing a package, run: cargo test -p <package>
- Do not delete target/ or CARGO_HOME to "fix" a build. If a compile looks stuck
  on crates.io, say so and stop.
- Do not edit Cargo.lock unless the task says to change a dependency.
- Before opening a PR, run cargo test --workspace once and put the result in the
  PR description.
```

## What the reviewer checks

A Cargo lockfile change in a pull request is a signal, the same way a Node lockfile is. If the task did not ask for a dependency change, ask why. Look at which crates were added or had their versions changed, not at every line. Our [reviewer checklist](https://sandscale.dev/blog/reviewing-an-agent-diff-checklist) covers the rest.

## The full suite

`cargo test --workspace` before the pull request, on the agent’s machine if it fits, or on a larger leased machine if the workspace is heavy; see [leasing a build host for a full test suite](https://sandscale.dev/blog/build-host-lease-for-a-full-test-suite). CI on the pull request stays the merge gate, not the agent’s loop. That split is the subject of [why the edit-test loop should not wait on CI](https://sandscale.dev/blog/agent-edit-test-loop-should-not-wait-on-ci).

When the task is done, stop the machine. A running machine counts toward the plan’s hours whether the agent is busy or waiting:

```sh
sandscale workspace stop --ws-id WORKSPACE_ID
```

The disk is kept, so the next task starts with a warm `target/`.

**On this page**

1. Why a machine per agent suits Cargo
2. What goes in the template
3. Warm the cache once
4. The loop: one test, not the workspace
5. The AGENTS.md block
6. What the reviewer checks
7. The full suite

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [December 2, 2026 · **Auditing the MCP tool calls your team's coding agents make** · When Claude Code, Codex, Cursor or Gemini CLI call MCP tools, the record of what happened can live in three places: the client, the MCP server, and the system behind it. What each layer can see, which one to trust as the record, whether to keep arguments, and how to read Sandscale's audit log for agent calls from the CLI.](https://sandscale.dev/blog/auditing-mcp-tool-calls)
- [December 2, 2026 · **Coding agents on client projects: a team lead's checklist for one machine per agent** · Services teams run Claude Code, Codex and Cursor across several client codebases at once. When those agents share developer laptops, client code, credentials and history mix. A checklist for team leads: one machine per agent per client, secrets kept per client, who can start and stop what, the audit record a client may ask for, and a clean exit at the end of the engagement.](https://sandscale.dev/blog/client-projects-one-machine-per-agent-checklist)

---
Source: https://sandscale.dev/blog/rust-and-cargo-teams-the-agent-test-loop-on-its-own-machine
