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

# Create PTY Session

> Create a PTY-backed interactive terminal session through the sandbox proxy.

Create a PTY session for interactive terminal access.

## Endpoint

```http theme={null}
POST /api/v1/pty
```

Use this endpoint on the sandbox proxy host:

```text theme={null}
https://<sandbox-id-or-name>.sandbox.tensorlake.ai/api/v1/pty
```

## Example Request

```bash theme={null}
curl -X POST https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/pty \
  -H "Authorization: Bearer $TENSORLAKE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "/bin/bash",
    "args": ["-l"],
    "env": {"TERM": "xterm-256color"},
    "working_dir": "/workspace",
    "rows": 24,
    "cols": 80
  }'
```

## Request Body

```json theme={null}
{
  "command": "/bin/bash",
  "args": ["-l"],
  "env": {"TERM": "xterm-256color"},
  "working_dir": "/workspace",
  "rows": 24,
  "cols": 80
}
```

* `command` is required.
* `args` is optional.
* `env` is optional.
* `working_dir` is optional.
* `rows` and `cols` are optional and default to `24` and `80`.
* Tensorlake clamps `rows` to `1..500` and `cols` to `1..1000`.

## Response

Tensorlake returns `201 Created`:

```json theme={null}
{
  "session_id": "LYtJOrxE9Kz3bphPUDzuX",
  "token": "<pty-session-token>"
}
```

Use `session_id` with the other PTY endpoints. Use `token` when connecting to the PTY WebSocket.

If the sandbox already has 64 PTY sessions, Tensorlake returns `429 Too Many Requests` with code `TOO_MANY_SESSIONS`.


## OpenAPI

````yaml post /api/v1/pty
openapi: 3.1.0
info:
  title: Tensorlake API
  description: >-
    Tensorlake Cloud APIs for Sandboxes, Document Ingestion, and Serverless
    Workflows
  license:
    name: ''
  version: 0.1.0
servers:
  - url: https://api.tensorlake.ai/
security:
  - bearerAuth: []
tags:
  - name: Tensorlake Cloud API
    description: >-
      Tensorlake Cloud APIs for Sandboxes, Document Ingestion, and Serverless
      Workflows
paths:
  /api/v1/pty:
    servers:
      - url: https://{identifier}.sandbox.tensorlake.ai
        description: >-
          Example sandbox proxy host for a specific running sandbox. For
          programmatic access, use the sandbox's `ingress_endpoint`.
        variables:
          identifier:
            default: example-sandbox
            description: The sandbox ID or sandbox name.
    post:
      tags:
        - sandbox-pty
      summary: Create a PTY session
      description: >-
        Create a PTY-backed interactive terminal session through the sandbox
        proxy.
      operationId: sandbox_pty_create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SandboxPtyCreateRequest'
      responses:
        '201':
          description: PTY session created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxPtyCreateResponse'
        '429':
          description: Too many concurrent PTY sessions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxProxyError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxProxyError'
components:
  schemas:
    SandboxPtyCreateRequest:
      type: object
      required:
        - command
      properties:
        command:
          type: string
        args:
          type: array
          items:
            type: string
        env:
          type: object
          additionalProperties:
            type: string
        working_dir:
          type: string
        rows:
          type: integer
          format: int32
        cols:
          type: integer
          format: int32
    SandboxPtyCreateResponse:
      type: object
      required:
        - session_id
        - token
      properties:
        session_id:
          type: string
        token:
          type: string
    SandboxProxyError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        code:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````