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

# Execute sandbox command



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/cerca/openapi.documented.yml post /agents/{agentId}/sandbox/exec
openapi: 3.1.0
info:
  description: API-key accessible routes for Cerca agents.
  title: Cerca API
  version: 0.0.0
servers:
  - url: https://api.cerca.dev
security:
  - bearerAuth: []
paths:
  /agents/{agentId}/sandbox/exec:
    post:
      tags:
        - Sandbox
      summary: Execute sandbox command
      parameters:
        - schema:
            type: string
            minLength: 1
            example: agent_abc123
          required: true
          in: path
          name: agentId
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SandboxExecRequest'
      responses:
        '200':
          description: Sandbox command result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxExecResult'
        '400':
          description: Invalid runtime request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: >-
            Access denied or non-transient quota exceeded. Limit errors include
            a stable code field.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Runtime resource not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: >-
            Transient capacity limit exceeded. Limit errors include a stable
            code field.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Required runtime dependency unavailable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        default:
          description: Runtime error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Cerca from '@cerca-dev/sdk';


            const client = new Cerca({
              apiKey: process.env['CERCA_API_KEY'], // This is the default and can be omitted
            });


            const execResult = await client.sandbox.exec('agent_abc123', {
            command: 'command' });


            console.log(execResult.exitCode);
        - lang: Python
          source: |-
            import os
            from cerca import Cerca

            client = Cerca(
                api_key=os.environ.get("CERCA_API_KEY"),  # This is the default and can be omitted
            )
            exec_result = client.sandbox.exec(
                agent_id="agent_abc123",
                command="command",
            )
            print(exec_result.exit_code)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/matrices/cerca-go\"\n\t\"github.com/matrices/cerca-go/option\"\n)\n\nfunc main() {\n\tclient := cercago.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\texecResult, err := client.Sandbox.Exec(\n\t\tcontext.TODO(),\n\t\t\"agent_abc123\",\n\t\tcercago.SandboxExecParams{\n\t\t\tCommand: cercago.F(\"command\"),\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", execResult.ExitCode)\n}\n"
        - lang: Ruby
          source: >-
            require "cerca"


            cerca = Cerca::Client.new(api_key: "My API Key")


            exec_result = cerca.sandbox.exec_("agent_abc123", command:
            "command")


            puts(exec_result)
        - lang: CLI
          source: |-
            cerca sandbox exec \
              --api-key 'My API Key' \
              --agent-id agent_abc123 \
              --command command
components:
  schemas:
    SandboxExecRequest:
      type: object
      properties:
        command:
          type: string
        maxBuffer:
          type: number
        timeout:
          type: number
          description: Timeout in seconds. Runtime converts this to milliseconds.
          example: 30
          x-stainless-param: execution_timeout
        workdir:
          type:
            - string
            - 'null'
          description: Optional sandbox working directory.
          example: /home/user
      required:
        - command
      additionalProperties:
        x-stainless-any: true
    SandboxExecResult:
      type: object
      properties:
        exitCode:
          type:
            - number
            - 'null'
        handle:
          type: string
        state:
          type: string
          enum:
            - running
            - exited
        stderr:
          type: string
        stderrOffset:
          type: number
        stdout:
          type: string
        stdoutOffset:
          type: number
      required:
        - exitCode
        - handle
        - state
        - stderr
        - stderrOffset
        - stdout
        - stdoutOffset
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        code:
          type: string
          description: Stable machine-readable error code when the API can provide one.
          example: MONTHLY_TOKEN_BUDGET_EXCEEDED
      required:
        - error
  securitySchemes:
    bearerAuth:
      bearerFormat: Cerca API key
      scheme: bearer
      type: http

````