Skip to content
Wardcase Docs

Your first agent sandbox in five minutes

By the end of this page you will have run a small agent loop: a model picks a tool, the tool runs in a fresh sandbox, the result goes back to the model, and the sandbox is destroyed when the loop ends. Then you will read the audit trail of what happened. Every snippet is a complete file you can run, and every output block is what it prints.

Pick TypeScript or Python in any tab; the rest of the page follows.

  • Node 18 or later for TypeScript, or Python 3.10 or later.
  • A Wardcase account.

During private early access, signing up needs an invite code; write to business@wardcase.com for one.

Sign in to the dashboard at app.wardcase.com, open API keys and create a key. Keep the three scopes the dialog selects: sandboxes:read, sandboxes:write and audit:read. The key starts with vv_live_ and is shown once. Put it in an environment variable:

Terminal window
export VIVARIUM_API_KEY="vv_live_..."
Terminal window
npm install @vivarium/sdk tsx

The TypeScript examples run with tsx, which runs a TypeScript file directly.

Save this as hello.mts or hello.py and run it with npx tsx hello.mts or python hello.py.

hello.mts
import { Vivarium } from "@vivarium/sdk";
const vv = new Vivarium({ apiKey: process.env.VIVARIUM_API_KEY, baseUrl: "https://api.wardcase.com" });
// Resolves once the sandbox is running.
const sbx = await vv.sandboxes.create({ image: "python", region: "eu-west" });
console.log(sbx.id, sbx.status);
const result = await sbx.run("whoami && pwd && python -c 'print(sum(range(10)))'");
console.log("exit code:", result.exitCode);
console.log(result.stdout.trim());
await sbx.kill();
Output
sbx_4f9k2m8q1z7x3c5v running
exit code: 0
agent
/work
45

What happened:

  1. create asked for a sandbox from the python image in eu-west and returned once its host reported it running. Your id will differ.
  2. run sent a shell command. A string runs through /bin/sh -c; the result carries the exit code, stdout and stderr. The command ran as the unprivileged user agent in /work, the sandbox’s only writable directory.
  3. kill destroyed the sandbox. It moves to stopping, then stopped; its filesystem is deleted and billing ends.

An agent is a loop: ask the model for the next tool call, run it, give the model the result, repeat until it says it is done. Here the sandbox provides two tools, write_file and run, and a fixed plan stands in for the model so the file runs as it is.

Save this as agent.mts or agent.py and run it the same way.

agent.mts
import { Vivarium } from "@vivarium/sdk";
const vv = new Vivarium({ apiKey: process.env.VIVARIUM_API_KEY, baseUrl: "https://api.wardcase.com" });
// The tools your model can call. Each result goes back to the model as an observation.
type ToolCall =
| { tool: "write_file"; path: string; content: string }
| { tool: "run"; command: string }
| { tool: "finish"; answer: string };
// A stand-in for your model: a fixed plan, so this file runs as it is. Replace nextToolCall
// with a call to your LLM that sends the task and the observations and returns a tool call.
const PLAN: ToolCall[] = [
{ tool: "write_file", path: "/work/stats.py", content: "import statistics\nprint(statistics.mean([3, 5, 10]))\n" },
{ tool: "run", command: "python stats.py" },
{ tool: "finish", answer: "The mean is 6." },
];
async function nextToolCall(task: string, observations: string[]): Promise<ToolCall> {
return PLAN[observations.length] ?? { tool: "finish", answer: "No more steps." };
}
const task = "Compute the mean of 3, 5 and 10 with Python.";
const sbx = await vv.sandboxes.create({
image: "python",
region: "eu-west",
idleTimeoutS: 300, // destroyed after 5 idle minutes if this script dies
hardTimeoutS: 900, // and 15 minutes after creation, whatever happens
});
console.log("sandbox", sbx.id);
const observations: string[] = [];
try {
for (let step = 1; step <= 10; step++) {
const call = await nextToolCall(task, observations);
if (call.tool === "finish") {
console.log("answer:", call.answer);
break;
}
let observation: string;
if (call.tool === "write_file") {
const file = await sbx.files.write(call.path, call.content);
observation = `wrote ${file.path} (${file.size} bytes)`;
} else {
const r = await sbx.run(call.command, { timeoutS: 60 });
const late = r.timedOut ? " (timed out)" : "";
observation = `exit ${r.exitCode}${late}: ${(r.stdout + r.stderr).trim()}`;
}
console.log(`step ${step}: ${call.tool} -> ${observation}`);
observations.push(observation);
}
} finally {
await sbx.kill(); // always destroy it, even when a step throws
}
Output
sandbox sbx_4f9k2m8q1z7x3c5v
step 1: write_file -> wrote /work/stats.py (53 bytes)
step 2: run -> exit 0: 6
answer: The mean is 6.

Three things in this file are worth keeping in every agent you build:

  • Timeouts at creation. idleTimeoutS and hardTimeoutS (idle_timeout_s and hard_timeout_s in Python) make the platform destroy the sandbox even if your process crashes before kill runs. Without them, the defaults apply: 10 idle minutes and 60 minutes in total.
  • A timeout per command. timeoutS: 60 makes the host kill a command that runs longer, and the result says timedOut. The model gets that as an observation instead of your loop hanging.
  • kill in finally. The sandbox is destroyed whether the loop finishes, the model gives up or a call throws.

A non-zero exit code is a result, not an exception: the loop passes it to the model like any other output, which is usually what you want an agent to see.

The audit trail recorded the loop from outside the sandbox. Read it with the id the agent printed. Events come back newest first, so the script reverses them.

trail.mts
import { Vivarium } from "@vivarium/sdk";
const vv = new Vivarium({ apiKey: process.env.VIVARIUM_API_KEY, baseUrl: "https://api.wardcase.com" });
// The sandbox id the agent printed, for example: npx tsx trail.mts sbx_4f9k2m8q1z7x3c5v
const sandboxId = process.argv[2];
const page = await vv.audit.list({ sandboxId });
for (const event of page.data.reverse()) {
const { cmd, path, exit_code, reason } = event.payload;
console.log(event.type, JSON.stringify(cmd ?? path ?? exit_code ?? reason ?? null));
}
Output
sandbox.created null
sandbox.ready null
file.put "/work/stats.py"
exec.started ["/bin/sh","-c","python stats.py"]
exec.finished 0
sandbox.destroyed "api"

Each line is one event: the sandbox was created and became ready, the agent wrote /work/stats.py (the event also carries its size and SHA-256, never its contents), ran one command through /bin/sh -c, the command exited 0, and the sandbox was destroyed by an API call. If the last line is missing, the sandbox was still stopping; run the script again.

Reading the trail needs the audit:read scope. In production, give the key your agent uses only sandboxes:read and sandboxes:write, and read the trail with a separate key.

Replace nextToolCall (next_tool_call in Python) with a call to your model:

  1. Describe the two tools to the model: write_file with a path under /work and the content, and run with a shell command.
  2. Send the task and the observations so far.
  3. Map the tool call the model returns onto the same shape, and send each observation back as the tool’s result.

The sandbox side does not change. Keep the step limit: a model that never says it is done should not run forever.