> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hiloop.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Post v1sandboxes exec

> Execute one command in the sandbox's workload container and return buffered output. An
 optional Idempotency-Key provides replay safety: a repeated request carrying the same key
 replays the recorded outcome instead of executing the command a second time, which is what
 makes a retry safe after a response is lost in transit. Timeout and indeterminate are process
 outcomes, not errors; truncation is an orthogonal output property and never replaces a real
 process exit code.



## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/sandboxes/{id}/exec
openapi: 3.0.3
info:
  title: ''
  version: 0.0.1
servers: []
security:
  - bearerAuth: []
tags:
  - name: AnnotationSchemaService
    description: |-
      Org-scoped annotation-schema registry CRUD.

       Every RPC scopes to the caller's organization, derived from their credential; a request with no org
       scope is UNAUTHENTICATED. Registration runs a backward-compatibility check against the latest live
       version and REJECTS an incompatible change (FAILED_PRECONDITION). These endpoints are what the
       generated OpenAPI, SDKs, and CLI consume.
  - name: AnnotationService
    description: >-
      Typed annotation surface over the telemetry store: the annotate writes
      plus the one served
       annotation read every consumer shares. Organization scoping is enforced from request identity,
       not from the request body. Ingest of ordinary telemetry lives in TelemetryIngestService
       (telemetry.proto); the general event read surface lives in TelemetryQueryService (query.proto).
  - name: FeedbackService
    description: |-
      Product-feedback intake.

       The organization is derived from the caller's credential, never from the request body; a request with
       no org scope is UNAUTHENTICATED. Any org-scoped caller — a user session, a service key, or
       a sandbox-scoped credential — may submit feedback.
  - name: IdentityService
    description: Identity/health surface for the control-plane API.
  - name: MetaService
    description: Unauthenticated discovery surface for client-visible sibling service URLs.
  - name: ProjectService
    description: |-
      Org-scoped project CRUD.

       Every RPC scopes to the caller's organization, derived from their credential; a request with no org
       scope is UNAUTHENTICATED. These endpoints are what the generated OpenAPI, SDKs, and CLI consume.
  - name: RunService
    description: |-
      Org-scoped access to runs and their lineage.

       Every RPC scopes to the caller's organization, derived from their credential; a request with no org
       scope is UNAUTHENTICATED. These endpoints are what the generated OpenAPI, SDKs, and CLI consume.
  - name: SandboxService
    description: |-
      Org-scoped sandbox runtime API.

       The organization comes from the caller's credential. Org-scoped human and service credentials may
       use every route in their organization. A sandbox-scoped, lineage-confined credential may read its own
       sandbox and snapshot lineage and may exec or snapshot only that sandbox; it may not create,
       update, or delete sandboxes, delete snapshots, or exec into a sibling sandbox.

       State and verb rules are closed. Get and list serve every visible state. Failed and terminated
       rows remain available through GetSandbox for a server retention window, then return 404
       not_found. Update to stopped is accepted from ready or running and is idempotent from stopped;
       update to running wakes stopped and is idempotent from running. A wake racing an in-flight stop
       waits for stop to win before wake proceeds. Workspace growth is accepted only for a stable
       durable sandbox and is idempotent for the same target; lifecycle mutation and growth never
       overlap. An undurable snapshot, including one whose request timed out, fences growth and cannot
       be deleted because its seal may still publish a late receipt; repeat the same snapshot request
       (and idempotency key, if supplied) to resolve its outcome. Delete is accepted once for a
       nonterminal sandbox; a second delete returns 404
       not_found. Exec requires running and never wakes implicitly; any
       other non-quarantined state returns 409 sandbox_not_running. Snapshot is accepted from ready,
       running, or stopped; other non-quarantined states return 409 sandbox_not_ready. Every mutating
       verb on a quarantined sandbox returns 409 quarantined. A concurrent snapshot returns 409
       snapshot_in_progress.

       Every error uses the flat {code, message, request_id} envelope. Stable route codes are
       invalid_argument (400), not_found (404), idempotency_conflict, name_conflict, sandbox_not_running,
       sandbox_not_ready, quarantined, snapshot_in_progress, snapshot_in_use, and
       snapshot_not_restorable, workspace_shrink_unsupported, and operation_conflict (409),
       unsupported_capability (422), quota_exceeded (429; details.quota.metric names the limit —
       sandboxes.running, sandboxes.total, or sandboxes.workspace_capacity_gib), and unavailable
       (503). Exec transport failures use spawn_failed or sandbox_stopped and discard any partial
       output; both mean the command did not run. A command that WAS dispatched but whose outcome
       could not be read is never an error: it returns 200 with the indeterminate outcome, alongside
       whatever partial output was collected, as a timeout does.

       Capability-receipt observation has no route in this version and is explicitly NOTIMPL; it is not
       inferred from Sandbox fields.
  - name: SecretService
    description: |-
      Org-scoped sandbox-secret management.

       Every RPC scopes to the caller's organization, derived from their credential; a request with no org
       scope is UNAUTHENTICATED. Create/revoke/rotate require an owner/admin in the organization; these
       management RPCs never return the secret value.
  - name: TelemetryViewService
    description: >-
      Typed data-view surface over the telemetry store. Organization scoping is
      enforced from request
       identity, not from the request body. A data view's spec is the engine's `DataViewSpec` — a raw
       `Sql` `SELECT` — re-validated and compiled fresh on every run under the forced-organization
       safe-SQL gateway. The untrusted raw-SQL escape hatch is a separate `POST /v1/telemetry/sql`
       endpoint, intentionally kept off this typed wire.
  - name: UsageService
    description: Org-scoped product quota reads.
  - name: VolumeService
    description: |-
      Org-scoped volume CRUD.

       Every RPC scopes to the caller's organization, derived from their credential; a request with no org
       scope is UNAUTHENTICATED. These endpoints are what the generated OpenAPI, SDKs, and CLI consume.
  - name: WorkloadService
    description: |-
      Org-scoped workload registry management.

       The organization is derived from the caller's credential; a request with no org scope is
       UNAUTHENTICATED. Registering and reading workloads is open to any org member. Setting a launch
       ACL and deleting a workload are operator actions and require an owner or admin in the organization. A
       sandbox-scoped credential may not register, delete, or manage workloads.
paths:
  /v1/sandboxes/{id}/exec:
    post:
      tags:
        - SandboxService
      description: >-
        Execute one command in the sandbox's workload container and return
        buffered output. An
         optional Idempotency-Key provides replay safety: a repeated request carrying the same key
         replays the recorded outcome instead of executing the command a second time, which is what
         makes a retry safe after a response is lost in transit. Timeout and indeterminate are process
         outcomes, not errors; truncation is an orthogonal output property and never replaces a real
         process exit code.
      operationId: SandboxService_ExecSandbox
      parameters:
        - name: id
          in: path
          description: The running sandbox in which to execute the command.
          required: true
          schema:
            type: string
        - name: idempotency-key
          in: header
          required: false
          description: >-
            Optional idempotency key for this mutation. The server records the
            result from execution start. For at least 72 hours, reuse by the
            same organization and route replays the original status and body. A
            matching request still in flight or reuse for different input
            returns 409 idempotency_conflict. Keys are scoped by organization
            and route and contain 1-255 characters.
          schema:
            type: string
            minLength: 1
            maxLength: 255
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecSandboxBody'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecSandboxResponse'
        default:
          $ref: '#/components/responses/SandboxError'
components:
  schemas:
    ExecSandboxBody:
      type: object
      properties:
        cmd:
          type: array
          items:
            type: string
            maxLength: 4096
          description: >-
            Command and arguments. The first entry is a non-empty executable; at
            most 256 entries are
             accepted and each entry is at most 4096 characters.
          minItems: 1
          maxItems: 256
        timeout_seconds:
          type: integer
          description: >-
            Execution timeout in whole seconds, from 1 through 3600. Omit it to
            use the server default;
             sub-second budgets are outside this version.
          format: uint32
          minimum: 1
          maximum: 3600
        secret_environment:
          type: array
          items:
            $ref: '#/components/schemas/SandboxExecSecretEnvironment'
          description: >-
            Secret references released atomically into the child environment. No
            value crosses this
             public API. Omit for ordinary execution.
      required:
        - cmd
    ExecSandboxResponse:
      oneOf:
        - $ref: '#/components/schemas/ExecSandboxCompletedResponse'
        - $ref: '#/components/schemas/ExecSandboxTimedOutResponse'
        - $ref: '#/components/schemas/ExecSandboxIndeterminateResponse'
    SandboxExecSecretEnvironment:
      type: object
      properties:
        secret_name:
          type: string
          description: >-
            Name of an active sandbox-environment secret in the caller's
            organization, at most 128 bytes.
        variable_name:
          type: string
          description: >-
            POSIX environment variable name populated in the child process, at
            most 128 bytes.
      description: >-
        One write-only secret reference mapped to one environment variable for
        this execution. The
         secret value is resolved by the server and never appears in this request.
    ExecSandboxCompletedResponse:
      type: object
      properties:
        stdout:
          type: string
          description: >-
            Buffered standard output. It may contain partial output on a timeout
            or an indeterminate
             outcome.
        stderr:
          type: string
          description: >-
            Buffered standard error. It may contain partial output on a timeout
            or an indeterminate
             outcome.
        exit:
          type: integer
          description: The process exit code for a completed command, including zero.
          format: int32
        truncated:
          type: boolean
          description: >-
            Whether stdout or stderr was truncated at the server-configured
            combined output cap. The
             default cap is no more than 1 MiB. Truncation does not replace the real process outcome.
      required:
        - stdout
        - stderr
        - truncated
        - exit
      additionalProperties: false
      description: >-
        Buffered output and the real exit code from a completed command;
        truncated reports output loss independently.
    ExecSandboxTimedOutResponse:
      type: object
      properties:
        stdout:
          type: string
          description: >-
            Buffered standard output. It may contain partial output on a timeout
            or an indeterminate
             outcome.
        stderr:
          type: string
          description: >-
            Buffered standard error. It may contain partial output on a timeout
            or an indeterminate
             outcome.
        timeout:
          allOf:
            - $ref: '#/components/schemas/SandboxExecTimeout'
          description: >-
            Presence means the execution exceeded timeout_seconds before a
            process exit was observed.
        truncated:
          type: boolean
          description: >-
            Whether stdout or stderr was truncated at the server-configured
            combined output cap. The
             default cap is no more than 1 MiB. Truncation does not replace the real process outcome.
      required:
        - stdout
        - stderr
        - truncated
        - timeout
      additionalProperties: false
      description: >-
        Partial buffered output from a timed-out command, with no exit code;
        truncated reports output loss independently.
    ExecSandboxIndeterminateResponse:
      type: object
      properties:
        stdout:
          type: string
          description: >-
            Buffered standard output. It may contain partial output on a timeout
            or an indeterminate
             outcome.
        stderr:
          type: string
          description: >-
            Buffered standard error. It may contain partial output on a timeout
            or an indeterminate
             outcome.
        indeterminate:
          allOf:
            - $ref: '#/components/schemas/SandboxExecIndeterminate'
          description: >-
            Presence means the command was dispatched but its outcome could not
            be read. The command
             may have completed; this is never a statement that it did not run.
        truncated:
          type: boolean
          description: >-
            Whether stdout or stderr was truncated at the server-configured
            combined output cap. The
             default cap is no more than 1 MiB. Truncation does not replace the real process outcome.
      required:
        - stdout
        - stderr
        - truncated
        - indeterminate
      additionalProperties: false
      description: >-
        The command was dispatched but its outcome could not be read, so no exit
        code is reported; any output collected first is still returned. It may
        have completed: do not re-run a command that is unsafe to repeat without
        checking, or send an Idempotency-Key so a retry replays instead of
        re-executing.
    SandboxErrorBody:
      type: object
      additionalProperties: false
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
          description: Stable machine-readable error code in snake_case.
        message:
          type: string
          description: Human-readable description; clients must not parse it.
        request_id:
          type: string
          description: Correlation id for support and diagnostics.
    SandboxExecTimeout:
      type: object
      properties: {}
      description: >-
        Presence marker returned when an execution exceeded its requested
        timeout.
      additionalProperties: false
    SandboxExecIndeterminate:
      type: object
      properties: {}
      description: >-
        Presence marker returned when the command was dispatched but its
        execution channel was lost
         before an outcome could be read, so the service cannot say what the command did.

         This is not a failure to run. The command may have run to completion, and any output collected
         before the channel was lost is still returned. Treat it as "unknown", never as "did not run":
         re-issuing a command that is not safe to run twice requires an Idempotency-Key, which replays
         the recorded outcome instead of executing again.
      additionalProperties: false
  responses:
    SandboxError:
      description: An error using the successor flat API error envelope.
      headers:
        Retry-After:
          description: Seconds to wait before retrying when the error is retryable.
          schema:
            type: integer
            format: uint64
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SandboxErrorBody'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Hiloop API key sent as an HTTP Bearer token.

````