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

# Workspace: Bash

> Execute a shell command inside the agent's workspace

Run a shell command inside the per-agent workspace.

## Path Parameters

<ParamField path="agent_id" type="string" required>
  Agent ID (UUID)
</ParamField>

## Request Body

<ParamField body="command" type="string" required>
  Shell command to execute inside the workspace.
</ParamField>

<ParamField body="timeout" type="integer" default={300}>
  Maximum execution time in seconds before the command is terminated.
</ParamField>

<ParamField body="working_dir" type="string">
  Optional working directory for the command. Defaults to the workspace root when empty.
</ParamField>

## Response

<ResponseField name="status" type="string">
  Result status of the operation (e.g., `ok`).
</ResponseField>

<ResponseField name="stdout" type="string">
  Standard output captured from the command.
</ResponseField>

<ResponseField name="stderr" type="string">
  Standard error captured from the command.
</ResponseField>

<ResponseField name="exit_code" type="integer">
  Process exit code.
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/workspace/bash" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "command": "ls -la",
    "timeout": 300,
    "working_dir": ""
  }'
```

## Notes

* The workspace is per-agent and persists between calls, so files created here remain available to subsequent workspace operations for the same agent.
* Commands are run as an unprivileged user. Avoid commands that require elevated permissions.

## See Also

* [Workspace: File Write](/api-reference/v1/agents/workspace/file-write)
* [Workspace: File Read](/api-reference/v1/agents/workspace/file-read)
* [Workspace: Grep](/api-reference/v1/agents/workspace/grep)


## OpenAPI

````yaml POST /v1/agents/{agent_id}/workspace/bash
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/agents/{agent_id}/workspace/bash:
    post:
      tags:
        - API v1
        - Agents
        - Agents Workspace
      summary: 'Workspace: Bash'
      description: >-
        Execute a shell command inside the agent's workspace. Supports
        installing packages, running scripts, and general shell operations.
      operationId: Workspace__Bash_v1_agents__agent_id__workspace_bash_post
      parameters:
        - name: agent_id
          in: path
          required: true
          schema:
            type: string
            title: Agent Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BashRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BashResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    BashRequest:
      properties:
        command:
          type: string
          title: Command
          description: >-
            Shell command to execute inside the workspace. Supports installing
            packages (apt-get, pip, npm), running scripts, and general shell
            operations.
          examples:
            - >-
              pip install pandas && python -c 'import pandas;
              print(pandas.__version__)'
        timeout:
          type: integer
          maximum: 1800
          minimum: 1
          title: Timeout
          description: >-
            Maximum execution time in seconds. The command is killed if it
            exceeds this limit.
          default: 300
          examples:
            - 60
        working_dir:
          type: string
          title: Working Dir
          description: >-
            Working directory for the command, relative to workspace root.
            Defaults to the workspace root.
          default: ''
          examples:
            - my_project
      type: object
      required:
        - command
      title: BashRequest
    BashResponse:
      properties:
        stdout:
          type: string
          title: Stdout
          description: Standard output captured from the command
          default: ''
          examples:
            - |
              2.2.0
        stderr:
          type: string
          title: Stderr
          description: Standard error captured from the command
          default: ''
          examples:
            - ''
        exit_code:
          type: integer
          title: Exit Code
          description: Process exit code. 0 indicates success, non-zero indicates failure.
          default: 0
          examples:
            - 0
        duration:
          type: number
          title: Duration
          description: Execution duration in seconds
          default: 0
          examples:
            - 3.21
      type: object
      title: BashResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````