# Generating files (/files/generating)



A workflow can produce text, such as a summary or CSV, or a file object, such as an image or audio clip. Save the result to workspace **Files** when it needs a stable workspace identity for later runs, editing, or sharing.

A file returned by a block can belong only to the execution. Returning it and saving it to Files are separate actions.

## Save text with Write [#saving-content-with-the-file-block]

To save an Agent's summary as Markdown:

1. Connect the Agent to a [File](/integrations/file) block.
2. Select **Write**.
3. Set **File Name** to `research_summary.md`.
4. Set **Content** to `<agent.content>` and leave **File** empty.
5. Choose a destination folder if needed, then run the workflow.

The saved file appears in workspace **Files**. Write returns:

| Field | Meaning |
| - | - |
| `id` | Canonical workspace file ID |
| `name` | Saved name, including any suffix added to avoid a duplicate |
| `size` | Stored file size in bytes |
| `url` | File access URL; it does not grant public access |
| `version` | Content version recorded by the write |
| `revision` | Opaque token identifying the written content |

The content type is inferred from the extension: `.md` becomes `text/markdown`, and `.csv` becomes `text/csv`. **Content Type** in advanced mode overrides it. Setting `application/pdf` on a text string does not render a PDF; use an actual PDF file for that format.

A [Function](/workflows/blocks/function) can build text deterministically, such as CSV or JSON. Use `<function.result>` as **Content** when the returned value is the text you want to store. See [Using files in workflows](/files/using-in-workflows) for the full read → summarize → save example.

## Save an existing file [#save-an-existing-file]

If a block already returns a file object, pass it to Write's **File** input and leave **Content** empty. Set **File Name** and the destination folder. Provide exactly one source: text in **Content**, or an existing object in **File**.

For example, ElevenLabs text-to-speech returns `<elevenlabs.audioFile>`. An image generator returns an image file, and a remote Function can return `<function.files[0]>`. These objects can go directly to compatible attachment or upload inputs. Write's **File** input copies their bytes into workspace Files so later runs can reuse them.

At the tool level, `file_write` accepts `fileInput` and can inherit the source name when `fileName` is omitted. The current block editor still requires **File Name**.

## Create, overwrite, or append [#create-overwrite-or-append]

By default, Write keeps an existing file with the same name in the destination folder and adds a numeric suffix to the new file: `data.csv`, `data (1).csv`, then `data (2).csv`.

Turn on **Overwrite Existing File** to replace the file at the exact destination name and folder. If that path does not exist, Write creates it. Use **Append** to add text to the end of an existing file instead. Select the file directly, or use its name with a folder scope to avoid targeting an ambiguous name.

For file tools or API operations that accept `expectedRevision`, use it to guard a content change based on an earlier read. A version number can stay the same across coalesced collaborative or workflow writes, so it is not an exact content precondition. For Write, `expectedRevision` requires `overwrite: true`. See the [file content API](/api-reference/files/updateFileContent) and [version history API](/api-reference/files/listFileVersions).

## Generate files with Function [#what-produces-file-content]

A remote Function can write files under `/tmp/sim/outputs`. Sim returns those files as the block's `files` output, ready for a compatible downstream input:

```python
with open('/tmp/sim/outputs/summary.csv', 'w') as handle:
    handle.write('category,count\ncompleted,12\nfailed,2\n')
```

Pass `<function.files[0]>` to File **Write** to keep this execution artifact in workspace Files. Automatic exports allow up to 20 files and 50 MiB total; exceeding a cap fails the export rather than returning a partial set.

The Chat workbench uses a per-call `SIM_OUTPUT_DIR`; outputs written there are exported to workspace Files. Use the environment-provided directory in that context. The separate Function tool also supports explicit `outputPath` and `outputSandboxPath` persistence. These are tool capabilities, not fields in the current Function block editor.

## Reuse and return a file [#where-the-file-goes]

Saved files belong to the workspace. Authorized later runs can select them in a file picker or read them by canonical ID with **Read**; use **Get Content** when the next step needs extracted text. Renaming or moving a file does not require another workflow to generate it again.

A [Response](/workflows/blocks/response) block can return a file object or a saved file ID to an API caller. The response does not create public access. API-key callers download saved workspace files through the Files API, or run-produced files through the run-file endpoint. Optional base64 output can include eligible bytes within its limits. See [Passing files](/files/passing-files#receiving-files-in-api-responses).

## Related docs [#next]

* [Files](/files)
* [Using files in workflows](/files/using-in-workflows)
* [Passing files](/files/passing-files)
* [File block](/integrations/file)
* [API deployment](/workflows/deployment/api)
