For big jobs the agent writes JavaScript instead of calling tools one by one. The code joins, aggregates, and exports across your datasources in a sandbox, and the result lands as a file in your workspace.
const orders = await query("shop", ordersSql);
const subs = await query("billing", subsSql);
const ltv = joinOnCustomer(orders, subs);
await writeFile("ltv.csv", toCsv(ltv)); Done. 48,102 customers joined across both databases, sorted by lifetime value:
Ask a follow-up…
| customer | orders | mrr | ltv |
|---|---|---|---|
| Acme | 184 | $4,200 | $31,400 |
| Initech | 97 | $8,900 | $27,800 |
| Wayne | 212 | $11,200 | $24,100 |
| Northwind | 64 | $3,100 | $18,700 |
| Umbrella | 51 | $2,400 | $12,300 |
The code fetches and crunches the data inside the sandbox. The model sees the summary and the file name, not a million rows of context.
Every query the code runs goes through the same access policies as the ordinary tools. A column you hid from the AI stays hidden inside code mode too.
Inside the sandbox
await query("shop",
"SELECT email FROM customers"); Runs live in an isolated worker with data functions as the only globals. You can watch the code before it finishes and stop it at any point.