# How do I run many tasks at once?

Submit up to 1000 jobs in one **batch**: each runs in its own clean sandbox, at most as many at a time as you choose, under one price limit for all of them. A failed job does not stop the others, and you get a CSV report at the end.

## Steps

1. **Make a list of jobs** – usually one command with a different input each time.
2. **Submit them as a batch** with `max_concurrency` (how many run at once) and `max_total_cost` (the price limit of the whole batch).
3. **Wait** for the batch on the server.
4. **Download the report**: one row per job with its status, exit code and cost.

**Ask your assistant**

No code: copy this into Claude or ChatGPT with [WBX Sandbox connected](https://sandbox.wbx.cz/docs/connect.md) and change it to fit.

```
Run 20 WBX jobs as one batch: job number n computes n squared and writes it to output/square.txt. Run at most 10 at a time, with a price limit of US$0.50 (5 Kč) for the whole batch. When it has finished, give me the CSV report.
```

**Python**

`pip install wbxsandbox`, your key in `WBXSANDBOX_API_KEY`.

```
from wbxsandbox import run_batch

jobs = [{"command": f"mkdir -p output && python -c 'print({n} ** 2)' > output/square.txt"} for n in range(20)]
batch = run_batch(jobs, defaults={"timeout_seconds": 120, "save_artifacts": True},
                  max_concurrency=10, max_total_cost="0.50")   # for CZK use "5"
batch.wait()
print(batch.summary()["status"])     # completed / partial / failed
open("report.csv", "w").write(batch.report_csv())
```

**TypeScript**

`npm install wbxsandbox` (Node.js 20+); save as `.mts` for top-level `await`.

```
import { writeFile } from "node:fs/promises";
import { WBX } from "wbxsandbox";

const wbx = new WBX();
const jobs = Array.from({ length: 20 }, (_, n) => ({ command: `mkdir -p output && python -c 'print(${n} ** 2)' > output/square.txt` }));
const batch = await wbx.batches.create({
  jobs, defaults: { timeoutSeconds: 120, saveArtifacts: true },
  maxConcurrency: 10, maxTotalCost: "0.50",   // for CZK use "5"
});
await batch.wait();
console.log((await batch.summary()).status);   // completed / partial / failed
await writeFile("report.csv", await batch.reportCsv());
```

**curl**

Just `curl` and `jq`; your key in `WBXSANDBOX_API_KEY`.

```
H="Authorization: Bearer $WBXSANDBOX_API_KEY"
JOBS=$(seq 0 19 | jq -s -c 'map({command: "mkdir -p output && echo \(. * .) > output/square.txt"})')
BATCH=$(jq -n --argjson jobs "$JOBS" '{jobs: $jobs, defaults: {timeout_s: 120, save_artifacts: true},
  max_concurrency: 10, max_total_cost: "0.50"}' | curl -s -X POST https://sandbox.wbx.cz/v1/batches -H "$H" -d @- | jq -r .batch.id)   # for CZK use "5"
curl -s -X POST https://sandbox.wbx.cz/v1/jobs/wait -H "$H" -d "{\"batch_ids\": [\"$BATCH\"], \"timeout_s\": 60}"
curl -s "https://sandbox.wbx.cz/v1/batches/$BATCH/report?format=csv" -H "$H" -o report.csv
```

## How to tell it worked

- The summary says `completed`.
- `report.csv` has 20 rows plus the header, all `completed` with exit code `0`.
- In the portal, *Jobs* shows the batch and its progress while it runs.

## If it doesn't work

| What you see | What to do |
| --- | --- |
| `422 budget_too_low` | The worst case of all jobs together is above `max_total_cost`. Shorten the time limits, submit fewer jobs or raise the limit. |
| The batch ends as `partial` | Some jobs failed. Their rows in the report show why; run just those again. |
| Jobs stay `queued` a long time | No more than your plan's concurrent sandboxes run at once (2 on Free) – the rest wait their turn. |
| `429 queue_full` | You would have more than 1000 jobs waiting. Wait, or submit fewer. |

## What it costs

Each job is billed for the time it runs. `max_total_cost` is reserved for the whole batch at once and released as jobs finish – you pay only what the jobs really used.

## Next steps

- [Batches](https://sandbox.wbx.cz/docs/jobs/batches.md): Dependencies between jobs, cancelling and the report.
- [A batch of 100 tasks](https://sandbox.wbx.cz/docs/guides/batch.md): A longer example with dependencies and collected results.
- [Passing files between jobs](https://sandbox.wbx.cz/docs/jobs/inputs.md): Give one job the results of another.

Source: https://sandbox.wbx.cz/docs/howto/batch
