Run sandbox

Runs one command inside the caller's sandbox and answers its exit code, stdout and stderr.

POST /v1/sandbox/run

Addresshttps://api.hanzo.ai/v1/sandbox/run
MethodPOST
Operationrun_in_sandbox
AuthAuthorization: Bearer $HANZO_API_KEY

Runs one command inside the caller's sandbox and answers its exit code, stdout and stderr. A non-zero exit is a successful call carrying a failed program, so it comes back as data and not as an error.

Name a session and the command NARRATES INTO IT: its output is appended to that session's live log as the program produces it, so anything watching the session — GET /v1/agent/sessions/stream, scoped to one run with ?root= — watches the work happen rather than waiting for the verdict. Without it the call is what it always was: silent until it returns, which for an agentic run is twenty-five minutes of blank screen.

The session is named; the TENANT is not. It is the org the caller already proved, so a session belonging to somebody else is absent from the org this call acts for and the append is refused there.

Request

9 fields, body application/json (required).

FieldInTypeRequiredDescription
argvbodystring[]—Argv is the program and its arguments, already split — the form no shell can misread.
blindbodystring[]—Blind is the set of secrets this command must never publish.
commandbodystring—Command is a shell line, run by sh -c.
dirbodystring—Dir runs the command somewhere other than the sandbox's working directory, which Leased.Workdir names.
eventsbodyboolean—Events says the command writes JSON lines to stdout, one event each, as an agent harness's --json does: each is appended to Session as one event, in the shape the command wrote it, and stderr is narrated as output.
idbodystring—ID is the sandbox to run in, from an earlier lease.
sessionbodystring—Session is the live agent session this command narrates into: its output is appended there AS IT IS PRODUCED, so every surface watching that session watches the command work instead of a blank pause.
stdinbodystring—Stdin is fed to the program on standard input.
timeoutSecbodyinteger (int64)—TimeoutSec bounds this ONE command, so a wedged program holds the caller for its own timeout rather than for the whole lease.

Response

StatusBodyMeaning
200sandbox.Ranok
defaultproblem-detailsrefused

200 body — 3 fields.

FieldInTypeAlwaysDescription
exitCodebodyinteger (int64)—ExitCode is the PROGRAM's own status — 0 succeeded, anything else is what it returned, and a Command runs under sh -c so its shell's conventions apply.
stderrbodystring—Stderr is standard error, kept apart from Stdout so a caller reading a program's OUTPUT is not reading its diagnostics as data.
stdoutbodystring—Stdout is what the program wrote to standard output, collected whole rather than streamed — to watch it arrive instead, name a RunIn.Session and read that session's feed.

Failure carries the platform error shape — see Errors.

Examples

hanzo sandbox run
import { Configuration, SandboxApi } from 'hanzoai';

const api = new SandboxApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.runInSandbox({ argv: ["<argv>"], blind: ["<blind>"] });
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import SandboxApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = SandboxApi(client).run_in_sandbox(argv=["<argv>"], blind=["<blind>"])
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.SandboxAPI.RunInSandbox(context.Background()).Execute()
if err != nil {
	return err
}
use hanzo_client::apis::{configuration::Configuration, sandbox_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = sandbox_api::run_in_sandbox(&cfg, Default::default()).await?;
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.SandboxApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new SandboxApi(client).runInSandbox();
curl -X POST https://api.hanzo.ai/v1/sandbox/run \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "argv": [
         "<argv>"
       ],
       "blind": [
         "<blind>"
       ]
     }'

Tool sandbox, op run_in_sandbox — POST the JSON-RPC envelope to https://api.hanzo.ai/v1/mcp.

curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "sandbox",
         "arguments": {
           "op": "run_in_sandbox",
           "input": {
             "argv": [
               "<argv>"
             ],
             "blind": [
               "<blind>"
             ]
           }
         }
       }
     }'

Sandbox API · All Hanzo APIs · Interactive reference

Was this page useful?