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

# Run a command in a sandbox

> **Preview.** Available to teams with the `sandboxes_api` feature flag. The shape of this
endpoint may change before general availability.

Run a command in a sandbox and wait for its output.




## OpenAPI

````yaml https://spec.speakeasy.com/latitude/latitude/latitude-sh-api-with-code-samples post /sandboxes/{sandbox_id}/exec
openapi: 3.0.1
info:
  title: Latitude.sh API
  version: '2023-06-01'
  description: >-
    The Latitude.sh API is a RESTful API to manage your Latitude.sh account. It
    allows you to perform the same actions as the Latitude.sh dashboard.
servers:
  - url: https://api.latitude.sh
    variables:
      latitude_api_key:
        default: <insert your api key here>
  - url: http://api.latitude.sh
    variables:
      latitude_api_key:
        default: <insert your api key here>
security: []
tags:
  - name: API keys
  - name: Baselines (Preview)
    description: >-
      Preview. Available to teams with the `baselines_api` feature flag. The
      shape of these endpoints may change before general availability.
  - name: Billing
  - name: Clusters
    description: >-
      Projects that have a GPU cluster only. Every operation answers 404
      PROJECT_NOT_A_CLUSTER for a project without one.
  - name: Elastic Ips
  - name: Events
  - name: Firewalls
  - name: Inference
  - name: IP Addresses
  - name: Managed Databases
    description: Managed database instances (PostgreSQL, ClickHouse)
  - name: Kubernetes Clusters
  - name: LKS
  - name: Marketplace apps
  - name: Operating Systems
  - name: Plans
  - name: Sandboxes (Preview)
    description: >-
      Preview. Available to teams with the `sandboxes_api` feature flag. The
      shape of these endpoints may change before general availability.
  - name: Public Networks
  - name: Private Networks
  - name: Projects
  - name: Regions
  - name: Roles
  - name: SSH Keys
  - name: Servers
  - name: Block Storage
  - name: Filesystem Storage
  - name: Object Storage
  - name: Tags
  - name: Teams
  - name: Team members
  - name: Traffic
  - name: User data
  - name: User profile
  - name: Virtual machines
  - name: Virtual machine backups
  - name: Virtual machine restores
paths:
  /sandboxes/{sandbox_id}/exec:
    post:
      tags:
        - Sandboxes (Preview)
      summary: Run a command in a sandbox
      description: >
        **Preview.** Available to teams with the `sandboxes_api` feature flag.
        The shape of this

        endpoint may change before general availability.


        Run a command in a sandbox and wait for its output.
      operationId: exec-sandbox
      parameters:
        - name: sandbox_id
          in: path
          required: true
          description: Sandbox name
          examples:
            Success:
              value: sbx-demo
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    attributes:
                      type: object
                      properties:
                        command:
                          type: array
                          items:
                            type: string
                          description: Command and arguments to run
                        environment:
                          type: object
                          additionalProperties:
                            type: string
                          description: Environment variables set for the command
                        workdir:
                          type: string
                          description: Working directory for the command
                        timeout_seconds:
                          type: integer
                          minimum: 1
                          maximum: 60
                          description: >-
                            Maximum run time of the command. Defaults to 30
                            seconds
                      required:
                        - command
            examples:
              Success:
                summary: Success
                value:
                  data:
                    attributes:
                      command:
                        - python
                        - '-V'
          application/vnd.api+json:
            schema:
              type: object
              properties:
                data:
                  type: object
                  properties:
                    attributes:
                      type: object
                      properties:
                        command:
                          type: array
                          items:
                            type: string
                          description: Command and arguments to run
                        environment:
                          type: object
                          additionalProperties:
                            type: string
                          description: Environment variables set for the command
                        workdir:
                          type: string
                          description: Working directory for the command
                        timeout_seconds:
                          type: integer
                          minimum: 1
                          maximum: 60
                          description: >-
                            Maximum run time of the command. Defaults to 30
                            seconds
                      required:
                        - command
            examples:
              Success:
                summary: Success
                value:
                  data:
                    attributes:
                      command:
                        - python
                        - '-V'
        required: true
      responses:
        '200':
          description: Success
          content:
            application/vnd.api+json:
              examples:
                Success:
                  value:
                    data:
                      id: sbx-demo
                      type: sandbox_execs
                      attributes:
                        stdout: |
                          Python 3.12.0
                        stderr: ''
                        exit_code: 0
                        truncated: false
              schema:
                $ref: '#/components/schemas/sandbox_exec'
      security:
        - Bearer: []
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from latitudesh_python_sdk import Latitudesh
            import os


            with Latitudesh(
                bearer=os.getenv("LATITUDESH_BEARER", ""),
            ) as latitudesh:

                res = latitudesh.sandboxes_preview.exec_sandbox(sandbox_id="sbx-demo", data={
                    "attributes": {
                        "command": [
                            "python",
                            "-V",
                        ],
                    },
                })

                # Handle response
                print(res)
        - lang: go
          label: Go (SDK)
          source: "package main\n\nimport(\n\t\"context\"\n\t\"os\"\n\tlatitudeshgosdk \"github.com/latitudesh/latitudesh-go-sdk\"\n\t\"github.com/latitudesh/latitudesh-go-sdk/models/operations\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := latitudeshgosdk.New(\n        latitudeshgosdk.WithSecurity(os.Getenv(\"LATITUDESH_BEARER\")),\n    )\n\n    res, err := s.SandboxesPreview.ExecSandbox(ctx, \"sbx-demo\", operations.ExecSandboxSandboxesPreviewRequestBody{\n        Data: &operations.ExecSandboxSandboxesPreviewData{\n            Attributes: &operations.ExecSandboxSandboxesPreviewAttributes{\n                Command: []string{\n                    \"python\",\n                    \"-V\",\n                },\n            },\n        },\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.SandboxExec != nil {\n        // handle response\n    }\n}"
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Latitudesh } from "latitudesh-typescript-sdk";

            const latitudesh = new Latitudesh({
              bearer: process.env["LATITUDESH_BEARER"] ?? "",
            });

            async function run() {
              const result = await latitudesh.sandboxesPreview.execSandbox({
                sandboxId: "sbx-demo",
                requestBody: {
                  data: {
                    attributes: {
                      command: [
                        "python",
                        "-V",
                      ],
                    },
                  },
                },
              });

              console.log(result);
            }

            run();
components:
  schemas:
    sandbox_exec:
      type: object
      properties:
        data:
          type: object
          properties:
            id:
              type: string
              description: Sandbox name
            type:
              type: string
              enum:
                - sandbox_execs
            attributes:
              type: object
              properties:
                stdout:
                  type: string
                  description: Standard output, capped at 1 MiB
                stderr:
                  type: string
                  description: Standard error, capped at 1 MiB
                exit_code:
                  type: integer
                  nullable: true
                  description: >-
                    Exit code of the command. Null when the command did not
                    report one
                truncated:
                  type: boolean
                  description: Whether stdout or stderr exceeded the cap and was truncated
  securitySchemes:
    Bearer:
      type: apiKey
      name: Authorization
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.