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, 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 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:

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:

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:

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

## 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 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. 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.

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

sandscale workspace stop --ws-id WORKSPACE_ID 

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

Originally published on the Sandscale blog.