# Run a sandbox job A job runs a shell command in a fresh sandbox and returns its output when it finishes. You can submit one from a script, a coding agent or a deployed app. For a terminal, live output or files you want to keep editing between commands, [start a session](sandbox-workbench.md). ## Submit a job This example checks a JSON settings file with Python. You need a sandbox with Python 3, access to run it, and a worker with available capacity. On your computer, you’ll use a shell, `curl`, `jq` and `uuidgen`. Set `ENV_ID` to the ID from `smolcloud sandbox list`. Set `WORKSPACE_URL` to your HTTPS management address and `WORKSPACE_ID` to the `tenantId` shown by `smolcloud doctor`. Load `WORKSPACE_TOKEN` from your secret store using your personal token or the agent’s own credential. [CLI sign-in](cli.md#sign-in). ```sh JOBS_URL="${WORKSPACE_URL%/}/api/sandbox-environments/$ENV_ID/sandbox-jobs" job_api() { printf 'Authorization: Bearer %s\n' "$WORKSPACE_TOKEN" | curl -fsS -H @- -H "X-Innie-Workspace: $WORKSPACE_ID" \ -H 'Content-Type: application/json' "$@" } JOB_KEY=$(uuidgen) ``` Submit the command and its input together. Keep the same `JOB_KEY` and body if the response is lost. Smolcloud returns the original job. Generate a new key each time you want the command to run again. ```sh JOB_BODY=$(jq -n --arg key "$JOB_KEY" '{ version: 1, idempotencyKey: $key, command: "python3 -m json.tool \"$INNIE_INPUT_DIR/settings.json\"", files: {inputs: [{path: "settings.json", contentBase64: ("{\"enabled\":true}" | @base64)}]}, lifetimeSeconds: 120 }') JOB_ID=$(job_api "$JOBS_URL" -d "$JOB_BODY" | jq -er '.id') ``` A new job returns HTTP 201. A retry with the same key and body returns 200. Reusing the key with a different body returns 409. ## Read output and cancel Run the first command to check the job. Once its state is `succeeded`, `failed` or `cancelled`, run the second to read the result. ```sh job_api "$JOBS_URL/$JOB_ID" | jq '{state, reason}' job_api "$JOBS_URL/$JOB_ID/result" | jq '.result' ``` For the settings file above, expect `exitCode: 0` and the formatted JSON in `stdout`. Invalid JSON produces a nonzero exit code and an explanation in `stderr`. If the command never ran, the result can be null. Check the job’s `reason` in that case. HTTP 410 means the saved input and output have expired. To stop a job, send the cancellation request below. You can repeat it safely. Poll the job until it reaches a final state. ```sh job_api "$JOBS_URL/$JOB_ID/cancel" -d '{"version":1}' ``` ## Supply files Each entry in `files.inputs` has a relative `path` and base64-encoded contents. The command reads those files under `$INNIE_INPUT_DIR`. For a file already on your computer, `jq -Rs '@base64' < settings.json` produces a JSON string for a text file’s `contentBase64` value. **To keep an output file from an app job**, connect an approved bucket and have the owner allow sandbox file exports. Then declare the file in `files.exports` and write it under `$INNIE_OUTPUT_DIR`. For example, declare `{"path":"result.json","maxBytes":4096}` and write to `"$INNIE_OUTPUT_DIR/result.json"`. After the job finishes, read its `/exports` endpoint to find the stored object. Standalone jobs return command output. To download a file from a standalone sandbox, use a [session and the CLI file commands](sandbox-workbench.md#bring-files-and-run-tests). ## API paths | Caller | Job collection | | --------------------------------------------- | ------------------------------------------------ | | Person or agent using a standalone sandbox | `/api/sandbox-environments/{envId}/sandbox-jobs` | | Person or agent using an app’s sandbox access | `/api/apps/{appId}/sandbox-jobs` | | Deployed app backend acting for a caller | `/api/workloads/apps/{appId}/sandbox-jobs` | On each collection, `POST` submits a job and `GET` lists up to 50 recent jobs you can see. Append `/{jobId}` for status, `/{jobId}/result` for output or `/{jobId}/cancel` to cancel. The two app routes also support `GET /{jobId}/exports`. For app jobs, the workspace owner enables sandbox access and approves callers in the app’s **Sandboxes → Settings**. A deployed backend sends its `SANDBOX_API_TOKEN` as a bearer token and forwards the incoming `X-Innie-Connector-Context` header. On the app routes, agents can request a structured response with `Accept: application/vnd.innie.agent-result+json; version=1`. The authenticated schema is at `GET /api/sandboxes/openapi.json`. ## Limits - **Time.** Request 15–3,600 seconds, within the owner’s configured limit. Waiting for a worker counts toward the deadline. - **Command and output.** A command can contain up to 8,192 UTF-8 bytes. Standard output and standard error share a 64 KiB limit. - **Files.** Up to four inputs of 64 KiB each. App jobs can export up to four files of 1 MiB each. To have a model choose which commands to run in an app’s sandbox, use an [agent job](sandbox-agent.md).