# Run a sandbox agent job A deployed app can give a model a task and a Linux sandbox to work in. The model can run a shell command, read its output and decide what to do next. Your app gets the final answer. A regular [sandbox job](sandbox-api.md) runs the command you supply. A [sandbox session](sandbox-workbench.md) gives you a machine where you can run your own coding agent directly, even without a deployed app. ## Before you start The workspace needs a worker. In the app’s **Sandboxes → Settings**, the owner enables sandbox access and approves the people who can run jobs. In **Connections**, enable AI for the app and allow the model tier you want to use. Deploy the app with those settings. [AI setup and budgets](llm.md#enable-ai-for-an-app). Model calls use the app’s AI access and budget. Smolcloud calls the model through the gateway, so the sandbox can keep outbound networking blocked. The provider receives the prompt and any command output the model reads. The provider key stays outside the sandbox. ## Submit a task Here’s how a Node backend can ask the agent to inspect a test log. Pass in the incoming request, the log text and a UUID you generated for this task. Keep the UUID and inputs if you need to retry. ```js async function inspectTestLog(request, logText, jobKey) { const context = request.headers.get("X-Innie-Connector-Context"); if (!context) throw new Error("Missing caller context"); const response = await fetch(process.env.SANDBOX_API_URL, { method: "POST", redirect: "error", headers: { Authorization: `Bearer ${process.env.SANDBOX_API_TOKEN}`, "Content-Type": "application/json", "X-Innie-Connector-Context": context, }, body: JSON.stringify({ version: 1, idempotencyKey: jobKey, lifetimeSeconds: 120, agent: { prompt: "Inspect test.log in the input directory. Identify the first failing test and quote the error. If none failed, say so.", model: "everyday", tools: ["command"], maxSteps: 4, maxToolCalls: 8, }, files: { inputs: [ { path: "test.log", contentBase64: Buffer.from(logText).toString("base64"), }, ], }, }), }); if (!response.ok) throw new Error(`Job submission failed (HTTP ${response.status})`); return (await response.json()).id; } ``` The token and URL come from the deployment. Forward the caller context from the request delivered by the app gateway. A personal CLI token can’t start this kind of job. If submission times out, send the same body with the same UUID to get the original job ID. ## Collect the result Save the job ID when you submit the task. To show progress, have the client call your app again. In that request handler, use the deployment token and forward the fresh caller context from the app gateway. Each context expires after 30 seconds or four uses. The same signed-in user can check the job on the same deployment after the original context expires. Append the following paths to `SANDBOX_API_URL`, replacing `{jobId}` with the ID returned at submission. | Request | What to read | | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | `GET /{jobId}` | Poll `state` until `succeeded`, `failed` or `cancelled`. | | `GET /{jobId}/result` | On success, `result.stdout` holds the model’s final answer. If it failed, check `result.failure` when present and the job’s `reason`. | | `GET /{jobId}/exports` | Lists declared output files and their storage state. Check for `stored` before using a file. | | `POST /{jobId}/cancel` | Send `{"version":1}` to cancel. Poll the job for its final state. | The test-log example returns text and needs no bucket. For a file you want to keep, connect a bucket to the app, enable sandbox exports and declare the path in `files.exports`. Tell the agent to write there under `$INNIE_OUTPUT_DIR`. [Inputs and file exports](sandbox-api.md#supply-files). ## Limits - **Model calls.** Each step is one call to the model. The default is 4 steps and the maximum is 8. Each call requests up to 2,048 output tokens. The owner chooses the models behind `everyday` and `best`. - **Shell commands.** The agent has one tool, `command`, which runs inside the job’s sandbox. The default is 8 tool calls and the maximum is 16. If a command’s outcome is unknown, the runner stops. - **Time and output.** Set `lifetimeSeconds` between 15 and 3,600, within the workspace and app limits. The prompt and each command can be up to 8 KiB each. Command output and the final answer share a 64 KiB limit. If you see `agent_limit`, narrow the task or check which limit it reached. For `agent_policy`, check the app’s permissions and whether the model requested a supported command. For `agent_model`, check the model tier, provider and remaining budget.