Urgent.News

What's breaking now, across hundreds of outlets.

Tech

One sandbox per run, per session or per user: isolation, cost and state trade-offs

When you put an agent's code execution in a sandbox, you also decide, often without noticing, how many pieces of work share each sandbox. One per tool call? One per conversation? One per user, kept for days? The choice sets your isolation story more than the sandbox technology does. A microVM shared by two users is a shared environment, whatever kernel it runs. This post compares the three common…

When an agent's code is executed in a sandbox, the decision on how many tasks share each sandbox determines the level of isolation, cost, and state trade-offs. There are three common granularities: per run, per session, and per user.

Per run means every task or tool call gets a fresh sandbox from a template, which is stopped when the task ends. This provides the strongest isolation, as nothing from one run can affect another, including runs by the same user. However, this approach requires paying for the setup each time, as state is not carried over. If setup is needed, it's more cost-effective to start each run from a snapshot taken after setup.

The failure mode here is the repeated expense of setup and the inconvenience of agents expecting state, which they won't find.

Per session involves giving each conversation or agent task one sandbox, which is kept across its turns and stopped when the session ends. Isolation between users and sessions is good, but not between turns of the same session. This means that if a malicious instruction occurs during a turn, it may leave behind something that runs in subsequent turns.

The cost while waiting depends on the platform's billing model. If billed per provisioned resources while running, idle sessions cost as much as busy ones. Pausing or setting aggressive timeouts can reduce idle session costs without extra work. However, sessions that never end can be problematic, so giving each session sandbox a lifetime and a sweep that stops idle sessions is recommended.

Per user grants each user a long-lived environment, such as a workspace or persistent sandbox that survives across sessions and days. Isolation between users is maintained, but within one user's history, none exists. Every session sees what every earlier session left behind, including any malicious code planted by an attacker. State persists, including installed tools, history, and configuration.

Cost while waiting is the highest exposure due to the environment existing for days. Idle behaviour or short-lived certificates can help control costs. Failure modes include drift and accumulation of secrets, like old tokens in shell history or credentials in configuration files. Treating a per-user environment like a laptop, with hygiene and rotation, is essential.

The most important rule is never to share a sandbox across users. Cloudflare's sandbox security documentation emphasizes that a sandbox is the smallest unit of trust, and when two users share a sandbox, each user's code can read the other's work. This rule applies to every platform. If the mapping from user to sandbox comes from a request's name or ID, derive it from the authenticated identity, not from anything the client sends.

Real systems often use two sandboxes: one for per-session state and another for riskier commands, ensuring that each sandbox maintains its security boundaries.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Locking out tomorrow's quantum hackers

LETTERS: Imagine a thief attempting to steal a locked safe today, knowing full well he cannot open it yet, simply because of the wait for a master key currently being built in a laboratory.

Cardmarket Scraper in Python: Every Card in a Set, Price Trends and Offers Past Cloudflare

Cardmarket is Europe's biggest marketplace for Magic: The Gathering, Pokémon, Yu-Gi-Oh! and other trading cards. Every set has a page listing each card with its rarity, the number of copies for sale…

  • Cardmarket provides data for Magic: The Gathering, Pokémon, Yu-Gi-Oh! cards.
  • Cloudflare blocks direct HTTP requests, causing 403 errors.
  • Scrape.do proxies requests, but may return 502 errors requiring retries.

See the HTTP requests your script makes, without changing it

My morning brief script found only 2 stories on my topics yesterday. The day before, it found 4. Was the API's answer different, or is my filter wrong? How do you find out?

  • cmdbook captures HTTP requests without altering scripts
  • Shows method, URL, and status code for each request
  • Supports curl, wget, Python libraries, and standard utilities

More from Thursday 26 November →