Blank white background with no objects or features visible.

Ask TFY: Debug, Analyze, and Act on Everything Happening Inside Your AI Gateway Learn More

TrueFoundryはSeldon AIの買収を発表し、エンタープライズAI向けコントロールプレーンを拡張します。プレスリリース全文はこちら→

Sandboxed Code Agents: Let Models Execute Without Letting Them Roam

By Boyu Wang

Published: August 17, 2026

Giving an AI model code execution is one of the highest-leverage upgrades you can make. Instead of reading 100,000 rows into context, the agent can write code that computes over them. Instead of asking a model to mentally transform files, it can run a parser. Instead of returning a vague suggestion, it can build an artifact and test it.

It is also the moment an AI system stops being “just text.” Code can read files, open sockets, consume CPU, fork processes, inspect environment variables, and mutate whatever the runtime can reach. The correct production pattern is not “trust the model more.” It is give the model a smaller computer.

Operating Principle and Key Takeaways
The operating principle: autonomy should expand inside an isolated workspace before it expands into real infrastructure.

Key Takeaways

  • A sandbox is a capability boundary. The important question is not whether code runs in a container; it is what filesystem, network, secrets, time, CPU, and tools the environment can access.
  • Ephemeral by default is safer. Preserve only explicit artifacts and state that need to survive the run.
  • Code mode is also context engineering. Let programs compute over bulky data instead of injecting the entire dataset into the model window.
  • Tool access and sandbox access are different. A sandboxed process should not automatically inherit production MCP credentials.
  • Consequential egress needs a gate. Creating a file in a sandbox is different from deploying it, emailing it, or writing it into a system of record.
  • TrueFoundry Agent Harness supplies the runtime isolation; MCP Gateway and guardrails govern external actions; Agent Registry and traces supply identity and evidence.

1. The Sandbox Boundary

agent
ephemeral workspace
  ├─ filesystem: scoped
  ├─ CPU / memory: bounded
  ├─ runtime: code + shell
  ├─ network: deny / allowlist
  ├─ secrets: none by default
  └─ artifacts: explicit export
     governed tool boundary
   approval / policy
   external side effect
TrueFoundry Agent Harness architecture
Official TrueFoundry Agent Harness architecture. The sandbox is one runtime component around the agent loop, alongside governed tools, approvals, and traces.

Filesystem

Give the run a workspace, not the host filesystem. Mount only necessary inputs and make sensitive host paths unreachable. Artifact export should be explicit so “the agent created a file” does not mean “the agent can write anywhere.”

Network

Network access should be treated as a capability. Many analysis tasks need no outbound network at all. Others may need an allowlist. Broad egress turns arbitrary code execution into a data-exfiltration path.

Secrets

Do not inject long-lived provider or business credentials into the sandbox environment by default. If the agent needs an external capability, prefer a governed tool that authenticates outside the sandbox and exposes only the narrow operation required.

Time and resources

Set wall-clock, CPU, memory, process, and output-size limits. Without them, an accidental infinite loop or unbounded data expansion becomes an infrastructure incident instead of a failed agent step.

Artifact handoff

Separate creation from consequence. The sandbox can produce a patch, report, image, SQL file, or deployment plan. A later policy/approval step decides whether that artifact is published or applied.

Safe Defaults Table
Action Safe default Why
Parse local CSV Allow in sandbox Contained computation
Install arbitrary package Restrict/allowlist Supply-chain + network risk
Read host secrets Deny Credential exfiltration
Call production API Use governed MCP tool Identity + policy + audit
Deploy generated code Approval + external tool Consequential side effect

Threat-model the sandbox by capability

“Sandboxed” is not a binary property. Enumerate the capabilities the process receives: read/write paths, outbound destinations, package installation, subprocess creation, kernel features, environment variables, mounted credentials, and maximum runtime. The security posture is the intersection of those capabilities, not the container label.

For example, a workspace with no host mounts but unrestricted internet and cloud credentials can still exfiltrate data or mutate infrastructure. A workspace with no network but a writable production volume can still cause damage. The useful design artifact is a capability matrix that shows exactly what each class of agent job may do.

Prefer artifact promotion over direct mutation

Many useful code-agent tasks do not require live production access. Let the agent create a patch, notebook, report, migration plan, deployment manifest, or transformed dataset in the sandbox. Then promote that artifact through a separate reviewed path. This creates a natural checkpoint where deterministic tests, policy, and human review can run before consequence.

The pattern is especially strong for software work: generate patch → run tests in sandbox → emit diff and test evidence → approve → apply through a controlled repository or deployment tool. The agent gets rich autonomy over computation without receiving equivalent autonomy over production.

Package installation is code execution too

An agent that can freely install packages can execute arbitrary third-party install scripts and expand its network surface. Production sandboxes should use curated base images, pinned dependency sets, allowlisted package sources, or an explicit package-install policy. The convenience of “pip install whatever you need” is appropriate for some low-risk ephemeral work, but it should be a conscious choice.

Capture enough evidence to reproduce the run

Store the sandbox image/runtime version, input artifact identifiers, executed commands or code cells, exit statuses, produced artifact hashes, and any governed external calls. Full byte-for-byte replay may not always be practical, but an operator should be able to explain what ran and which outputs crossed the sandbox boundary.

2. Where TrueFoundry Fits: Sandbox Inside the Harness, Authority Outside It

TrueFoundry's Agent Harness treats sandboxed execution as part of the runtime around the model, alongside context management, approvals, tool execution, and tracing. That makes code execution useful for both automation and context control: bulky intermediate data can be processed in the workspace rather than copied through repeated model turns.

External actions remain better expressed through the MCP Gateway, where tool credentials, access control, pre/post guardrails, and approvals are centralized. Agent Registry supplies the identity/owner context around the agent, and end-to-end traces correlate sandbox work with model and tool steps.

TrueFoundry Agent Registry
Official TrueFoundry Agent Registry view. Sandboxed execution still needs an accountable agent identity, owner, and defined access posture.

The architectural point is separation: the sandbox is where the agent may compute; the gateway is where the agent earns authority to affect other systems.

The Sandbox Audit Note
The sandbox audit. What filesystem can agent code see? What network destinations can it reach? Which environment variables and secrets exist inside the process? Are package installs unrestricted? What resource/time ceilings exist? Which artifacts survive run teardown? Can code directly reach production APIs, or must it cross a governed tool boundary? What action turns a sandbox artifact into a real-world side effect, and who authorizes it? If “it runs in Docker” is the entire threat model, the isolation design is unfinished.

3. Boundaries, Stated Plainly

A sandbox reduces blast radius; it does not make arbitrary code trustworthy. Kernel/container escapes, dependency risk, excessive privileges, and network exposure still matter. High-assurance environments may require stronger isolation than a standard container.

Also, not every agent needs code execution. Adding a shell to a workflow that only calls three well-defined APIs increases attack surface without adding much capability. Use the smallest execution surface that solves the problem.

References

Sandboxing is a defense-in-depth control, not a guarantee of safety. Isolation strength should match the sensitivity of the code, data, network, and downstream systems involved.

Try now.

One gateway for all your models, MCP servers, and agents.
No credit card needed.

Start free
Table of Contents

One Gateway for Every LLM, Agent and MCP Server

Book a 30-min with our AI expert

Book a Demo

The fastest way to build, govern and scale your AI

Book Demo
Summarize with
ChatGPT logo by OpenAI
Perplexity AI logo
Blurry red snowflake on white background, symmetrical frosty design with soft edges and abstract shape.

Discover More

No items found.
August 17, 2026
|
5 min read

Sandboxed Code Agents: Let Models Execute Without Letting Them Roam

No items found.
Portkey AI Gateway Pricing
August 15, 2026
|
5 min read

2026年版 Portkey AI Gateway 料金:完全ガイドと比較

No items found.
MCP registry connecting agents to governed MCP servers
August 15, 2026
|
5 min read

2026年版 最高のMCPレジストリ:開発者と企業向け比較

No items found.
TrueFoundry AI gateway powers enterprise AI platform engineering at scale
August 15, 2026
|
5 min read

AIプラットフォームエンジニアリングとは?エンタープライズチームのための実践ガイド

No items found.
No items found.

Recent Blogs

Black left pointing arrow symbol on white background, directional indicator.
Black left pointing arrow symbol on white background, directional indicator.
Take a quick product tour
Start Product Tour
Product Tour