/messages request. Use it to analyze uploaded data, run calculations, transform documents, or produce files such as charts, spreadsheets, and reports.
It follows the same model as the Anthropic code execution tool: the server runs every command, so you never execute code or send tool_result blocks yourself.
Prerequisites
- An API token. See Backoffice Developer Console.
- A configured code-execution provider, included by default in standard Zylon 1.58 deployments. For Workspace API requests, the Workspace code-execution feature must also be enabled. See Code Execution for configuration and disabled behavior.
Requirements
- Tool spec:
{ "name": "code_execution", "type": "code_execution_v1" } - Anthropic-compatible spec also accepted:
{ "name": "code_execution", "type": "code_execution_20250825" } - No
tool_contextrequired - Optional: a
containerID to reuse a sandbox across requests
Quick start
POST /api/gpt/v1/messages/validate.
How code execution works
When you add the code execution tool to a request:- The assistant decides whether running code would help answer the question.
- The tool expands into two sub-tools that the assistant can combine freely:
bash_code_execution: run shell commands.text_editor_code_execution: view, create, and edit files.
- Every operation runs server-side in a sandboxed container, and the results are fed back to the assistant within the same request.
- The response contains each tool call (
server_tool_use) and its result, followed by the assistant’s final answer. - The response also contains a top-level
containerobject. Pass itsidback in later requests to keep working in the same sandbox.
Sub-tools
bash_code_execution
Each call runs in a new shell. Files persist between calls; environment variables and
cd do not.
text_editor_code_execution
Relative paths resolve against the workspace (
/home/agent/workspace/).
Containers
A container is an isolated sandbox with its own file system. The container is identified by a string ID that you choose or that the server assigns.Select a container
Set the top-levelcontainer field to the ID you want to use. If the container doesn’t exist yet, it’s created; if it exists, the request reuses it and all its files.
Read the container from the response
When code runs, the response includes the container that was used:container object arrives in the final message_delta event as delta.container.
Reuse a container
Pass the samecontainer ID in follow-up requests to keep the files created earlier:
expires_at is a rolling value that is refreshed on every request. When a container is idle, its sandbox is shut down to free resources, but its files are kept. The next request with the same ID starts a fresh sandbox with the same files. Installed packages, running processes, and shell state aren’t kept.
To start clean, use a new container ID or delete the files.
File system layout
Runtime environment
The sandbox includes Python 3 with common data libraries: pandas, numpy, scipy, scikit-learn, statsmodels, matplotlib, seaborn, pyarrow, openpyxl, xlsxwriter, xlrd, pillow, python-pptx, python-docx, pypdf, pdfplumber, pypdfium2, pdf2image, pdfkit, tabula-py, reportlab, img2pdf, sympy, mpmath, tqdm, python-dateutil, pytz, and joblib. Command-line tools includeunzip, unrar, 7zip, bc, rg, fd, and sqlite3.
Networking and security
- No internet access. The sandbox can’t reach the internet, so packages can’t be installed at runtime. Only the pre-installed libraries are available.
- Zylon API access. The sandbox can reach the Zylon API, with these environment variables already set:
ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN, andANTHROPIC_MODEL. Code running in the sandbox, such as a script that uses the Anthropic SDK, can call the model with the permissions of the user who sent the request. - Isolation. Each container runs in its own sandbox, isolated from the host and from other containers.
Work with files
Use the Files API to put files into a container before a request, and to list, download, and delete the files it produced. Every Files API call takes ascope_id query parameter: this is the container ID.
Upload files
Upload a file into the container’s uploads folder. It’s available to the assistant at/mnt/user-data/uploads/{filename}:
id is the file ID used by the other endpoints. It’s the base64url-encoded sandbox path (here, /mnt/user-data/uploads/sales.csv), without padding.
Use the path query parameter to choose the key, for example to organize files into folders. Parent folders are created automatically, and uploading to an existing key overwrites it:
outputs/ places the file in /mnt/user-data/outputs/ instead. Keys must be relative and can’t contain .. or end with /.
You can also put raw bytes at a key, S3-style:
Analyze uploaded files
After uploading, send a message with the same container ID and refer to the file by its path:List files
List every file in a container, both uploads and generated outputs, sorted by creation time:downloadable is true for files in /mnt/user-data/outputs/ and false for uploads.
Optional query parameters:
Download files
Download a file with its ID:disposition=inline to open the file in the browser instead of downloading it.
The file ID is the base64url-encoded sandbox path, so you can also build it yourself:
Delete files
Delete one file, whether it’s an upload, a generated output, or a workspace file:/ so sibling keys that share the same text aren’t deleted:
End-to-end example
Code execution in the Workspace API
When you use the Workspace API instead of calling the ZylonGPT API directly, Zylon manages the container for you:- The container is the chat thread. Each thread gets its own sandbox, and the
containerfield is set to the thread ID. Files persist for the life of the thread, and threads can’t see each other’s files. - Code execution is added automatically when the request uses Skills and the Workspace feature is enabled. You can also request it explicitly through
pgpt.tools. Iffeatures.codeExecution.enabledisfalse, Workspace removes these tools, including explicitly requested ones. This flag does not globally disable the ZylonGPT API provider; see When disabled. - Generated files become artifacts. When the assistant presents a file, Zylon saves it as an artifact in the project and returns it in the stream as a
zylon-resourceblock, so users can preview and download it.
Downloads follow your organization’s settings: generated files (
outputs/) need generated-resource downloads to be enabled, and uploaded files (uploads/) need uploaded-resource downloads to be enabled.Response format
Each sub-tool call appears as aserver_tool_use block followed by its result block.
Bash command
return_code isn’t an error: it means the command ran and failed, and the assistant can read stderr and retry.
File operations
View:str_replace and insert):
Errors
When a tool can’t run, its result contains an error block:detail.explanation holds the underlying reason. It’s a Zylon extension and is omitted in Anthropic-compatible responses.
Tips
- Use one
containerID per conversation or task, and reuse it for every follow-up and Files API call. - Ask for deliverables in
/mnt/user-data/outputs/so they can be listed and downloaded. - Combine code execution with other tools, such as Web Fetch or Semantic Search, to bring data into the analysis.
- Delete uploads and outputs you no longer need: files stay in the container until you remove them.
Next steps
- Learn how messages return tool blocks: Messages
- Handle long-running turns: Handling stop reasons