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

# Execute a command with a known ID, optimistically waiting for completion

> Execute a command with a known command ID on a devbox, optimistically waiting for it to complete within the specified timeout. If it completes in time, return the result. If not, return a status indicating the command is still running. Note: attach_stdin parameter is not supported; use execute_async for stdin support.



## OpenAPI

````yaml /openapi-specs/stainless-processed-openapi.json post /v1/devboxes/{id}/execute
openapi: 3.1.0
info:
  title: RunLoop API
  version: '0.1'
  description: >-
    The RunLoop API spec that allows you to host lambda functions and Devboxes
    to enable scaled long running ai workflows.
  contact:
    name: Runloop AI Support
    url: https://runloop.ai
    email: support@runloop.ai
servers:
  - url: https://api.runloop.ai
    description: Runloop API
    variables: {}
security:
  - bearerAuth: []
tags:
  - name: Benchmark
  - name: Blueprint
  - name: Blueprint-Lifecycle
  - name: Blueprint-ObservabilityTools
  - name: Devbox
  - name: Devbox-FileTools
  - name: Devbox-Lifecycle
  - name: Devbox-NetworkTools
  - name: Devbox-ObservabilityTools
  - name: Devbox-PersistenceTools
  - name: Devbox-ShellTools
  - name: Scenario
  - name: ScenarioScorer
  - name: accounts
  - name: agents
  - name: apikeys
  - name: axons
  - name: executions
  - name: gateway-configs
  - name: mcp-configs
  - name: network-policies
  - name: objects
  - name: restricted_keys
  - name: secrets
  - name: streaming
paths:
  /v1/devboxes/{id}/execute:
    post:
      tags:
        - Devbox
        - Devbox-ShellTools
      summary: Execute a command with a known ID, optimistically waiting for completion
      description: >-
        Execute a command with a known command ID on a devbox, optimistically
        waiting for it to complete within the specified timeout. If it completes
        in time, return the result. If not, return a status indicating the
        command is still running. Note: attach_stdin parameter is not supported;
        use execute_async for stdin support.
      operationId: executeCommand
      parameters:
        - name: id
          in: path
          description: The Devbox ID.
          required: true
          schema:
            type: string
        - name: last_n
          in: query
          description: >-
            Last n lines of standard error / standard out to return (default:
            100)
          allowEmptyValue: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DevboxStartExecutionParameters'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DevboxAsyncExecutionDetailView'
        '404':
          description: Devbox not found.
        '408':
          description: Command timed out.
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Runloop from '@runloop/api-client';


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


            const devboxAsyncExecutionDetailView = await
            client.devboxes.execute('id', {
              command: 'command',
              command_id: 'command_id',
            });


            console.log(devboxAsyncExecutionDetailView.devbox_id);
        - lang: Python
          source: |-
            import os
            from runloop_api_client import Runloop

            client = Runloop(
                bearer_token=os.environ.get("RUNLOOP_API_KEY"),  # This is the default and can be omitted
            )
            devbox_async_execution_detail_view = client.devboxes.execute(
                id="id",
                command="command",
                command_id="command_id",
            )
            print(devbox_async_execution_detail_view.devbox_id)
components:
  schemas:
    DevboxStartExecutionParameters:
      type: object
      properties:
        command_id:
          type: string
          description: The command ID in UUIDv7 string format for idempotency and tracking
        command:
          type: string
          description: >-
            The command to execute via the Devbox shell. By default, commands
            are run from the user home directory unless shell_name is specified.
            If shell_name is specified the command is run from the directory
            based on the recent state of the persistent shell.
        shell_name:
          description: >-
            The name of the persistent shell to create or use if already
            created. When using a persistent shell, the command will run from
            the directory at the end of the previous command and environment
            variables will be preserved.
          type:
            - string
            - 'null'
        optimistic_timeout:
          format: int32
          description: >-
            Timeout in seconds to wait for command completion, up to 25 seconds.
            Defaults to 25 seconds. Operation is not killed.
          type:
            - integer
            - 'null'
      required:
        - command_id
        - command
    DevboxAsyncExecutionDetailView:
      type: object
      properties:
        devbox_id:
          type: string
          description: Devbox id where command was executed.
        execution_id:
          type: string
          description: Ephemeral id of the execution in progress.
        status:
          $ref: '#/components/schemas/DevboxExecutionStatus'
          description: Current status of the execution.
        shell_name:
          description: Shell name.
          type:
            - string
            - 'null'
        stdout:
          description: >-
            Standard out generated by command. This field will remain unset
            until the execution has completed.
          type:
            - string
            - 'null'
        stderr:
          description: >-
            Standard error generated by command. This field will remain unset
            until the execution has completed.
          type:
            - string
            - 'null'
        exit_status:
          format: int32
          description: >-
            Exit code of command execution. This field will remain unset until
            the execution has completed.
          type:
            - integer
            - 'null'
        stdout_truncated:
          description: Indicates whether the stdout was truncated due to size limits.
          type:
            - boolean
            - 'null'
        stderr_truncated:
          description: Indicates whether the stderr was truncated due to size limits.
          type:
            - boolean
            - 'null'
      required:
        - devbox_id
        - execution_id
        - status
    DevboxExecutionStatus:
      type: string
      enum:
        - queued
        - running
        - completed
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````