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

# Execute Code

> Execute Python code in a running sandbox

<Note>
  **v2 available:** See [POST /v2/sandcastles/{id}/execute](/api-reference/v2/sandbox/execute-code) for the REST-native version of this endpoint.
</Note>


## OpenAPI

````yaml POST /v1/sandbox/execute
openapi: 3.1.0
info:
  title: textql.rpc.platform
  version: '1.0'
servers: []
security: []
tags:
  - name: textql.rpc.platform.SandboxService
    description: >-
      Platform Sandbox Service - External API for creating and managing Python
      sandbox environments
paths:
  /v1/sandbox/execute:
    post:
      tags:
        - textql.rpc.platform.SandboxService
      summary: ExecuteCode
      description: Execute Python code in a running sandbox
      operationId: textql.rpc.platform.SandboxService.ExecuteCode
      parameters:
        - name: Connect-Protocol-Version
          in: header
          required: true
          schema:
            $ref: '#/components/schemas/connect-protocol-version'
        - name: Connect-Timeout-Ms
          in: header
          schema:
            $ref: '#/components/schemas/connect-timeout-header'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/textql.rpc.platform.ExecuteCodeRequest'
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/textql.rpc.platform.ExecuteCodeResponse'
        default:
          description: Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/connect.error'
components:
  schemas:
    connect-protocol-version:
      type: number
      title: Connect-Protocol-Version
      enum:
        - 1
      description: Define the version of the Connect protocol
      const: 1
    connect-timeout-header:
      type: number
      title: Connect-Timeout-Ms
      description: Define the timeout, in ms
    textql.rpc.platform.ExecuteCodeRequest:
      type: object
      properties:
        sandboxId:
          type: string
          title: sandbox_id
        code:
          type: string
          title: code
          description: Python code to execute
      required:
        - sandboxId
        - code
      title: ExecuteCodeRequest
      additionalProperties: false
    textql.rpc.platform.ExecuteCodeResponse:
      type: object
      properties:
        output:
          type: array
          items:
            type: string
          title: output
          description: Lines of stdout output
        error:
          type: string
          title: error
          description: Error message if execution failed
          nullable: true
        files:
          type: array
          items:
            $ref: '#/components/schemas/textql.rpc.platform.FileOutput'
          title: files
          description: Files generated during execution
        dataframes:
          type: array
          items:
            $ref: '#/components/schemas/textql.rpc.platform.DataFrameOutput'
          title: dataframes
          description: DataFrames created or modified during execution
        executionTimeMs:
          type: integer
          title: execution_time_ms
          format: int64
      title: ExecuteCodeResponse
      additionalProperties: false
    connect.error:
      type: object
      properties:
        code:
          type: string
          examples:
            - not_found
          enum:
            - canceled
            - unknown
            - invalid_argument
            - deadline_exceeded
            - not_found
            - already_exists
            - permission_denied
            - resource_exhausted
            - failed_precondition
            - aborted
            - out_of_range
            - unimplemented
            - internal
            - unavailable
            - data_loss
            - unauthenticated
          description: >-
            The status code, which should be an enum value of
            [google.rpc.Code][google.rpc.Code].
        message:
          type: string
          description: >-
            A developer-facing error message, which should be in English. Any
            user-facing error message should be localized and sent in the
            [google.rpc.Status.details][google.rpc.Status.details] field, or
            localized by the client.
        details:
          type: array
          items:
            $ref: '#/components/schemas/connect.error_details.Any'
          description: >-
            A list of messages that carry the error details. There is no limit
            on the number of messages.
      title: Connect Error
      additionalProperties: true
      description: >-
        Error type returned by Connect:
        https://connectrpc.com/docs/go/errors/#http-representation
    textql.rpc.platform.FileOutput:
      type: object
      properties:
        name:
          type: string
          title: name
        url:
          type: string
          title: url
        mimeType:
          type: string
          title: mime_type
      title: FileOutput
      additionalProperties: false
    textql.rpc.platform.DataFrameOutput:
      type: object
      properties:
        name:
          type: string
          title: name
        numRows:
          type: integer
          title: num_rows
          format: int32
        numCols:
          type: integer
          title: num_cols
          format: int32
      title: DataFrameOutput
      additionalProperties: false
    connect.error_details.Any:
      type: object
      properties:
        type:
          type: string
          description: >-
            A URL that acts as a globally unique identifier for the type of the
            serialized message. For example:
            `type.googleapis.com/google.rpc.ErrorInfo`. This is used to
            determine the schema of the data in the `value` field and is the
            discriminator for the `debug` field.
        value:
          type: string
          format: binary
          description: >-
            The Protobuf message, serialized as bytes and base64-encoded. The
            specific message type is identified by the `type` field.
        debug:
          oneOf:
            - type: object
              title: Any
              additionalProperties: true
              description: Detailed error information.
          discriminator:
            propertyName: type
          title: Debug
          description: >-
            Deserialized error detail payload. The 'type' field indicates the
            schema. This field is for easier debugging and should not be relied
            upon for application logic.
      additionalProperties: true
      description: >-
        Contains an arbitrary serialized message along with a @type that
        describes the type of the serialized message, with an additional debug
        field for ConnectRPC error details.

````