---
title: "Preview Code Step"
method: POST
path: "/workflow/code-steps/preview"
tags: ["code-steps"]
---

# Preview Code Step

`POST /workflow/code-steps/preview`

## Request

- Base URL: `https://api.anyreach.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.anyreach.ai/workflow/code-steps/preview`
- Auth: HTTP bearer

Run Python code in the same sandbox path as a workflow code step (no workflow execution).

Sync handler so ``run_code_preview`` (sandbox + user code) runs in FastAPI's thread pool
instead of blocking the asyncio event loop.

## Headers

- `x-anyreach-org` string, nullable: Organization ID for user PATs (pat_ prefix tokens)

## Request body

- CodePreviewRequest
  - `code` string, required: Python function body for the code step
  - `packages` string[], nullable: pip packages to install before run; defaults to service default
  - `context_data` object: Workflow JSONata context (WorkflowContext.data) for preview
  - `step_id` string: Step id used for ctx.current_step_id and recorded outputs

## Response `200`

Successful Response

- CodePreviewResponse
  - `status` string, required: SUCCESS or FAILURE
  - `output` unknown
  - `error` string, nullable: Step-level error message
  - `stdout` string
  - `stderr` string
  - `execution_error` string, nullable: Interpreter/sandbox error string if any

## Other responses

- `404`: Not found
- `422`: Validation Error

---

[API](https://skmtc.dev/anyreach/apis/anyreach-api.md) - [All operations](https://skmtc.dev/anyreach/apis/anyreach-api/llms.txt) - [OpenAPI document](https://skmtc.dev/anyreach/apis/anyreach-api/revisions/2eddf40c8c93?raw)
