Code sandbox is in Beta. Its shape may change without a version.
transform(input_data: Input) -> Output, and the fields of Output. For each document the node runs your function in a sandbox with no network access and stores the JSON object it returns.
No model writes or checks the code. Saving the workflow stores the code only. Nothing runs until a document does.
The node
Options
The node does not accept the retired
instructions and template fields. The schema the API accepts is generated from the same source: Code sandbox node schema.
What the function receives
- After an Extract,
Inputhas one field for each extracted field, named by the field’s sanitized name (the name made safe as a Python identifier). Every value can beNone. A value that does not fit its declared type arrives as text. There is no confidence and no evidence. - After a Parse,
Inputholdspages, and each page holdsnumber,textandblocks.
Limits
Thecode may not exceed 64 KiB (65,536 bytes of UTF-8). The function runs for at most 60 seconds and 1024 MB of memory. Its output may not exceed 1 MiB. A run that breaks a limit, raises, or returns something that is not a valid Output fails the whole run.
When the function fails
If your function raises, returns something that does not matchoutput_schema, writes more than 1 MiB, or runs out of time or memory, the run ends in error. It is not retried, because the same code would fail on the same document, and it is not charged. The error message names the exception and the lines of your code that raised it; fix the code and run the document again. The error message is recorded on the node’s run, but the public run response carries only status: error and no reason yet. An organization with zero data retention records only the exception type.
A succeeded function bills 5 credits for each run of the node, once per split behind a splitter.
Connects to
Parse or Extract feeds Code sandbox, and nothing follows it.
What it returns
The node fills thesandbox_outputs section of the run results: one entry per split the node ran for.
status is succeeded. A function that fails ends the run in error, and a failed run has no results, so the value is always succeeded. output is the JSON object your function returned, and null when its stored output is no longer available. In the Python SDK, run.wait().sandbox_outputs holds the same entries.
