---
title: "Write to command stdin"
method: POST
path: "/v2/sandboxes/sessions/{sessionId}/cmd/{cmdId}/stdin"
tags: ["sandboxes"]
---

# Write to command stdin

`POST /v2/sandboxes/sessions/{sessionId}/cmd/{cmdId}/stdin`

## Request

- Base URL: `https://api.vercel.com`
- URL: `https://api.vercel.com/v2/sandboxes/sessions/{sessionId}/cmd/{cmdId}/stdin`
- Auth: HTTP bearer

Writes data to the stdin of a running command, and optionally closes it. The command must have been started with `attachStdin` set to true. Writes are applied in the order they are received. Send them one at a time to keep the data in order. A write returns once the command has accepted the data, and fails with a 504 after 30 seconds if the command is not reading stdin. Each write counts against the sandbox control plane rate limit, so batch small writes where possible. Set `offset` to the position in stdin where `data` starts to make a request safe to resend, for example after a 502 or 504: bytes the command has already received are skipped, and an offset past them fails with a 409. The response returns `bytesWritten`, the total written so far, and a 504 includes it in the error when the sandbox reports it. A request with no `data` and no `close` writes nothing and returns it.

## Path parameters

- `cmdId` string, required: The unique identifier of the command to write to.
- `sessionId` string, required: The unique identifier of the session containing the command.

## Query parameters

- `teamId` string
- `slug` string

## Request body

- object
  - `data` string: Base64-encoded bytes to write to the command stdin. The request body is limited to 1 MB, so send at most about 700 KB of data per request.
  - `offset` integer: The position in the command stdin where `data` starts. Bytes before the total already written are skipped, so a resent request does not write them twice. Fails with 409 if it is past the bytes written so far. Without it, `data` is appended.
  - `close` boolean: If true, closes the command stdin after writing `data`. Use this for commands that wait for end of input.

## Response `200`

The data was written to the command's stdin.

- object
  - `bytesWritten` number
  - `command` SessionCommand, required: This object represents a command run in a Vercel Sandbox session (v2 API).
    - `args` string[], required: The arguments of the command.
    - `cwd` string, required: The current working directory of the command.
    - `durationMs` number: Duration of the command execution in milliseconds.
    - `exitCode` number, nullable, required: If the command did finish, the exit code.
    - `id` string, required: The ID of the command.
    - `name` string, required: The name of the command.
    - `sessionId` string, required: The ID of the session associated with the command.
    - `startedAt` number, required: When the command was started, in milliseconds since the epoch.

## Other responses

- `400`: One of the provided values in the request body is invalid. One of the provided values in the request query is invalid.
- `401`: The request is not authorized.
- `403`: You do not have permission to access this resource.
- `404`
- `409`
- `410`
- `422`
- `429`
- `502`
- `504`

## Changes

- **2026-10-23** `0ab54ee1bd2e`: 1 info
  - removed the non-success response with the status `500`
- **2026-10-10** `32399b3ed273`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/vercel/apis/api/changes/v2/sandboxes/sessions/:sessionId/cmd/:cmdId/stdin/post.md)

---

[API](https://skmtc.dev/vercel/apis/api.md) - [All operations](https://skmtc.dev/vercel/apis/api/llms.txt) - [OpenAPI document](https://skmtc.dev/vercel/apis/api/revisions/4a06e85c2848?raw)
