System statusby Solari Status ↗

How to Run Untrusted Agent Code Safely: Sandboxes Explained

·

7 min read

·

Summarize with AI
ON THIS PAGE

Updated November 10, 2026

Code written by a model now runs minutes, sometimes seconds, after it is written, and model providers ship code execution as a built-in tool. Whatever that code does, it does with the access of the machine it runs on.

That makes isolation the first thing an agent team has to get right. The safe way to run agent code nobody has read is a sandbox per task: a disposable machine with its own kernel, no outbound network unless the task needs it and no long-lived keys inside, killed or rewound when the task ends. This guide covers why containers fall short, the habits that keep agent code contained, how to set them up on Solari, and where agent code execution is heading.

Why Is Agent-Written Code Unsafe to Run?

Agent-written code is unsafe because nobody reviews it and outside content can steer it. A person used to write a script, read it and then run it. Now a model writes the script and runs it straight away, and a prompt injection hidden in a web page or a file can change what it writes.

Mistakes need no attacker at all. Replit's coding agent deleted a production database during a code freeze, because the code it ran could reach production.

The fix is least privilege applied to a whole machine: agent code reaches only what its task needs, and nothing it can break outlives the task.

Why Isn't a Container Enough?

A container narrows what code can reach, but it does not give the code a machine of its own. Containers are OS-level virtualization: they share the host's kernel, so one kernel bug stands between the script and everything else on the host.

A sandbox built on a virtual machine moves that line. The code gets its own kernel behind a hypervisor, so an exploit has to escape a VM, not a namespace. A Solari sandbox is that kind of machine without a screen: it runs commands, keeps code state between calls, and can be snapshotted and forked.

How Do You Run Untrusted Agent Code Safely?

You run it in a machine that can reach nothing it doesn't need and that disappears afterwards. Six habits get you there:

  • One machine per task. One sandbox per task means one task's leftovers never become the next task's input. A steered script then damages a machine you were going to delete anyway.

  • A closed network. Code that cannot open an outbound connection cannot send your data anywhere. Open the network only for tasks that must call an API, and keep those tasks away from code nobody has read.

  • Fixed size and deadlines. Set CPU and memory at create time and give every command a deadline. A runaway loop then hits a limit you chose instead of running until someone notices.

  • Short-lived keys. A key inside the machine is readable by any code that runs there. Pass scoped, short-lived credentials to the one task that needs them, never long-lived account keys.

  • Ids and URLs as secrets. A sandbox's control address or a preview link lets whoever holds it reach the machine. Keep them out of logs, tickets, prompts and client-side code.

  • Kill or rewind. End the sandbox when the task finishes, or revert it to a clean snapshot when setup is slow. Either way the next task starts with nothing the last one left behind.

Which Isolation Tier Should You Pick?

Pick by how far you trust the code: hardened for code nobody has read, dedicated for code that must call an API, shared only for trusted jobs. Solari sets that wall with one create option, isolation.

Solari sandbox isolation tiers at a glance

The hardened tier is the same microVM as the default with all outbound network blocked, so a steered script has nowhere to send data. Use the dedicated tier when a task needs network storage or an outside API.

Shared sandboxes run as process trees in a VM shared only with your organization's other shared sandboxes, isolated by namespaces and a cgroup rather than a hypervisor. No tier ever puts two organizations on one VM. A shared sandbox's memory cap is a hard limit the code inside cannot see, so set worker counts explicitly instead of reading them from the machine.

How Do You Set Up a Safe Sandbox on Solari?

Three choices at create time do most of the work: the hardened tier, a fixed size and what happens when the sandbox sits idle. With the @solarisdk/sandbox package it reads like this:

import { SandboxClient } from "@solarisdk/sandbox"

const sandboxes = new SandboxClient({ apiKey: process.env.SOLARI_API_KEY! })
const sbx = await sandboxes.create({
  template: "base",
  isolation: "hardened",
  cpu: 2,
  memMb: 2048,
  lifecycle: { onTimeout: "kill" },
})
await sbx.connect()
await sbx.files.write("/work/task.py", agentCode)
const res = await sbx.commands.run("python3", { args: ["/work/task.py"] })
if (res.timedOut) throw new Error("agent code hit its deadline")
import { SandboxClient } from "@solarisdk/sandbox"

const sandboxes = new SandboxClient({ apiKey: process.env.SOLARI_API_KEY! })
const sbx = await sandboxes.create({
  template: "base",
  isolation: "hardened",
  cpu: 2,
  memMb: 2048,
  lifecycle: { onTimeout: "kill" },
})
await sbx.connect()
await sbx.files.write("/work/task.py", agentCode)
const res = await sbx.commands.run("python3", { args: ["/work/task.py"] })
if (res.timedOut) throw new Error("agent code hit its deadline")
import { SandboxClient } from "@solarisdk/sandbox"

const sandboxes = new SandboxClient({ apiKey: process.env.SOLARI_API_KEY! })
const sbx = await sandboxes.create({
  template: "base",
  isolation: "hardened",
  cpu: 2,
  memMb: 2048,
  lifecycle: { onTimeout: "kill" },
})
await sbx.connect()
await sbx.files.write("/work/task.py", agentCode)
const res = await sbx.commands.run("python3", { args: ["/work/task.py"] })
if (res.timedOut) throw new Error("agent code hit its deadline")

Size is a hard bound: a request above the limit is rejected, not quietly reduced. A command that passes its deadline returns timedOut instead of throwing, so check that flag before you trust the exit code. Setting onTimeout to kill ends an idle sandbox instead of pausing it.

Keys need one more rule. Solari passes git credentials as environment variables of the one command that uses them, never in the URL or the repo's config, so nothing stays behind on the machine. A snapshot saves the exact state of a running machine, so any other key in its memory or files lives on in every copy started from it. A preview URL carries a signed token that expires, and until then it works for whoever holds it.

What Role Does Solari Play?

Solari is the infrastructure agent code runs on: sandboxes, cloud browsers and desktops from one API. Your agent brings the code; Solari gives every task a machine of its own.

  • Fast starts. Solari sandboxes start in milliseconds, so you can give every task its own machine without making your agent wait. Your agent creates, runs and kills a sandbox for each piece of code it writes.

  • Its own kernel. Each Solari sandbox runs as a Cloud Hypervisor microVM with a dedicated kernel per session. Agent code has to escape a virtual machine before it can reach anything else you run.

  • Clean copies. Prepare a machine once, snapshot it, and start independent copies from that snapshot. revert() rewinds a machine to a snapshot under the same id, so the next task starts with no leftovers.

  • Pause and resume. Pause saves memory and processes, and resume brings the sandbox back exactly as it was, on the same VM lifecycle as Solari desktops. Use it for a long job you trust, never to keep unread code alive.

  • One account. The same account and API key run Solari cloud browsers and desktops, so your agent can read a page in a browser and run the code it writes about that page in a sandbox, on one bill. Introducing Solari covers all three.

Solari bills a sandbox by the vCPU-hour and GB-hour while it runs, so a machine per task costs you only the time it works. Solari runs a full sandbox lifecycle about 1.3x faster than E2B and is almost 3x cheaper per sandbox hour. Snapshot storage costs $0.05 per GB-month with the first 10 GB free, and deleting a snapshot stops its charges the same day.

Where Is Agent Code Execution Going Next?

Today most teams sandbox the obvious cases and trust the rest. Over the next year that changes in four ways:

  • A sandbox per tool call. As machines start in milliseconds, isolating each call becomes the default rather than the exception. Teams stop deciding which code deserves a sandbox.

  • Allowlists. A task that needs one API will reach that one domain and nothing else. Network rules will be written per task, not per account.

  • Screens in the same wall. Models with computer use already operate whole desktops, so the isolation rules that apply to a script will apply to a screen.

  • Replays as evidence. Teams will record sessions and keep the replay as proof of what an agent did, the way they keep logs today.

What stays human is the boundary itself: what an agent may touch, which keys it holds and what reaches production. The teams that draw that line well will let their agents run more code, not less, because a bad run costs them one disposable machine.

Get Started With Solari

Start with one job: send one generated script to a hardened sandbox and check timedOut before you trust its output. Solari is the fastest and cheapest way to run cloud browsers and VMs for coding agents. Get started with a free account and start running your agents today.

Share this article

Give every agent
a place to work

Browsers, sandboxes and desktops from one API. Start free and scale when you need to.

Planet horizon at sunrise
opsra logo

The Fastest AI Infrastructure

Unsubscribe anytime. See our Privacy Policy.

System status

Copyright © 2026 Solari

Engineered by Pinetree

opsra logo

The Fastest AI Infrastructure

Unsubscribe anytime. See our Privacy Policy.

System status

Copyright © 2026 Solari

Engineered by Pinetree

opsra logo

The Fastest AI Infrastructure

Unsubscribe anytime. See our Privacy Policy.

System status

Copyright © 2026 Solari

Engineered by Pinetree