Docs
Sandboxes ›

Exec command

POST/v1/sandboxes/{id}/exec

Run a command and wait for it.

RequestTypeScript
  1. import { Agental } from "agental-sdk";
  2. const agental = new Agental();
  3. const sandbox = await agental.sandboxes.get("sbx_2a9a47e50daec64a");
  4. const result = await sandbox.exec(["npm", "test"]);
Answer200 OK · ExecResult
  1. {
  2. "exitCode": integer,
  3. "stdout": string,
  4. "stderr": string,
  5. "truncated": boolean,
  6. }

Command finished.

Path

idrequired
string
e.g. "sbx_0123456789abcdef"

Headers

Authorizationrequired
Bearer key
An API key that may make this call.

Body

commandrequired
array of string
Argv. The control plane does not invoke a shell. It runs as root, with the variables of the sandbox's template and its own in its environment, and AGENTAL_SANDBOX_ID, the sandbox's id, AGENTAL_API_URL, where this API answers, and AGENTAL_SANDBOX_TOKEN, the sandbox's own token for the run it is in, which reads and moves its stop and does nothing else. e.g. ["echo","hello"]
timeoutMs
integer
Defaults to 60000. On timeout the exit code is 124. Up to 600000 for /commands and /exec/stream, and up to 90000 for POST /v1/sandboxes/{id}/exec, which answers only when its command ends: a proxy in front of the API stops waiting after 100 seconds.

Returns

200 Command finished. A non-zero exit code is still HTTP 200.

ExecResult4 fields
exitCode
integer
stdout
string
stderr
string
truncated
boolean

Errors and other answers

400invalid_request timeoutMs is above 90000. This call answers only when its command ends, and a proxy in front of the API stops waiting after 100 seconds, so a longer command is started with POST /v1/sandboxes/{id}/commands, which answers at once. Nothing was run.
404 Not found.
409 Sandbox is not running.
503sandbox_moved the sandbox was moved to another server while this was being done, and it was cut off. Send it again.

Every error answers { "error": { "code", "message" } }; a key without the action a call needs answers 403 key_action_forbidden, naming it.