Run a command in a sandbox you hold and read its output
Runs one command inside the caller's sandbox and answers its exit code, stdout and stderr.
POST /v1/sandbox/run
| Address | https://api.hanzo.ai/v1/sandbox/run |
| Method | POST |
| Operation | run_in_sandbox |
| Auth | Authorization: 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/agents/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
8 fields, body application/json (required).
| Field | In | Type | Required | Description |
|---|---|---|---|---|
argv | body | string[] | — | Argv is the program and its arguments, already split — the form no shell can misread. |
blind | body | string[] | — | Blind is the set of secrets this command must never publish. It exists because output is redacted where it is PRODUCED or not at all. |
command | body | string | — | Command is a shell line, run by sh -c. |
dir | body | string | — | Dir runs the command somewhere other than the sandbox's working directory, which Leased.Workdir names. |
id | body | string | — | ID is the sandbox to run in, from an earlier lease. |
session | body | string | — | 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… |
stdin | body | string | — | Stdin is fed to the program on standard input. |
timeoutSec | body | integer | — | TimeoutSec bounds this ONE command, so a wedged program holds the caller for its own timeout rather than for the whole lease. |
Response
| Status | Body | Meaning |
|---|---|---|
200 | Ran | ok |
200 body — 3 fields.
| Field | In | Type | Always | Description |
|---|---|---|---|---|
exitCode | body | integer | — | 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. |
stderr | body | string | — | Stderr is standard error, kept apart from Stdout so a caller reading a program's OUTPUT is not reading its diagnostics as data. Same 1 MiB cap, same redaction. |
stdout | body | string | — | 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… |
Failure carries the platform error shape — see Errors.
Examples
hanzo sandboxes runimport { 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 := cloud.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := cloud.NewAPIClient(cfg)
resp, _, err := client.SandboxAPI.RunInSandbox(context.Background()).Execute()
if err != nil {
return err
}use hanzo_cloud::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.setRequestInterceptor(b -> b.header("Authorization", "Bearer " + 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 sandboxes, 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": "sandboxes",
"arguments": {
"op": "run_in_sandbox",
"input": {
"argv": [
"<argv>"
],
"blind": [
"<blind>"
]
}
}
}
}'How is this guide?