# Generate a file from code and save it

**Use case:** 

Runs a Python snippet that writes a CSV file (`squares.csv`) during the run and preserves it in the run's key-value store via `saveFiles`. The snippet also prints a small JSON summary. Use this pattern to produce reports, exports or generated assets from code. Adjust `code` and the `saveFiles` list.

## Input

```json
{
  "language": "python",
  "code": "import csv, json\nrows = [[\"id\", \"square\"]] + [[i, i*i] for i in range(1, 11)]\nwith open(\"squares.csv\", \"w\", newline=\"\") as f:\n    csv.writer(f).writerows(rows)\nprint(json.dumps({\"file\": \"squares.csv\", \"rows\": len(rows) - 1}))",
  "stdin": "",
  "parseJsonOutput": true,
  "timeoutSeconds": 5,
  "maxOutputBytes": 256000,
  "saveFiles": [
    "squares.csv"
  ],
  "maxSavedFileBytes": 5000000
}
```

## Output

```json
{
  "status": {
    "label": "Status",
    "format": "text"
  },
  "language": {
    "label": "Language",
    "format": "text"
  },
  "exitCode": {
    "label": "Exit code",
    "format": "number"
  },
  "signal": {
    "label": "Signal",
    "format": "text"
  },
  "durationMs": {
    "label": "Duration (ms)",
    "format": "number"
  },
  "timedOut": {
    "label": "Timed out",
    "format": "boolean"
  },
  "outputTruncated": {
    "label": "Output truncated",
    "format": "boolean"
  },
  "terminationReason": {
    "label": "Termination reason",
    "format": "text"
  },
  "resultParseError": {
    "label": "Result parse error",
    "format": "text"
  },
  "executedAt": {
    "label": "Executed at",
    "format": "text"
  }
}
```

## About this Actor

This example demonstrates how to use [AI Code Runner Sandbox](https://apify.com/parsebird/code-runner-sandbox.md) with a specific input configuration. Visit the [Actor detail page](https://apify.com/parsebird/code-runner-sandbox.md) to learn more, explore other use cases, and run it yourself.


## How to integrate an Actor?

This Task's input is already configured above. Use it as-is rather than inventing a new one.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For full API examples (JavaScript, Python, CLI, MCP, OpenAPI), see this Task's Actor page: https://apify.com/parsebird/code-runner-sandbox.md

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).
