# Write a file

> Create or replace a file. Up to 5 MiB.

`PUT https://api.zavu.dev/v1/sandboxes/{sandboxId}/files`

Create or replace a file. Up to 5 MiB.

## Parameters

- `sandboxId` (path, string, required): Sandbox ID.

## Body

- `path` (string, required): Absolute, or relative to `/home/user`. Must resolve under `/home/user` or `/tmp`.
- `content` (string, required): Up to 5 MiB after decoding.
- `encoding` (string): Use `base64` for binary files. One of: `utf8`, `base64`.

## Responses

### 200

Written.

- `file` (object, required)
  - `path` (string, required)
  - `content` (string): Present on read.
  - `encoding` (string) One of: `utf8`, `base64`.
  - `size` (integer, required): Bytes.

### 400

Invalid body or path.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Sandbox not found, or it belongs to another project.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 409

`sandbox_not_running`: the sandbox is stopped, stopping, failed or deleted; resume it first. `sandbox_not_ready`: it is still starting and did not become ready in time; retry.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 413

`file_too_large`: the content is larger than 5 MiB.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X PUT "https://api.zavu.dev/v1/sandboxes/sandbox_abc123/files" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "path": "app/main.py",
  "content": "print('\''hello'\'')\n"
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.sandboxes.files.write("sandbox_abc123", {
  path: "app/main.py",
  content: "print('hello')\n",
});

console.log(result);
```
