> ## 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.

# Run Process

> Start a non-interactive process, stream captured output over Server-Sent Events, and emit a final exit event. Stdin is closed for this endpoint.

Start a process, stream its captured output over Server-Sent Events, and receive a final exit event.

Use this endpoint when you want a single request for non-interactive command execution. If the process needs stdin, use [Start Process](/api-reference/v2/processes/start), [Process Stdin](/api-reference/v2/processes/stdin), and [Close Process Stdin](/api-reference/v2/processes/close-stdin) instead.

## Endpoint

```http theme={null}
POST /api/v1/processes/run
```

Use this endpoint on the sandbox proxy host:

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

## Example Request

```bash theme={null}
curl -N -X POST https://<sandbox-id>.sandbox.tensorlake.ai/api/v1/processes/run \
  -H "Authorization: Bearer $TENSORLAKE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "python",
    "args": ["-c", "import os; print(os.environ[\"MODE\"])"],
    "env": {"MODE": "batch"},
    "working_dir": "/workspace",
    "timeout": 30
  }'
```

## Request Body

```json theme={null}
{
  "command": "python",
  "args": ["-c", "print('hello')"],
  "env": {"MODE": "batch"},
  "working_dir": "/workspace",
  "user": "tl-user",
  "timeout": 30
}
```

* `command` is required.
* `args` defaults to `[]`.
* `env` defaults to `{}` and is applied to the process environment.
* `working_dir` is optional.
* `user` is optional and accepts a username, UID string, `uid:gid` string, or an object such as `{"uid": 1000, "gid": 1000}`.
* `timeout` is optional. When set, Tensorlake kills the process if it is still running after that many seconds.

<Note>
  `/processes/run` always starts the process with stdin closed and stdout/stderr captured, even if `stdin_mode`, `stdout_mode`, or `stderr_mode` are present in the request body.
</Note>

## SSE Events

Tensorlake streams JSON payloads in SSE `data:` frames:

```text theme={null}
data: {"handle":1,"pid":42,"started_at":1710000000000}

data: {"line":"hello","timestamp":1710000000010,"stream":"stdout"}

data: {"exit_code":0}
```

The first event contains `handle`, `pid`, and `started_at`. Output events contain `line`, `timestamp`, and `stream`. The final event contains `exit_code` or `signal`; if the kernel OOM killer ended the process, it includes `signal: 9` and `oom_killed: true`.


## OpenAPI

````yaml post /api/v1/processes/run
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/processes/run:
    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-processes
      summary: Run a process
      description: >-
        Start a non-interactive process, stream captured output over Server-Sent
        Events, and emit a final exit event. Stdin is closed for this endpoint.
      operationId: sandbox_process_run
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SandboxRunProcessRequest'
      responses:
        '200':
          description: Process event stream
          content:
            text/event-stream:
              schema:
                $ref: '#/components/schemas/SandboxRunProcessEvent'
              examples:
                started:
                  summary: Process started
                  value: |+
                    data: {"handle":1,"pid":42,"started_at":1710000000000}

                output:
                  summary: Process output
                  value: >+
                    data:
                    {"line":"hello","timestamp":1710000000010,"stream":"stdout"}

                exited:
                  summary: Process exited
                  value: |+
                    data: {"exit_code":0}

        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SandboxProxyError'
components:
  schemas:
    SandboxRunProcessRequest:
      type: object
      required:
        - command
      properties:
        command:
          type: string
        args:
          type: array
          items:
            type: string
        env:
          type: object
          additionalProperties:
            type: string
        working_dir:
          type: string
        user:
          $ref: '#/components/schemas/SandboxProcessUser'
        timeout:
          type: number
          format: double
          description: Maximum seconds to wait before killing the process.
    SandboxRunProcessEvent:
      description: >-
        JSON payload carried in each Server-Sent Events `data:` frame from
        `/api/v1/processes/run`.
      oneOf:
        - $ref: '#/components/schemas/SandboxRunProcessStartedEvent'
        - $ref: '#/components/schemas/SandboxProcessOutputEvent'
        - $ref: '#/components/schemas/SandboxRunProcessExitedEvent'
    SandboxProxyError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        code:
          type: string
    SandboxProcessUser:
      oneOf:
        - type: string
          description: Username, UID string, or uid:gid string.
        - type: object
          properties:
            name:
              type: string
            uid:
              type: integer
              format: int32
            gid:
              type: integer
              format: int32
    SandboxRunProcessStartedEvent:
      type: object
      required:
        - handle
        - pid
        - started_at
      properties:
        handle:
          type: integer
          format: int64
        pid:
          type: integer
          format: int32
        started_at:
          type: integer
          format: int64
    SandboxProcessOutputEvent:
      type: object
      required:
        - line
        - timestamp
      properties:
        line:
          type: string
        timestamp:
          type: integer
          format: int64
        stream:
          type: string
          enum:
            - stdout
            - stderr
    SandboxRunProcessExitedEvent:
      type: object
      properties:
        exit_code:
          type:
            - integer
            - 'null'
          format: int32
        signal:
          type:
            - integer
            - 'null'
          format: int32
        oom_killed:
          type: boolean
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````