TheDocumentation Index
Fetch the complete documentation index at: https://docs.ubik-agent.com/llms.txt
Use this file to discover all available pages before exploring further.
code_execution (or code_interpreter) tool provides agents with a secure, sandboxed Python environment. This allows them to go beyond text generation and perform computational tasks, data analysis, and visualization by writing and executing real code.
It is designed to be iterative: the agent can write code, see the output (or errors), and then refine its code in a loop until the task is complete.
When to Use This Tool
Usecode_execution when you need to:
- Analyze Data: Process CSVs, Excel files, or JSON data to find insights.
- Visualize Information: Create charts, graphs, and plots using libraries like
matplotliborseaborn. - Perform Math: Solve complex algebraic equations or financial calculations accurately.
- Transform Files: Convert data formats or clean up messy datasets.
Security & IsolationEvery execution runs in a completely isolated, ephemeral sandbox. The environment cannot access your local filesystem, ensuring complete safety. Files must be explicitly passed into the sandbox via
document_ids to be available in the sandbox.Input Parameters
The tool accepts the following parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
request | string | Yes | A natural language description of what you want the code to do (e.g., “Plot the sales trend from this CSV”). |
document_ids | array<uuid> | No | A list of Document UUIDs representing files (CSVs, images, etc.) that the code needs to access. These files will be uploaded to the sandbox. |
context | string | No | Additional context or constraints (e.g., “Use a dark theme for the plot”). |
sandbox_id | string | No | The ID of an existing sandbox session to resume. If omitted, a new session is started. |
Output Structure
The tool returns a structured object containing the execution results, logs, and any generated artifacts.| Field | Description |
|---|---|
sandbox_id | The ID of the session. Pass this back in subsequent calls to keep the state (variables, defined functions, etc.) alive. |
logs | A complete transcript of the code executed, standard output (print statements), and standard errors. It includes markers for each execution round. |
generated_files | References to data files created by the code (e.g., modified CSVs). |
artifacts | References to visual assets created by the code (e.g., PNG plots). |
plan | The step-by-step plan the agent formulated to solve the request. |
execution_id | The unique identifier for this tool execution. |
Example Usage
Scenario: analyzing Sales Data
Input:- Plan: Create a multi-step plan (Load data -> Group by region -> Plot).
- Execute: Write Python code using
pandasto read the CSV (uploaded to/home/uploaded_files/). - Visualize: Use
matplotlibto create the chart and save it as an image. - Return: The final response will include the calculated numbers in the
logsand the chart in theartifactsarray.
How It Works
- Planning: The agent first breaks down your
requestinto a logical, step-by-step coding plan. - Iterative Coding: It executes the plan one step at a time.
- It writes code for Step 1.
- It runs the code in the sandbox.
- It observes the output (stdout/stderr).
- If there’s an error, it self-corrects and retries.
- State Persistence: Variables and dataframes defined in Step 1 are available in Step 2, allowing for complex, multi-stage workflows.
- Finalization: Once all steps are complete, it packages the logs, files, and images into the final response.

