Your AI Agent Can't Count Primes. A Daytona Sandbox Can.

On this page
TL;DR: The new Daytona component gives ByteChef workflows and AI agents a safe place to run code. Its Execute Code action works as an AI Agent tool: the model writes a Python, TypeScript, JavaScript or Bash program, Daytona runs it in an isolated sandbox, and the printed output goes back to the model. By default, each call gets a new sandbox that is deleted when the call finishes. For longer jobs you can create a sandbox, upload files into it, let the agent work in it, and delete it at the end. Two templates show both patterns: Answer questions with a code interpreter agent and Analyze sales data in a Daytona sandbox and post a weekly report to Slack. We ran both end to end against the real Daytona API, and every number in this post was checked against the source data.
Language models are good at writing code and bad at doing arithmetic in their heads. Ask a model how many prime numbers there are below ten million and it gives you a number that looks plausible. Ask it for the revenue of each city in a CSV with a thousand rows and it gives you a table that looks plausible. Neither answer is computed. Both can be wrong, and nothing in the answer tells you so.
The usual fix is a code interpreter: let the model write a program, run the program, and give the output back to the model. The model turns the question into code, which it is good at, and the computer runs that code exactly, which the model can't do.
The hard question is where the code runs. The code was written by a model, sometimes from text a user or an email sent in. You don't want it running on your ByteChef server, next to your credentials and your database.
Daytona answers that question. It runs code in isolated sandboxes, created on demand, which are ready in about a second and are deleted when you are done. The new Daytona component brings those sandboxes into ByteChef.
Four Actions and Two Sandbox Lifetimes
The component has one connection and four actions.
The connection takes a Daytona API key and a Base URL. The base URL defaults to https://app.daytona.io/api; change it only if you run a self-hosted Daytona. To create the key, open the Keys page in the Daytona dashboard, click Create Key, and give it the write:sandboxes and delete:sandboxes permissions. Those two are all the component needs.
The actions:
| Action | What it does | Output |
|---|---|---|
| Execute Code | Runs code in a sandbox and returns its output. Works as a workflow step and as an AI Agent tool. | exitCode, stdout, success, sandboxId, charts |
| Create Sandbox | Creates a sandbox for a language (Python, TypeScript, JavaScript or Bash) and waits until it is running. | sandboxId |
| Upload File | Uploads a file from an earlier step to a path inside a sandbox. | |
| Delete Sandbox | Deletes a sandbox and frees its resources. | deleted |
Execute Code is the core of the component. It takes four inputs besides the code:
- Language:
python,typescript,javascriptorbash. - Sandbox ID: optional. Leave it empty and the action creates a new sandbox for this call. Set it, and the action runs the code in that existing sandbox, so files and installed packages from earlier calls are still there. A sandbox you pass in is never deleted by this action.
- Keep Sandbox: when the action creates the sandbox itself, keep it after the call instead of deleting it. The output contains the
sandboxId, so a later step can reuse it. - Timeout: the longest the code may run, in seconds.
The output tells you whether the code worked (exitCode and success), what it printed (stdout), which sandbox it ran in (sandboxId), and any charts it drew with matplotlib (charts).
Two ways to use a sandbox
These inputs give you two patterns, and the templates below use one each.
One sandbox per call. Leave Sandbox ID empty and Keep Sandbox off. Every call starts clean and leaves nothing behind. This is the right default for a general code interpreter: one call cannot see what another call did, and there is nothing to clean up.
One sandbox per run. Create a sandbox with Create Sandbox, put files into it with Upload File, point Execute Code at it with its Sandbox ID, and remove it with Delete Sandbox at the end. This is the right pattern when the code needs data, or when an agent works in several steps and each step builds on the last.
Execute Code as an Agent Tool
Every ByteChef action can be a tool for an AI Agent. You drop it into the agent's Tools slot, and the model can call it. What matters is which inputs the model fills in and which ones you fix.
By default, every input of a tool is fixed: you set it in the editor, and the model never sees it. To let the model fill in an input, set its value with fromAi. In both templates, Code is the only input the model controls:
=fromAi('code', 'STRING', {'description': 'Complete Python 3 program to run. Print every value you need; only printed output comes back.'})Only fromAi inputs become part of the tool's schema that the model sees. Here that schema has a single string field, code, with that description. Language is fixed to python, Timeout to 120 seconds, and Keep Sandbox and Sandbox ID are set by you, not by the model.
This is a deliberate choice, and it is worth copying in your own workflows:
- The model cannot pick the sandbox. If Sandbox ID were a
fromAiinput, the model could, in principle, run code in any sandbox your API key can reach. Pinning it means the model only ever touches the sandbox you gave it, or a new one. - The model cannot keep sandboxes alive. Keep Sandbox is fixed, so a model that misreads its instructions cannot leave a trail of running sandboxes behind.
- The schema is small. One field with a clear description is the easiest tool for a model to call correctly.
The description matters more than it looks. "Only printed output comes back" tells the model that a bare expression on the last line, which works in a notebook, returns nothing here. Without that sentence, models sometimes write code that computes the right value and then never prints it.
Template 1: A Code Interpreter Agent
The Answer questions with a code interpreter agent template is the smallest useful setup: one agent, one model, one tool.

The workflow has a Manual trigger with one input, Question, and two steps:
- Code interpreter agent is an AI Agent with an Anthropic model and one tool, Run Python in Daytona. That tool is Execute Code with the settings described above: Python, a 120-second timeout, no sandbox ID and Keep Sandbox off, so each call runs in a new sandbox.
- Log the answer writes the agent's answer to the execution log.
The system prompt is short and strict:
You are a precise analyst with a code interpreter. Never do arithmetic, counting, hashing or data processing in your head: write a short Python 3 program and run it with the Run Python in Daytona tool, then answer from the printed output. If the code fails, read the error, fix the code and run it again. In the final answer, give each result clearly, and add a short note on how you computed it.The important phrase is never do it in your head. Models are confident by default. If you only allow a tool, the model often skips it for anything that looks easy. If you require the tool for a whole class of work, the model uses it.
A test run
We asked it a question that no model can answer from memory with any confidence:
How many prime numbers are there below 10,000,000, and what is their sum? Also give the 300th Fibonacci number and the SHA-256 hash of the text ByteChef.
The agent made one tool call. This is the program it wrote:
import hashlib
N = 10_000_000
sieve = bytearray([1]) * N
sieve[0] = sieve[1] = 0
for i in range(2, int(N**0.5) + 1):
if sieve[i]:
sieve[i*i::i] = bytearray(len(range(i*i, N, i)))
primes = [i for i in range(N) if sieve[i]]
print("count:", len(primes))
print("sum:", sum(primes))
def fib(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
print("F(300) (F(0)=0,F(1)=1):", fib(300))
print("sha256:", hashlib.sha256("ByteChef".encode("utf-8")).hexdigest())It is a sensible program. It uses a sieve of Eratosthenes on a byte array, Python's arbitrary-precision integers for the Fibonacci number, and hashlib for the hash. It prints every result, as the tool description asked. You can see the call in the run's task list, as a child of the agent step:

Daytona returned:
count: 664579
sum: 3203324994356
F(300) (F(0)=0,F(1)=1): 222232244629420445529739893461909967206666939096499764990979600
sha256: adf4b0a32ca539981a1af25e095a9e22514a1e6506ba0c4363b559395bab0ac4The agent then wrote its answer from that output:

We checked every value independently. There are 664,579 primes below ten million, and their sum is 3,203,324,994,356. F(300) is correct with the usual indexing, where F(0) = 0 and F(1) = 1, and the agent said which indexing it used. The hash matches printf ByteChef | sha256sum.
The whole run took about 9 seconds. The tool call took about 2.3 seconds of that, and the call covers creating the sandbox, waiting for it to start, running a sieve over ten million numbers, and deleting the sandbox. The rest is the model thinking and writing.
What it is good for
Anything where a wrong number costs more than an extra two seconds:
- Calculations: loan schedules, unit conversions, statistics, date arithmetic across time zones.
- Text and data work: counting, sorting, deduplicating, parsing a block of JSON or CSV pasted into the question.
- Checks: hashes, checksums, regular expressions tested against real input.
Put this agent behind a chat trigger, a Slack command or an API endpoint, and you have a code interpreter your whole team can use. The code never runs on your server.
Template 2: A Weekly Sales Report
The second template is closer to real work. Every Monday morning, it downloads a sales export, has an agent analyze it with pandas, and posts a short report to Slack. Every number in the report comes from code.

The steps:
- Every Monday at 8:00: a weekly schedule trigger (UTC).
- Download the sales CSV: an HTTP GET that returns the file as binary. The template uses a public sample dataset of supermarket sales (1,000 invoices from January to March 2019). Point it at your own export.
- Create a sandbox: a new Python sandbox for this run.
- Upload the CSV to the sandbox: puts the downloaded file at
/home/daytona/sales.csv. - Sales analyst agent: an AI Agent with one tool, Run Python in the sandbox.
- Delete the sandbox: removes the sandbox once the report is written.
- Post the report to Slack: sends the agent's answer to a channel.
Pinning the tool to the run's sandbox
The tool is the same Execute Code action as in the first template, with one difference: its Sandbox ID is set to the output of the Create a sandbox step.

Code comes from the model, through fromAi. Sandbox ID is ${daytona_1.sandboxId}, a reference to an earlier step that the model cannot change. Every call the agent makes runs in the sandbox that holds the CSV, and only in that sandbox. Because the sandbox ID is set, the tool never deletes it after a call; the explicit Delete the sandbox step does that, once, at the end.
This is also why the agent can work in several steps. Files and Python packages stay in the sandbox between calls. If the agent saves an intermediate result in its first call, the second call can read it.
The prompts
The system prompt tells the agent where the data is, what the columns are, and how to work:
You are a retail sales analyst. The sales data is a CSV file at /home/daytona/sales.csv inside your sandbox. Columns: Invoice ID, Branch, City, Customer type, Gender, Product line, Unit price, Quantity, Tax 5%, Total, Date (M/D/YYYY), Time, Payment, Cost of goods sold, Gross margin percentage, Gross income, Customer stratification rating.
Use the Run Python in the sandbox tool for every number you report. pandas is available. Start by loading the file and checking its shape. If code fails, fix it and run it again. Never estimate a number you did not compute.
Write the report for a Slack channel, in Slack mrkdwn (*bold*, bullet lists with •, no Markdown tables, no headings with #). Keep it under 250 words. Reply with the report only, with no preamble or closing remarks.A few choices in this prompt came from test runs:
- The column list. It saves the agent a round trip, and it tells the agent the date format, which pandas would otherwise have to guess.
- "Start by loading the file and checking its shape." A cheap first call catches a missing file or a wrong delimiter before the agent writes the real analysis.
- Slack mrkdwn, not Markdown. Slack does not render Markdown tables or
#headings. Without this rule the agent writes a nice Markdown table that arrives in Slack as a wall of pipes. - "Reply with the report only." The agent's whole answer goes to Slack. In an early run, the agent opened with a sentence explaining that the data covered three months, not one week. That was true and useful, but it does not belong in the channel. Asking for the report only, and asking for the real date range in the title (in the user prompt below), fixed both.
The user prompt lists what the report must contain:
Write the sales report for the period the file covers, and put that date range in the title. Include: total revenue and gross income; revenue by city with each city's share; the best and worst product line by revenue; the most used payment method; revenue by month with the change from month to month; and two concrete, data-backed recommendations.The result
The agent made two tool calls. The first loaded the file and printed its shape, its column types and the first rows, and checked that every date parsed, that no values were missing and that no invoice ID appeared twice. The second computed everything in one program: totals, groupings by city, product line, payment method and month, and a few extra breakdowns to support the recommendations. Then it wrote the report:
*Sales Report: Jan 1 – Mar 30, 2019*
*Headline* (1,000 transactions)
• Total revenue: *$322,966.75*
• Gross income: *$15,379.37* (4.76% margin)
*Revenue by city*
• Naypyitaw: $110,568.71 (*34.2%*)
• Yangon: $106,200.37 (*32.9%*)
• Mandalay: $106,197.67 (*32.9%*)
*Product lines*
• Best: *Food and beverages*, $56,144.84
• Worst: *Health and beauty*, $49,193.74
*Payment*
• Most used: *Ewallet* (345 transactions), narrowly ahead of Cash (344) and Credit card (311)
*Revenue by month*
• Jan: $116,291.87
• Feb: $97,219.37 (*-16.4%* vs Jan)
• Mar: $109,455.51 (*+12.6%* vs Feb)
*Recommendations*
• *Fix the February dip in Home and lifestyle and Sports and travel.* Home and lifestyle fell from $20,494.74 in Jan to $12,434.38 in Feb, then rebounded to $20,932.79 in Mar. Sports and travel fell from $21,667.02 to $13,809.61, then rebounded to $19,646.19. A February promotion or bundle on these two lines could recover part of the gap.
• *Lift Health and beauty and Yangon.* Health and beauty is the weakest line overall, though it grew to $18,208.31 in March, so a push on it could build on that. Yangon dropped to $29,860.12 in Feb, the lowest of any city-month, and had the largest drop of the three cities from January. Targeted campaigns there would help.We recomputed every figure from the CSV with a separate script, and all of them match, down to the cent: the totals, the city shares, the product lines, the payment counts, the monthly changes, and the numbers behind the recommendations. That includes the claims that are easy to get wrong: that February in Yangon ($29,860.12) is the lowest of the nine city-months, and that Yangon's drop from January ($8,821) is larger than Naypyitaw's ($7,500) and Mandalay's ($2,752).
The first recommendation is the useful one. The agent did not just restate the totals; it went looking for where February lost revenue and found that two product lines account for most of it. The second is weaker: two observations stitched together with a generic suggestion, which is about what you can expect from a 250-word limit. Both are backed by numbers you can check.
Running the template again a few weeks later shows where the model varies. The agent made three tool calls instead of two and picked different recommendations: Health and beauty's low transaction count, and Yangon's February drop. Every total, city share, payment count and monthly change in the report was identical to the cent. The model varies in what it decides to look into, but the numbers come from the same code over the same file.

The run took about 27 seconds: about 0.4 seconds to download the file, 1.5 seconds to create the sandbox and wait for it to start, 2.2 seconds to upload the file, 22 seconds for the agent (two tool calls plus the writing), and 0.4 seconds to delete the sandbox. In an earlier run of the same workflow the Slack post took another 0.3 seconds.
Make it yours
To run the template on your own data:
- Point Download the sales CSV at your export. Any URL that returns the file works, and so does any step that produces a file, such as Google Drive, an S3 bucket or an email attachment.
- Update the column list in the agent's system prompt.
- Change the user prompt to the metrics your team cares about.
- Pick your Slack channel in Post the report to Slack, then deploy the workflow.
The same shape works for much more than sales: support ticket exports, ad spend, usage logs, survey results. Anything that arrives as a file and needs real analysis before a human reads it.
How the Component Talks to Daytona
This section is for readers who want to know what happens on each call, or who will build their own components against Daytona.

Creating a sandbox and waiting for it
Create Sandbox sends POST /sandbox with a label that tells Daytona which language runtime the sandbox's code runner should use:
{"labels": {"code-toolbox-language": "python"}}Daytona answers immediately, but the sandbox is not ready yet. Its state starts out as something like creating and becomes started a moment later. Code sent before that fails. So the component polls GET /sandbox/{id} once a second until the state is started. It stops with a clear error if the state becomes error or build_failed, or if the sandbox has not started after 60 seconds. In our runs, creating a sandbox and waiting for it took between half a second and a second and a half.
Finding the toolbox
Code runs through Daytona's toolbox, a small API that runs inside each sandbox. The toolbox is not served from the main API URL. Each sandbox has a toolbox proxy, and the component asks for its address first:
GET /sandbox/{id}/toolbox-proxy-url -> {"url": "https://..."}The toolbox for the sandbox is then at {url}/{sandboxId}. We learned this the hard way: an earlier version of the component called a toolbox path on the main API, which returned 404 against the live service. The fix was to ask for the proxy URL on every call. It costs one extra small request and keeps the component working if Daytona moves its proxies.
Running code
With the toolbox URL, running code is one request:
POST {toolbox}/process/code-run
{"code": "...", "language": "python", "timeout": 120}The response holds the exit code, the output and any artifacts, including matplotlib charts. The component turns this into its output: exitCode, stdout, success (true when the exit code is 0), sandboxId and charts.
When the action created the sandbox itself and Keep Sandbox is off, it deletes the sandbox in a finally block, so a failed run still cleans up.
Uploading a file
Upload File sends the file as a multipart form to:
POST {toolbox}/files/upload-v2?path=/home/daytona/sales.csvThe file comes from any earlier step that produces a file. In the template it is the HTTP step's binary response.
Why REST and not the Daytona SDK
Daytona publishes official SDKs, including one for Java. We looked at it closely and decided to stay with plain REST calls through ByteChef's own HTTP client, for three reasons:
- ByteChef's HTTP client does real work. It applies the connection's authentication and handles requests the same way for every component, which keeps Daytona consistent with the rest of the platform. The SDK brings its own HTTP client and goes around all of that.
- Dependencies. The SDK pulls in a cloud storage SDK, a websocket library and a second JSON library. That is a lot to add to a server for four API calls.
- Pace of change. The SDK is still pre-1.0 and ships new versions often. The REST API the component uses is small and stable.
If Daytona adds features that are hard to use over plain REST, such as interactive terminals or streaming file transfer, we will look at the SDK again.
Sandboxing AI-Generated Code: What Daytona Protects and What It Doesn't
A code interpreter is only as safe as the place the code runs. Here is what the component gives you and what is still up to you.
The code never runs on your ByteChef server. It runs in a Daytona sandbox, on Daytona's infrastructure (or on yours, if you self-host Daytona and set the Base URL). A program that deletes files, eats memory or loops forever hurts only its own sandbox.
Use a narrow API key. Create a key just for ByteChef with only write:sandboxes and delete:sandboxes, and give it an expiry date. If the key leaks, the damage is limited to sandboxes.
Fix everything except the code. As described above, make Code the only fromAi input. Fix the language, the timeout and Keep Sandbox, and when you pin a sandbox, set Sandbox ID from a workflow step, not from the model.
Keep timeouts short. The 120 seconds in the templates is generous for analysis on a small file. A model that writes an infinite loop will waste at most that much time.
Remember where your data goes. Files you upload and data the model puts into its code leave your infrastructure and go to Daytona. For customer data, check that this fits your policies, or run Daytona yourself.
Watch for leftover sandboxes. In the per-call pattern, sandboxes are always deleted, even when the code fails. In the per-run pattern, the Delete the sandbox step runs only if the agent step succeeds. If the agent fails, for example because the model provider is down, the run stops and the sandbox stays. Check the Daytona dashboard now and then, or set up an error path that deletes it.
Treat input as untrusted. If the agent's prompt includes text from outside, such as an email or a form, someone can try to steer the model into writing code that does something else. The sandbox limits what that code can do to your systems. It does not stop the code from, say, reading the uploaded file and printing it into the answer. Design the workflow so the output only goes where the input's author is allowed to see it.
Daytona or the Script Component?
ByteChef already runs code: the Script component runs Bash, JavaScript and Python, either in the GraalVM engine inside the ByteChef server or, for Script actions, in an external task runner. It also offers Python and JavaScript AI Agent tools. The difference is who writes the code. A Script tool runs a perform function you wrote in the editor, and the model only passes it arguments. The Daytona tool runs whatever program the model writes.
| Script component | Daytona component | |
|---|---|---|
| Who writes the code | You, in the editor; as an agent tool, the model only fills in its inputs | Usually the model, at run time |
| Where it runs | The GraalVM engine inside ByteChef, or an external task runner for Script actions | In an isolated Daytona sandbox |
| Packages | What the runtime provides | A full Linux sandbox; pandas and other common Python packages are available |
| Start-up cost | None | About half a second to a second and a half to create a sandbox |
| Best for | Small, known transformations and agent tools with a fixed job | Code you did not write and data analysis that needs real libraries |
Use the Script component for code you wrote and reviewed, including agent tools with a fixed job. Use Daytona when the code itself comes from the model, or when the job needs a full environment.
Try the Templates
Start with the code interpreter template and ask it the primes question from the top of this post, then ask the same model without the tool and compare the answers. Then import the weekly sales report template, point it at your own export, and let it post its first report. The component reference lists every property and output.
Subscribe to the ByteChef Newsletter
Get the latest guides on complex automation, AI agents, and visual workflow best practices delivered to your inbox.


