---
title: "Write a file into the sandbox. Accepts two body shapes — the SDK picks one based on `Content-Type`:"
method: POST
path: "/v1/sandboxes/{id}/fs/write"
tags: ["Sandboxes"]
---

# Write a file into the sandbox. Accepts two body shapes — the SDK picks one based on \`Content-Type\`:

`POST /v1/sandboxes/{id}/fs/write`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/v1/sandboxes/{id}/fs/write`
- Auth: HTTP bearer

- **`application/json`** (temps-native): `{path, contents_b64, mode}`
  — one file, base64-encoded.
- **`application/gzip`** (`@vercel/sandbox`): a gzipped tarball of
  one-or-more entries, with the target extract dir carried in the
  `x-cwd` header. The SDK's `writeFile` and `writeFiles` both post
  here; they differ only in how many entries the tarball contains.

Why merge them on one route: the SDK is hardcoded to
`POST /fs/write`, so splitting tar uploads onto a separate path would
force us to break SDK compat. Instead we dispatch on Content-Type,
preserve JSON for native callers, and add tar for SDK callers.

## Path parameters

- `id` string, required

## Request body

- WriteFileBody
  - `contents_b64` string, required: File contents, base64-encoded. Required — lets callers ship binary data over JSON without charset games.
  - `mode` integer, nullable: Unix permission mask (e.g. 0o644). Defaults to 0o644 when absent.
  - `path` string, required: Absolute path inside the sandbox. Must start with `/`.

## Response `204`

File(s) written

## Other responses

- `400`: Validation error or invalid base64
- `404`: Sandbox not found
- `415`: Unsupported Content-Type (expected application/json or application/gzip)

## Changes

- **2026-04-25** `774be20905f2`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/v1/sandboxes/:id/fs/write/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
