Parameters
filestringrequiredThe path to write, relative to the workspace.
contentstring | Buffer | Uint8Array | ArrayBufferrequiredWhat to write. Anything else is refused.
Text
const item = await pc.files.write("Launch plan/brief.md", "# Brief\n\nShip in March.");
// { name: "brief.md", path: "Launch plan/brief.md", type: "file", size: 29,
// mimeType: "text/markdown", modifiedAt: "…" }item = pc.files.write("Launch plan/brief.md", "# Brief\n\nShip in March.")
# {"path": "Launch plan/brief.md", "size": 29}A string is written as UTF-8. The mimeType that comes back is read from the extension, not from the content — so the name you choose is what decides how the file is later treated.
Binary
// A generated image, straight from a model session
const [picture] = await session.generate({
inputs: [{ type: "text", content: "A fox in the snow" }],
outputs: [{ type: "image" }],
}).then((r) => r.outputs);
await pc.files.write("Assets/fox.png", Buffer.from(picture.content, "base64"));
// A download
const response = await fetch("https://example.com/report.pdf");
await pc.files.write("Reports/report.pdf", await response.arrayBuffer());import base64, urllib.request
# A generated image, straight from a model session
picture = session.generate(
inputs=[{"type": "text", "content": "A fox in the snow"}],
outputs=[{"type": "image"}],
)["outputs"][0]
pc.files.write("Assets/fox.png", base64.b64decode(picture["content"]))
# A download
with urllib.request.urlopen("https://example.com/report.pdf") as response:
pc.files.write("Reports/report.pdf", response.read())It replaces, and keeps nothing
write() is the plain operation: the old content is gone. Keeping a copy is what the agent's own write tools add on top, under .versions/ — if you want that behaviour in your code, read the file first and write the copy yourself.
// Keep a copy before replacing
const before = await pc.files.read("notes.md");
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
await pc.files.write(`.versions/notes.md/${stamp}.md`, before.content);
await pc.files.write("notes.md", next);from datetime import datetime, timezone
# Keep a copy before replacing
before = pc.files.read("notes.md")
stamp = datetime.now(timezone.utc).isoformat().replace(":", "-").replace(".", "-")
pc.files.write(f".versions/notes.md/{stamp}.md", before["content"])
pc.files.write("notes.md", next_content)Folders are created as needed
Writing Clients/Acme/2026/invoice.md creates the three folders on the way. One call, whatever the depth.
Errors
| Code | Status | When |
|---|---|---|
| missing_content | 400 | content is undefined or null. An empty string is valid. |
| invalid_content | 400 | Not a string, a Buffer, a Uint8Array or an ArrayBuffer. |
| invalid_path | 400 | Absolute, outside the workspace, or the workspace root. |
| local_files_require_node | 400 | The runtime has no filesystem. |
| storage_not_on_this_machine | 409 | Another computer's storage. |
An object is not serialised for you: pass JSON.stringify(value), so the formatting stays yours.