A LlamaIndex.TS data agent that runs its Python in a Sandscale sandbox A developer built a LlamaIndex.TS data agent that answers analytical questions over CSV files by writing and executing Python inside a Sandscale sandbox, keeping model-generated code off the host server. The agent's tools are constructed per sandbox, closing over a single sandbox ID so the model cannot target another box, and data files are written into /workspace/data before the agent runs, with the sandbox stopped in a finally block. LlamaIndex is best known for retrieval, but its agent workflows are a good fit for a different kind of question: the ones you answer by computing, not by looking up. "Which region grew fastest last quarter?" over a few CSV files is a job for a short Python script. This guide builds a LlamaIndex.TS agent that writes that script and runs it in a Sandscale sandbox https://sandscale.dev/sandboxes , so code the model wrote never runs on your server. Type-checked with tsc --strict against llamaindex 0.12, @llamaindex/workflow 1.1, @llamaindex/openai 0.4, zod 4 and @sandscale/sdk 1.0. The Sandscale calls are from the TypeScript SDK reference https://sandscale.dev/docs/sdks/typescript . npm install llamaindex @llamaindex/workflow @llamaindex/openai zod @sandscale/sdk export SANDSCALE API KEY=... export OPENAI API KEY=... js import { tool } from 'llamaindex'; import { agent } from '@llamaindex/workflow'; import { openai } from '@llamaindex/openai'; import { z } from 'zod'; import { Sandscale } from '@sandscale/sdk'; const sandscale = new Sandscale ; // reads SANDSCALE API KEY const clip = s: string, n = 8 000 = s.length n ? s.slice 0, n + \n cut ${s.length - n} chars : s ; // Tools are built per sandbox, so each agent run can only reach its own box. function sandboxTools sandboxId: string, region?: string { const runPython = tool { name: 'run python', description: 'Run a Python 3 script in an isolated sandbox with the data files in /workspace/data. ' + 'Print what you need to see. There is no network access. Output over 8,000 characters is cut.', parameters: z.object { code: z.string .max 20 000 , } , execute: async { code } = { await sandscale.sandboxes.writeFile sandboxId, '/workspace/main.py', code, { region } ; const r = await sandscale.sandboxes.run sandboxId, 'python3', '/workspace/main.py' , { region, workdir: '/workspace', timeoutSeconds: 120, } ; return { exit code: r.exitCode, timed out: r.timedOut, oom killed: r.oomKilled, stdout: clip r.stdout , stderr: clip r.stderr, 4 000 , }; }, } ; const listData = tool { name: 'list data files', description: 'List the data files available in /workspace/data.', parameters: z.object {} , execute: async = { const entries = await sandscale.sandboxes.listFiles sandboxId, '/workspace/data', { region } ; return entries.map e = e.name ; }, } ; return runPython, listData ; } export async function ask question: string, files: Record