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

# Write a file or create a directory

> Writes the raw request body to the file at `path`, whatever its `Content-Type`: `201` with the file's entry when it was created, `200` when it replaced one. **The file is replaced in one step:** readers see the whole old content or the whole new content, and a write that fails or is cut off (the client leaves, the body is too large, the time runs out) leaves the file exactly as it was. Missing parent directories are created (`0755`) once the whole body has arrived. A new file gets `0644`; a replaced one keeps its permission bits. A write through a symlink writes the file it points to and keeps the link, even when that file doesn't exist yet.

**Permissions:** a write needs permission to write both the file and its directory (`permission_denied` otherwise: a file you own in a directory you can't write can still be changed with an exec), and a non-root writer becomes the replaced file's owner; root keeps the old owner. **Costs:** an overwrite needs room for both copies until the new one replaces the old; hard links to the old file keep the old content, and processes holding it open keep reading it. Files the sandbox mounts itself (`/etc/hosts`, `/etc/resolv.conf`, `/etc/hostname`) can't be replaced this way (`file_operation_failed`; use an exec).

A directory at `path`, or something that's neither a file nor a directory (a device, FIFO or socket, which is kept), is `path_type_mismatch`; so is a `path` ending in `/`, or a parent that's a file. A `path` ending in `.` or `..`, or under the reserved `/.telnyx` directory, is `invalid_path`.

**Size and time:** up to 64 MiB. A declared `Content-Length` over it is `file_too_large` before anything is sent to the sandbox; a body without one is refused as soon as it passes it. The body must be complete 2 s before the call's time budget ends: a body still arriving then is `408` (code 10008), and the file is unchanged. **A `503` after the whole body was sent may have written the file**; retrying writes the same content again, which is harmless.

**With `directory=true`** and an empty body (else `400`): creates the directory at `path` with any missing parents, `201`, or `200` if a directory was already there; trailing slashes are ignored, and a file in the way is `path_type_mismatch`.

Send an `Idempotency-Key`: a retry with the same key, path, flags and body gets the stored answer, and nothing is written again; a different request with it is `idempotency_key_reused`.

`path` is absolute, at most 4096 bytes in UTF-8, and must be valid UTF-8 once percent-decoded; it's taken as the sandbox's kernel resolves it (`.`, `..` and `//` included). A path holding a NUL byte is `invalid_path`.

The sandbox must be running (else `sandbox_not_running`); file calls keep working during the stop's grace period, so you can fetch results from a sandbox that's ending. They run as the sandbox's own user, with its permissions: what that user may not do, or a read-only file system, is `permission_denied`. Another refusal by the sandbox's file system (no space, a name too long, a busy file or mount point, a symlink loop, an I/O error) is `file_operation_failed`, with a fixed text naming the reason. File calls don't count as activity for `idle_timeout`.

Each call has a 64 MiB limit and a time budget of about 12 s for its whole transfer, so a full-size file needs about 5.3 MiB/s between you and the API to read, and about 6.4 MiB/s to write (a write's body must arrive 2 s before the budget ends). Move larger data through Cloud Storage from an exec.



## OpenAPI

````yaml /openapi/source/external/sandboxes/sandboxes.json put /ai/sandboxes/{sandbox_id}/files
openapi: 3.1.0
info:
  title: Telnyx API
  version: 1.0.0
  description: >-
    Run a container image of your choice on a whole GPU node, each sandbox in
    its own virtual machine, for seconds or indefinitely. Run commands inside
    it, move files in and out, stream its logs, read its metrics, and pay per
    second while it runs.


    ## Preview


    GPU Sandboxes is in an invite-only preview. `GET /ai/sandbox-access` tells
    whether it is enabled for your organization.


    ## Authentication


    All endpoints require a Telnyx API key sent as a Bearer token in the
    `Authorization` header.


    ## Retries


    Every side-effecting endpoint accepts an `Idempotency-Key` header. Send one
    on `POST /ai/sandboxes` and `POST /ai/sandboxes/{sandbox_id}/execs`, so a
    retry after a lost response doesn't start (and bill) a second workload.


    ## Errors


    Errors use the standard Telnyx error body. General errors carry their
    5-digit `code` (e.g. `10009`); Sandboxes-specific errors are identified by
    their name in `title` (e.g. `quota_exceeded`).
  contact:
    email: support@telnyx.com
  x-latency-category: responsive
  x-endpoint-cost: light
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: Sandboxes
    description: >-
      Create, find, wait for, tag and terminate sandboxes, and close the main
      process's stdin.
  - name: Sandbox execs
    description: Run commands in a running sandbox.
  - name: Sandbox files
    description: Read, write, list and delete files inside a running sandbox.
  - name: Sandbox logs
    description: The main process's stored and live output.
  - name: Sandbox metrics
    description: CPU, network, memory, disk and GPU usage.
  - name: Sandbox GPU types
    description: What you can rent, and at what price.
  - name: Sandbox access
    description: Whether Sandboxes is enabled for your organization.
paths:
  /ai/sandboxes/{sandbox_id}/files:
    put:
      tags:
        - Sandbox files
      summary: Write a file or create a directory
      description: >-
        Writes the raw request body to the file at `path`, whatever its
        `Content-Type`: `201` with the file's entry when it was created, `200`
        when it replaced one. **The file is replaced in one step:** readers see
        the whole old content or the whole new content, and a write that fails
        or is cut off (the client leaves, the body is too large, the time runs
        out) leaves the file exactly as it was. Missing parent directories are
        created (`0755`) once the whole body has arrived. A new file gets
        `0644`; a replaced one keeps its permission bits. A write through a
        symlink writes the file it points to and keeps the link, even when that
        file doesn't exist yet.


        **Permissions:** a write needs permission to write both the file and its
        directory (`permission_denied` otherwise: a file you own in a directory
        you can't write can still be changed with an exec), and a non-root
        writer becomes the replaced file's owner; root keeps the old owner.
        **Costs:** an overwrite needs room for both copies until the new one
        replaces the old; hard links to the old file keep the old content, and
        processes holding it open keep reading it. Files the sandbox mounts
        itself (`/etc/hosts`, `/etc/resolv.conf`, `/etc/hostname`) can't be
        replaced this way (`file_operation_failed`; use an exec).


        A directory at `path`, or something that's neither a file nor a
        directory (a device, FIFO or socket, which is kept), is
        `path_type_mismatch`; so is a `path` ending in `/`, or a parent that's a
        file. A `path` ending in `.` or `..`, or under the reserved `/.telnyx`
        directory, is `invalid_path`.


        **Size and time:** up to 64 MiB. A declared `Content-Length` over it is
        `file_too_large` before anything is sent to the sandbox; a body without
        one is refused as soon as it passes it. The body must be complete 2 s
        before the call's time budget ends: a body still arriving then is `408`
        (code 10008), and the file is unchanged. **A `503` after the whole body
        was sent may have written the file**; retrying writes the same content
        again, which is harmless.


        **With `directory=true`** and an empty body (else `400`): creates the
        directory at `path` with any missing parents, `201`, or `200` if a
        directory was already there; trailing slashes are ignored, and a file in
        the way is `path_type_mismatch`.


        Send an `Idempotency-Key`: a retry with the same key, path, flags and
        body gets the stored answer, and nothing is written again; a different
        request with it is `idempotency_key_reused`.


        `path` is absolute, at most 4096 bytes in UTF-8, and must be valid UTF-8
        once percent-decoded; it's taken as the sandbox's kernel resolves it
        (`.`, `..` and `//` included). A path holding a NUL byte is
        `invalid_path`.


        The sandbox must be running (else `sandbox_not_running`); file calls
        keep working during the stop's grace period, so you can fetch results
        from a sandbox that's ending. They run as the sandbox's own user, with
        its permissions: what that user may not do, or a read-only file system,
        is `permission_denied`. Another refusal by the sandbox's file system (no
        space, a name too long, a busy file or mount point, a symlink loop, an
        I/O error) is `file_operation_failed`, with a fixed text naming the
        reason. File calls don't count as activity for `idle_timeout`.


        Each call has a 64 MiB limit and a time budget of about 12 s for its
        whole transfer, so a full-size file needs about 5.3 MiB/s between you
        and the API to read, and about 6.4 MiB/s to write (a write's body must
        arrive 2 s before the budget ends). Move larger data through Cloud
        Storage from an exec.
      operationId: WriteSandboxFile
      parameters:
        - description: Sandbox ID (`sb-…`).
          in: path
          name: sandbox_id
          required: true
          schema:
            maxLength: 64
            minLength: 1
            type: string
          example: sb-0192f1c2-7a4b-7c3e-9d1e-2f3a4b5c6d7e
        - description: >-
            Absolute path inside the sandbox, e.g. `/app/out.txt`, at most 4096
            bytes in UTF-8.
          in: query
          name: path
          required: true
          schema:
            maxLength: 4096
            minLength: 1
            pattern: ^/
            type: string
          example: /app/out/results.json
        - description: Create a directory at `path` (send an empty body).
          in: query
          name: directory
          required: false
          schema:
            default: false
            type: boolean
        - description: >-
            Optional client-chosen key (e.g. a UUID, at most 255 characters)
            that makes the call safe to retry. Within 24 h, the same key with
            the same request returns the stored response instead of acting
            twice; the same key with a different request fails with
            `idempotency_key_reused`; a request with a key that's still being
            processed fails with `request_in_progress`.
          in: header
          name: Idempotency-Key
          required: false
          schema:
            maxLength: 255
            minLength: 1
            type: string
      requestBody:
        description: >-
          The file's contents, as raw bytes whatever the `Content-Type`; empty
          when `directory=true`.
        required: false
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
            example: '{"accuracy": 0.912, "split": "test"}'
      responses:
        '200':
          description: The file or directory already existed and was replaced or kept.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileEntryRespData'
              example:
                data:
                  name: results.json
                  path: /app/out/results.json
                  type: file
                  size_bytes: 18234
                  modified_at: '2026-11-13T10:42:17Z'
        '201':
          description: A new file or directory was created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FileEntryRespData'
              example:
                data:
                  name: results.json
                  path: /app/out/results.json
                  type: file
                  size_bytes: 18234
                  modified_at: '2026-11-13T10:42:17Z'
        '400':
          description: >-
            Validation error: the standard Telnyx validation errors (codes such
            as 10004 missing parameter, 10015 bad request, 10025 invalid string
            length, 10026 invalid type).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
        '401':
          description: Missing or invalid API key (code 10009).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10009'
                    title: Authentication failed
                    detail: Could not find any usable credentials in the request.
        '403':
          description: >-
            - `sandboxes_require_verification`: your account isn't fully
            verified.

            - `sandboxes_not_whitelisted`: Sandboxes isn't enabled for your
            organization (invite-only preview); `GET /ai/sandbox-access` tells
            whether it is.

            - `permission_denied`: the sandbox's user may not do this at the
            path, or its file system is read-only.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: sandboxes_not_whitelisted
                    detail: The organization isn't whitelisted.
        '404':
          description: >-
            Not found (code 10005): the resource doesn't exist or belongs to
            another organization. The detail says what's missing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10005'
                    title: Resource not found
                    detail: Sandbox not found.
        '408':
          description: >-
            Request timeout (code 10008): the request body didn't arrive within
            the call's time budget.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10008'
                    title: Request timeout
                    detail: The request body didn't arrive in time.
        '409':
          description: >-
            - `request_in_progress`: a request with the same `Idempotency-Key`
            is still being processed; retry later.

            - `sandbox_not_running`: the operation needs a running sandbox.

            - `path_type_mismatch`: the path is a directory where a file was
            expected, or the reverse (a parent that's a file included), or
            neither a file nor a directory.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: path_type_mismatch
                    detail: The path is a directory.
        '413':
          description: >-
            - `file_too_large`: the file is over the 64 MiB per-request limit;
            move large data through Cloud Storage.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: file_too_large
                    detail: The file is larger than 64 MiB.
        '422':
          description: >-
            - `idempotency_key_reused`: the same `Idempotency-Key` was sent with
            a different request.

            - `invalid_path`: the path holds a NUL byte, or a write or delete
            names the reserved `/.telnyx` directory, ends in a final `.` or
            `..`, or deletes `/`.

            - `file_operation_failed`: the sandbox's file system refused for
            another stated reason: no space, a name too long, a busy file or
            mount point, a symlink loop, or an I/O error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - title: invalid_path
                    detail: The path is reserved.
        '503':
          description: A dependency can't answer right now (code 10037); retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelnyxErrors'
              example:
                errors:
                  - code: '10037'
                    title: Service unavailable
                    detail: A dependency can't answer right now; retry later.
components:
  schemas:
    FileEntryRespData:
      properties:
        data:
          $ref: '#/components/schemas/FileEntry'
      required:
        - data
      type: object
    TelnyxErrors:
      description: The standard Telnyx error body.
      properties:
        errors:
          description: One or more errors.
          items:
            $ref: '#/components/schemas/TelnyxError'
          type: array
      required:
        - errors
      type: object
    FileEntry:
      description: A file or directory inside the sandbox.
      properties:
        modified_at:
          description: >-
            Last modification time, by the sandbox's own clock, shown within
            years 1–9999.
          format: date-time
          type: string
        name:
          description: Base name, e.g. `out.txt`.
          type: string
        path:
          description: Absolute path, e.g. `/app/out.txt`.
          type: string
        size_bytes:
          description: >-
            The size the sandbox's file system reports for the entry itself, in
            bytes: a file's length, a symlink's target string, a directory's own
            size (often 4096).
          type: integer
        type:
          $ref: '#/components/schemas/FileType'
      required:
        - name
        - path
        - type
        - size_bytes
        - modified_at
      type: object
    TelnyxError:
      description: One error in the standard Telnyx error body.
      properties:
        code:
          description: >-
            Telnyx error code: a 5-digit string for general errors, e.g.
            `10009`. Sandboxes-specific errors are identified by their name in
            `title`.
          type: string
        detail:
          description: Human-readable explanation.
          type:
            - string
            - 'null'
        meta:
          description: Extra information.
          anyOf:
            - $ref: '#/components/schemas/TelnyxErrorMeta'
            - type: 'null'
        source:
          description: Where the error is.
          anyOf:
            - $ref: '#/components/schemas/TelnyxErrorSource'
            - type: 'null'
        title:
          description: >-
            Short, constant summary of the error. For Sandboxes-specific errors,
            the error's name, e.g. `quota_exceeded`.
          type: string
      required:
        - title
      type: object
    FileType:
      description: >-
        What the path is: a regular `file`, a `directory`, a `symlink`, or
        `other`

        (a device, FIFO or socket).
      enum:
        - file
        - directory
        - symlink
        - other
      type: string
    TelnyxErrorMeta:
      description: Extra error information.
      properties:
        url:
          default: null
          description: Documentation page for the error code.
          type:
            - string
            - 'null'
      type: object
    TelnyxErrorSource:
      description: Where in the request the error was found.
      properties:
        parameter:
          default: null
          description: Name of the offending parameter.
          type:
            - string
            - 'null'
        pointer:
          default: null
          description: JSON pointer into the request body, e.g. `/timeout`.
          type:
            - string
            - 'null'
      type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````