Building an agent for your own team is one risk profile. Building a product where your customers' agents run code is another. Now the untrusted code belongs to customer A, the data next to it belongs to customer B, and the person who will ask "could A have seen our data?" is B's security team, in a questionnaire, with your name on the answer.
This post is a design for that situation. It is vendor-neutral, with notes on where a hosted sandbox covers a layer.
The threat model in one paragraph
Assume any run can be hostile. A customer's agent can be prompt-injected by a web page, a repository or a document it reads, and then it runs whatever the attacker wrote. The attacker's goals are, in order of how much they would hurt you: read another tenant's data, use your credentials, use your infrastructure (mining, spam, attacks on third parties), and deny service to other tenants. Every layer below exists to make one of those fail.
Layer 1: a kernel per run
Containers on a shared kernel put every tenant one kernel bug away from every other. For your own trusted code that is a reasonable trade; for a multi-tenant product running arbitrary code, it is the line customers' security teams will draw. Give each run its own kernel: a microVM, or at minimum a user-space kernel such as gVisor. Our isolation pillar compares the options.
Then never reuse a box across tenants. Not after a "cleanup", not from a warm pool that has run code before. A fresh box per run per tenant is the only answer that is easy to defend.
Layer 2: identity that flows from authentication
The mapping from request to sandbox must come from the authenticated tenant, not from anything the client sends. If the sandbox ID or name is in a URL parameter, someone will try another tenant's. Derive it server-side, and check on every call that the sandbox belongs to the caller's tenant.
Put the tenant on the sandbox as a label at creation, so every record downstream (logs, audit, billing) carries it without extra joins.
Layer 3: per-tenant credentials, scoped and short-lived
Your platform's own credentials must never enter a customer's run. If the run needs to call your API on the customer's behalf, mint a token scoped to that tenant, that task, and the shortest lifetime that works. If it needs the customer's own secrets, fetch them for that run only and make them expire when the run ends.
Remember that anything inside the box can be read by the code in the box. A credential in an environment variable is readable by the run it was given to. That is acceptable only if the credential is worth little outside that run.
Layer 4: per-tenant network policy
Default to no network. Open only what the task needs, per tenant: their package registry mirror, their API, a short allowlist. Never allow runs to reach your internal network or cloud metadata endpoints. Think about DNS, which leaks data through lookups even when HTTP is blocked; see DNS exfiltration.
Also decide what your runs may do to the rest of the internet. A hostile run with open egress is an attack platform with your IP addresses.
Layer 5: noisy neighbours
One tenant's runaway job should not slow everyone else.
- Per-run limits: vCPU, memory, disk and a lifetime on every box.
- Per-tenant concurrency: a cap on boxes at once for each tenant, enforced before creation, with a queue behind it. See concurrency limits and queueing.
- Per-tenant budgets: compute and model spend, with alerts. See spend caps for AI agents.
Layer 6: records a customer can trust
Customers will ask what happened in their runs, and auditors will ask how you know. For each run, keep: tenant, user, the agent and model, template and size, commands with exit codes, network destinations allowed and refused, secrets granted (names, never values), and who approved anything that needed approval. Make the log tamper-evident, for example hash-chained, so "we didn't edit it" is checkable. See what an audit log for coding agents should record.
Layer 7: a way to stop
Have a per-tenant stop and a global stop, both rehearsed. When a tenant's agent is doing something harmful, you want to halt that tenant's runs in one action, without touching anyone else's. See kill switch for AI agents.
What a hosted sandbox covers
With Sandscale as the execution layer:
- Layer 1: each run is its own Firecracker microVM with its own kernel, and a pooled sandbox has never run anyone's code before you claim it.
- Layer 2: labels on each sandbox carry your tenant ID; projects (Team and up) separate work further.
- Layer 3: Vault hands a run its secrets in memory, keeps values out of prompts, logs and the API's answer, and ends them with the run; API keys have scopes and expiry.
-
Layer 4: sandboxes start with the network off;
allowlistmode uses your organization's egress allowlist and registry presets. - Layer 5: per-box size and lifetime on create, plan limits on boxes at once, and spend caps per task, agent, project and organization on paid plans.
- Layer 6: a hash-chained audit log on every plan, with export on Team and up.
Layers 2, 5 and 7 still need logic in your product, because only you know who your tenants are. And one honest note for your own questionnaire: Sandscale claims no certification, and our service levels page says there is no availability commitment yet. The audit export is there to support your own assessment, not to replace it.
Originally published on the Sandscale blog.
Top comments (0)