Table of Contents
- What belongs inside an LLM sandbox?
- Define the execution contract before generating code
- Move one data job through the sandbox
- Keep credentials and network access out of the calculation
- Choose the runtime around the calculation
- Treat timeouts and retries as separate decisions
- Validate artifacts before showing them to a customer
- Budget compute, retained files and model calls separately
- LLM sandbox questions
- Does the language model run inside the sandbox?
- Can a sandbox make model-generated answers correct?
- Should every job get a new sandbox?
- What should we build first?
Do not index
Do not index
An LLM sandbox is an isolated environment where code written by a language model can run against selected files and produce results. The model proposes the code; your application controls execution. Agent37 provides the remote compute, file access and lifecycle controls for this pattern, with standard gVisor sandboxes and full VMs.
The useful output might be a cleaned CSV, a chart or a calculated total. Getting that file back reliably takes more than giving the model a Python tool. You need a clear boundary around inputs, credentials, runtime and outputs.
This guide follows one example: a customer uploads sales data and asks for a monthly summary. The architecture and checks below are recommendations, not a benchmark or a claim that we ran this example. Documentation was checked on October 29, 2026.
What belongs inside an LLM sandbox?
The term also names the open-source Python package `llm-sandbox`. Its documentation lists Docker, Kubernetes and Podman backends. That library is one way to manage code execution; this guide describes the broader application design, including a remote worker you control through an API.
Keep the model call and job coordinator in your application. Put the generated program and the files it needs inside the sandbox. The coordinator authenticates the customer, selects the input, starts execution and decides which results may leave.
For the sales report, the model might write Python that reads a CSV, checks its columns, groups revenue by month and saves a table plus an image. It does not need your production database password, the sandbox provisioning key or another customer's workspace.
Component | Responsibility | What it should receive |
Application | Authorization, job tracking and model calls | Customer identity and narrowly selected data |
Model | Propose code and explain results | Task, schema and an appropriate data sample |
Sandbox | Execute the program | Approved input files and prepared dependencies |
Result handler | Validate and deliver artifacts | Expected files, execution status and bounded logs |
This separates permission to calculate from permission to act elsewhere. A job that summarizes an export should not also acquire permission to email customers or update invoices.
Frameworks can connect these pieces. LangChain documents sandbox backends with filesystem tools and shell execution. Our LangChain sandbox guide covers that specific integration; the design here also works with your own coordinator. See the official backend documentation.
Define the execution contract before generating code
A prompt is an instruction to the model. An execution contract is the set of checks your application enforces regardless of what the model produces.
Start with one job type. For a monthly sales report, decide the accepted input columns, maximum upload size, output formats and failure behavior before exposing the feature to customers.
Contract item | Example decision | Enforced by |
Ownership | This customer owns this upload and job | Application authorization |
Input | One CSV with date, currency and amount columns | Upload and schema validation |
Dependencies | A prepared Python environment | Reviewed runtime template |
Network | No outbound access during calculation | Sandbox network policy |
Duration | An explicit wall-clock limit | Process supervision and job watchdog |
Output | One summary CSV and one PNG within size limits | Artifact validator |
Retention | Delete the job environment after export | Lifecycle cleanup |
These are example choices, not Agent37 defaults. Your workload may need different limits. Record them with the job so a retry uses the same contract instead of silently expanding access.
A fixed contract also makes errors useful. Report a missing currency column as an input problem. Do not let repeated model attempts invent exchange rates to make the report appear complete.
Move one data job through the sandbox
Use a job identifier generated by your backend. Store the customer-to-job-to-sandbox mapping outside the sandbox, where generated code cannot rewrite its ownership.
First, validate the upload before execution. Check size, encoding and expected structure. Select only the required columns when the original file contains unrelated information. Decide whether the model needs row contents at all; column names and a synthetic example may be enough to draft the transformation.
Next, prepare the runtime. Install reviewed dependencies in a template or preparation step. Avoid letting every generated program choose fresh packages from the internet while it can access customer data.
Upload the input and generated script as files. Do not interpolate uploaded filenames or code into a shell command assembled from untrusted text. Your launcher should use backend-controlled paths and a deliberate quoting strategy.
Agent37's file API accepts raw file bytes through
PUT /v1/files/content and streams downloads through GET /v1/files/content. Those operations are separate from command execution. Keep the API key in your backend.Run the program, record its status, then collect only expected outputs. A useful result record includes the job identifier, input checksum, script checksum, runtime version and artifact names. You can then explain which data and program produced a report without retaining every input forever.
Finally, mark delivery complete only after the authorized customer can retrieve the validated artifacts. A process exiting successfully is an intermediate event, not the entire product workflow.
Keep credentials and network access out of the calculation
Assume generated code can inspect anything available to its process. Hiding a token in an environment variable does not hide it from that code. A separate sandbox protects the application only if you avoid copying the application's privileges into it.
If the report needs data from a protected service, let your trusted backend retrieve an authorized export. Give the worker the export instead of a broadly privileged service token. Keep actions such as sending mail or changing records behind separate application checks.
This matters even when the customer request looks harmless. Uploaded documents and retrieved content can influence the model. LangChain's security guidance for sandboxes warns that isolation does not prevent context injection or protect credentials placed inside the environment.
Network access is another explicit choice. Agent37 instances allow outbound internet access by default. For an offline CSV calculation, prepare dependencies, then apply
network: "deny-all" before running untrusted code. Confirm that the policy is active. Under the network API, a successful 200 confirms enforcement; a 503 try_again requires a follow-up confirmation.That policy restricts outbound traffic. It does not switch off the authenticated exec and file interfaces used by your backend. If the calculation genuinely needs outside data, review the narrow access it requires instead of assuming an isolated machine has no internet connection.
Choose the runtime around the calculation
A Python reporting job needs its interpreter, libraries, enough memory for the dataset and an appropriate isolation boundary. It usually does not need to run a Docker daemon inside its workspace.
gVisor supplies an application kernel between the workload and the host. It is a different architecture from a full VM and from an ordinary container sharing the host kernel directly. The gVisor architecture guide explains that distinction.
On Agent37, standard gVisor instances cannot run a Docker daemon. Full VMs have their own Linux kernel and support Docker workloads, at a separate compute rate. Choose a VM when your actual dependency or toolchain needs it, then verify compatibility with a representative job. See the VM reference.
That distinction matters if you choose the
llm-sandbox package's Docker backend: hosting its Docker daemon inside an Agent37 worker calls for a VM, not a standard instance.For analytics, memory may become the first constraint. A small compressed upload can expand substantially during parsing, joins or chart generation. Test the largest supported input and reject jobs beyond the contract rather than relying on the model to estimate memory.
Our microVM versus container guide covers the broader runtime decision. No isolation choice proves that a generated calculation is correct.
Treat timeouts and retries as separate decisions
A timeout can mean your application stopped waiting. It does not necessarily mean the program stopped running.
Agent37 explicitly documents this distinction: an exec request can time out while its command continues inside the instance. Blindly sending the same request again starts another copy. A nonzero command exit can also arrive inside an HTTP
200, so inspect exit_code, not just the HTTP status. These behaviors are documented in the exec reference.Put the job deadline in a supervisor that can terminate the process and its children. Have an external watchdog reconcile jobs whose coordinator disappeared. For a dedicated disposable worker, stopping the instance is one recovery option after deciding what evidence to preserve.
Before retrying, inspect the recorded job state. Distinguish a failed launch, a still-running process, a failed calculation and a completed job whose response was lost. Each deserves a different response.
Bound model repair attempts too. One rejected column should not create unlimited generations, repeated package installs and several overlapping calculations. Log why a retry was allowed and what changed.
Validate artifacts before showing them to a customer
Treat outputs as untrusted even when the process exits with code zero. The runtime boundary controls execution; it does not verify the meaning of a chart or the safety of a file.
For a CSV summary, check the expected columns and types. Reconcile totals against an independently computed control total. Verify the date range, currency handling and row count. A convincing chart can still omit refunds or combine different currencies.
For downloads, accept only the artifact paths your contract permits. Check actual file type and size. Handle links and path traversal deliberately instead of accepting whatever path the generated program prints. Keep another customer's job directory out of the result handler's reach.
Prefer a validated PNG for a simple chart. If a task produces HTML or SVG, do not insert it into your product page as trusted markup. Agent37's file delivery guidance calls out active-content risks and recommends isolated rendering or an attachment download for untrusted files.
Send the model a bounded, structured result for its explanation. Keep raw logs and file contents out of prompts unless needed. The final answer should identify missing data or failed checks instead of smoothing them over.
Budget compute, retained files and model calls separately
An LLM sandbox bill has at least three parts: the machine, retained storage and the model calls coordinating the work. Retry loops and external tools can add more.
For Agent37 standard compute, a 2 vCPU, 4 GB RAM instance has a $4.40 compute rate per 730 running hours. Four GB of retained disk adds $0.36 per 730 hours. Using those published rates gives these illustrative infrastructure estimates:
One standard instance | Compute | Retained disk | Total |
Runs for 10 hours, then is deleted | $0.0603 | $0.0049 for 10 hours | About $0.065 |
Runs for 10 hours, disk retained for 730 hours | $0.0603 | $0.36 | About $0.42 |
Runs for all 730 hours | $4.40 | $0.36 | $4.76 |
These are calculations, not subscriptions or performance measurements. They exclude model tokens, tools and other services. Agent37 meters by the minute; awake idle time still bills compute. The billing reference specifies the rates and states.
Use explicit cleanup for one-off jobs. For a continuing analysis session, retain only the workspace that should survive, and stop or sleep between runs. Auto-sleep must be enabled; it is not a universal default. Review auto-sleep behavior before relying on its activity timer for long calculations.
Compare your own running hours and retention policy on the Agent37 pricing page.
LLM sandbox questions
Does the language model run inside the sandbox?
It can, but this design keeps model requests in the application and runs only generated code in the worker. That keeps model credentials outside the untrusted process and makes an offline calculation possible.
Can a sandbox make model-generated answers correct?
No. It lets the program execute within a chosen boundary. You still need input validation, independent checks and a clear way to reject an incomplete or incorrect result.
Should every job get a new sandbox?
A fresh worker is a useful default for unrelated customer jobs. Reuse can help a continuing analysis preserve files, but requires deliberate ownership, cleanup and retention. A new folder alone is not a separate machine boundary.
What should we build first?
Start with one input format and one output type. Prove authorization, cancellation, output validation and cleanup with representative data before adding more tools. When that contract is clear, explore Agent37 sandboxes and connect the chosen runtime to your existing application.
