# POST /automation/run

Execute an async JavaScript function body and retain its result.

This is a device HTTP route. Set `DEVICE_URL` to your reachable device URL; [connection and examples](https://mcp.applesauceos.com/doc/http.md) explain how. Do not append this path to the public MCP URL.

## Parameters

| Parameter | Type | Meaning |
| --- | --- | --- |
| `source` | JSON string | Inline async function body; exactly one of source/path; maximum 256 KiB. |
| `path` | JSON string | Saved relative .js file, executed as an async function body. |
| `id` | JSON string | Optional UUID or 32 hex characters chosen before submission; returned as lowercase 32-character runId. |
| `args` | JSON object | Optional; values become immutable strings in args. |

## Response

JSON {runId,nativeRunId,state,sourcePath}; initial state is submitted.

## Example

```sh
curl --fail-with-body "$DEVICE_URL/automation/run" \
  -H 'Content-Type: application/json' \
  -d '{"source":"console.log(\"Checking\"); return {foreground:frontMostAppId()};"}'
```

## Notes

Supports return and await. Use /scripts/run for ordinary .cso/.aso projects or repeats. Poll /automation/runs with the same ID after submission, including after a lost response. A retained ID cannot be submitted twice.

Check the HTTP status and any JSON error. [HTTP workflows and error handling](https://mcp.applesauceos.com/doc/http-guide.md) explain shared limits. [All endpoints](https://mcp.applesauceos.com/doc/http.md).
