# Run a command in a sandbox and wait for its result

Launch stage: Beta

`POST /api/2.0/sandbox-exec/{name=sandboxes/*}/exec-sync`

Runs a command in the sandbox and blocks until it exits, returning the
 captured stdout, stderr and exit code in a single response.

API scopes: sandbox

## Path parameters

- `name` (string, required)
  Resource name of the sandbox to run the command in, in the form
   `sandboxes/{sandbox_id}`. Bound from the URL path.

## Request body

- `cmd` (string, required)
  Executable or command to run (e.g. `/bin/echo`, `python3`).
- `args` (array of string, optional)
  Arguments passed to `cmd`.
- `envs` (object, optional)
  Extra environment variables for the command's process, merged over the
   sandbox's default environment.
- `execution_timeout` (string, optional)
  Maximum time to wait for the command to finish. When it elapses the
   command is terminated and the response carries status `TIMED_OUT`. The
   server applies a default when unset and clamps to an upper bound; negative
   or otherwise invalid durations are rejected with `INVALID_ARGUMENT`.

## Returns

- `exit_code` (int32, optional, Output only)
  Process exit code. Unset when the process was terminated by a signal
   (e.g. on `TIMED_OUT`) or never started (`FAILED`) rather than exiting
   normally.
- `status` (string, optional, Output only)
  Terminal status of the command execution. Always set on a successful
   response; never `EXECUTE_COMMAND_STATUS_UNSPECIFIED`.
  Possible values:
  - `EXECUTE_COMMAND_STATUS_UNSPECIFIED`
  - `EXECUTE_COMMAND_STATUS_COMPLETED`
  - `EXECUTE_COMMAND_STATUS_TIMED_OUT`
  - `EXECUTE_COMMAND_STATUS_FAILED`
- `stdout` (string, optional, Output only)
  Captured standard output as UTF-8 text. Invalid UTF-8 bytes are replaced
   with the Unicode replacement character (U+FFFD).
- `stderr` (string, optional, Output only)
  Captured standard error, with the same UTF-8 semantics as `stdout`.
- `command_id` (string, optional, Output only)
  Daemon-generated identifier for this command execution, for correlation
   (for example in `ListCommands`).
- `truncated` (boolean, optional, Output only)
  True when `stdout` / `stderr` were truncated because the captured output
   exceeded the server's per-response size cap. The dropped output is not
   included in this response and is not recoverable through this unary API.

## Response

```json
{
  "exit_code": 0,
  "status": "EXECUTE_COMMAND_STATUS_COMPLETED",
  "stdout": "string",
  "stderr": "string",
  "command_id": "string",
  "truncated": true
}
```

