LLMs are great at writing code and bad at doing math in their heads. Ask one how many primes there are below ten million, or for revenue per city in a 1,000-row CSV, and you'll get an answer that looks right. Nothing in it tells you whether it is.
The standard fix is a code interpreter: the model writes a program, something runs it, and the output goes back to the model. The awkward part is where that model-written code runs. You really don't want it on your app server, next to your credentials and your database.
We just shipped a Daytona component for ByteChef (an open-source workflow automation and AI agent platform) that solves exactly this. Here's how it works, two templates you can import, and what we learned building it.
The component in 30 seconds
One connection (a Daytona API key with only write:sandboxes and delete:sandboxes), four actions:
| Action | What it does | Output |
|---|---|---|
| Execute Code | Runs Python / TypeScript / JavaScript / Bash in a sandbox. Works as a workflow step and as an AI Agent tool. |
exitCode, stdout, success, sandboxId, charts
|
| Create Sandbox | Creates a sandbox and waits until it's running. | sandboxId |
| Upload File | Puts a file from an earlier step into the sandbox. | |
| Delete Sandbox | Cleans up. | deleted |
Execute Code takes language, code, an optional sandboxId, a keepSandbox flag and a timeout. Those give you two patterns:
-
Sandbox per call: leave
sandboxIdempty. Each call gets a fresh sandbox that's deleted afterwards. Nothing leaks between calls, nothing to clean up. -
Sandbox per run: Create → Upload → Execute (as many times as you like, pointing at that
sandboxId) → Delete. Files and installed packages persist across calls, so an agent can work in steps.
Let the model write the code, and nothing else
Any ByteChef action can be an agent tool. By default every input is fixed by you; an input only becomes part of the tool schema the model sees if you set it with fromAi. In both templates, code is the only model-controlled input:
=fromAi('code', 'STRING', {'description': 'Complete Python 3 program to run. Print every value you need; only printed output comes back.'})
Language, timeout, keepSandbox and sandboxId are pinned. That means:
- The model can't target some other sandbox your API key can reach.
- The model can't leave sandboxes running.
- The tool schema is a single string field, which is the easiest kind of tool for a model to call correctly.
That "only printed output comes back" line earns its place. Without it, models sometimes write notebook-style code where the last expression is the answer, compute the right value, and never print it.
Template 1: a code interpreter agent
One Manual trigger, one AI Agent (Anthropic model) with one tool (Run Python in Daytona), one log step. The system prompt is deliberately 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.
If you merely allow a tool, models skip it for anything that looks easy. If you require it for a whole class of work, they use it.
We asked: How many primes are there below 10,000,000, and what's their sum? Also give the 300th Fibonacci number and the SHA-256 of "ByteChef".
The agent made one tool call:
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())
Daytona returned:
count: 664579
sum: 3203324994356
F(300) (F(0)=0,F(1)=1): 222232244629420445529739893461909967206666939096499764990979600
sha256: adf4b0a32ca539981a1af25e095a9e22514a1e6506ba0c4363b559395bab0ac4
All four values check out independently (the hash matches printf ByteChef | sha256sum). The whole run took ~9 s; the tool call itself — create sandbox, wait for it, sieve ten million numbers, delete sandbox — was ~2.3 s.
Put this behind a chat trigger, a Slack command or an API endpoint and your team has a code interpreter that never runs code on your infrastructure.
Template 2: a weekly sales report in Slack
Something closer to real work. Every Monday at 08:00 UTC:
- HTTP GET a sales CSV (the template uses a public supermarket dataset: 1,000 invoices, Jan–Mar 2019)
- Create Sandbox (Python)
-
Upload File →
/home/daytona/sales.csv -
AI Agent with one tool,
Run Python in the sandbox - Delete Sandbox
- Post to Slack
The tool is the same Execute Code action, except sandboxId is pinned to ${daytona_1.sandboxId} — the output of the Create step. Every call the agent makes lands in the sandbox that holds the CSV. Because the sandbox ID is set, the tool never deletes it; the explicit Delete step does that once at the end.
A few prompt details that came straight out of failed test runs:
-
List the columns (and the date format) in the system prompt. Saves a round trip and stops pandas from guessing
M/D/YYYY. - "Start by loading the file and checking its shape." A cheap first call catches a missing file or wrong delimiter before the real analysis.
- Ask for Slack mrkdwn, not Markdown. Otherwise you get a beautiful Markdown table that arrives in Slack as a wall of pipes.
- "Reply with the report only." The whole answer goes to Slack. An early run opened with a (correct, useful) note that the data covered three months, not one week — which doesn't belong in the channel. Asking for the real date range in the title fixed both.
The agent made two tool calls: one to sanity-check the file (shape, dtypes, date parsing, nulls, duplicate invoice IDs), one to compute everything. Excerpt of the report:
*Sales Report: Jan 1 – Mar 30, 2019*
• Total revenue: *$322,966.75*
• Gross income: *$15,379.37* (4.76% margin)
• Naypyitaw: $110,568.71 (*34.2%*)
• Feb: $97,219.37 (*-16.4%* vs Jan)
• Mar: $109,455.51 (*+12.6%* vs Feb)
We recomputed every figure with a separate script and they all match to the cent — including the easy-to-fumble claims in its recommendations, like Yangon's February being the lowest of the nine city-months.
A rerun weeks later was instructive: the agent made three tool calls instead of two and chose different recommendations, but every total, share, count and monthly change was identical. The model varies in what it decides to look into; the numbers don't, because they come from code.
Timing: ~27 s end to end, of which ~22 s is the agent. Sandbox creation was ~1.5 s, upload ~2.2 s, delete ~0.4 s.
To adapt it: point the download step at your export (or Google Drive, S3, an email attachment…), update the column list, change the metrics in the user prompt, pick a Slack channel. Works just as well for support tickets, ad spend, usage logs or survey results.
Under the hood: talking to Daytona over REST
1. Create and wait. POST /sandbox with a label that picks the code runner's language:
{"labels": {"code-toolbox-language": "python"}}
The response comes back before the sandbox is ready, and code sent too early fails. So we poll GET /sandbox/{id} once a second until state is started, and bail on error, build_failed, or 60 s. In practice: 0.5–1.5 s.
2. Find the toolbox. Code runs through a toolbox API inside each sandbox, reached via a per-sandbox proxy — not the main API URL:
GET /sandbox/{id}/toolbox-proxy-url -> {"url": "https://..."}
The toolbox lives at {url}/{sandboxId}. We learned this the hard way: an early version called a toolbox path on the main API and got 404s from the live service. We now ask for the proxy URL on every call — one tiny extra request, and it survives Daytona moving its proxies.
3. Run.
POST {toolbox}/process/code-run
{"code": "...", "language": "python", "timeout": 120}
The response includes exit code, output and artifacts (matplotlib charts included). If the action created the sandbox and keepSandbox is off, it's deleted in a finally block, so failed runs clean up too.
4. Upload. Multipart to POST {toolbox}/files/upload-v2?path=/home/daytona/sales.csv.
Why not the official SDK?
Daytona has a Java SDK. We stuck with plain REST through ByteChef's own HTTP client because:
- Our client already handles connection auth consistently for every component; the SDK brings its own client and bypasses that.
- The SDK pulls in a cloud storage SDK, a websocket library and a second JSON library — a lot for four API calls.
- It's pre-1.0 and changes often; the REST surface we use is small and stable.
If we ever need interactive terminals or streaming file transfer, we'll revisit.
What the sandbox protects (and what it doesn't)
- ✅ Model-written code never runs on your ByteChef server. Infinite loops and
rm -rfonly hurt their own sandbox. - ✅ Use a dedicated, scoped, expiring API key. A leak is limited to sandboxes.
- ✅ Make
codethe onlyfromAiinput. Pin everything else. - ✅ Keep timeouts short.
- ⚠️ Uploaded files and data the model embeds in code leave your infrastructure. Self-host Daytona (set the Base URL) if that's a problem.
- ⚠️ In the per-run pattern, the Delete step only runs if the agent step succeeds. If your model provider is down, the sandbox stays. Add an error path or check the dashboard occasionally.
- ⚠️ Prompt injection still applies. If the prompt includes outside text (an email, a form), someone can steer the model into, say, printing the uploaded file into the answer. The sandbox limits damage to your systems, not data exposure — make sure output only goes where the input's author is allowed to see it.
Daytona vs. ByteChef's Script component
ByteChef already runs code via the Script component (GraalVM in-process, or an external task runner). The difference is who writes the code:
| Script component | Daytona component | |
|---|---|---|
| Who writes the code | You, in the editor (as an agent tool, the model only fills inputs) | Usually the model, at run time |
| Where it runs | GraalVM inside ByteChef, or a task runner | Isolated Daytona sandbox |
| Packages | Whatever the runtime provides | Full Linux sandbox; pandas etc. available |
| Start-up cost | None | ~0.5–1.5 s |
| Best for | Small, known transformations; fixed-job tools | Code you didn't write; real data analysis |
Code you wrote and reviewed → Script. Code the model wrote, or jobs that need a real environment → Daytona.
Try it
Import the Answer questions with a code interpreter agent template and ask it the primes question — then ask the same model without the tool and compare. Then import Analyze sales data in a Daytona sandbox and post a weekly report to Slack, point it at your own export, and let it post its first report.
ByteChef is open source: github.com/bytechefhq/bytechef. The full write-up, with more screenshots, is on the ByteChef blog.
Questions about the component or the REST integration? Drop them in the comments.



Top comments (0)