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

# Write Files (Batch)

> Write multiple files to a sandbox in a single request.

Writes multiple files to the sandbox filesystem in a single API call. All files
are written atomically through envd. Parent directories are created automatically
for each entry.

Use batch writes to upload a project's source files, configuration, or datasets
without making one API call per file.

## Path Parameters

<ParamField path="sandbox_id" type="string" required>
  The sandbox identifier. Format: `sbx-<8 chars>`.
</ParamField>

## Request Body

<ParamField body="files" type="object[]" required>
  Array of file entries to write. Each entry has a `path` and `data` field.

  <Expandable title="File entry fields">
    <ParamField body="path" type="string" required>
      Absolute path to write inside the sandbox.
    </ParamField>

    <ParamField body="data" type="string" required>
      File content as a string.
    </ParamField>
  </Expandable>
</ParamField>

## Response

Returns the envd batch write confirmation as a JSON object.

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/files/batch \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "files": [
        { "path": "/home/user/main.py", "data": "import helper\nhelper.run()\n" },
        { "path": "/home/user/helper.py", "data": "def run(): print(\"ok\")\n" }
      ]
    }'
  ```

  ```python Python theme={null}
  from declaw import Sandbox

  sbx = Sandbox.connect("sbx-a1b2c3d4", api_key="YOUR_API_KEY", domain="api.declaw.ai")
  sbx.files.write_files([
      {"path": "/home/user/main.py", "data": "import helper\nhelper.run()\n"},
      {"path": "/home/user/helper.py", "data": "def run(): print('ok')\n"},
  ])
  ```

  ```typescript TypeScript theme={null}
  import { Sandbox } from "@declaw/sdk";

  const sbx = await Sandbox.connect("sbx-a1b2c3d4", {
    apiKey: "YOUR_API_KEY",
    domain: "api.declaw.ai",
  });
  await sbx.files.writeFiles([
    { path: "/home/user/main.py", data: "import helper\nhelper.run()\n" },
    { path: "/home/user/helper.py", data: "def run(): print('ok')\n" },
  ]);
  ```
</CodeGroup>

## Error Responses

| Status | Cause                      |
| ------ | -------------------------- |
| `400`  | Invalid request body       |
| `401`  | Missing or invalid API key |
| `404`  | Sandbox not found          |
| `502`  | envd daemon unreachable    |
| `503`  | Sandbox has no VM          |
