Introduction
AI agents are increasingly expected to do more than generate text. They may inspect files, execute code, run tests, call utilities, transform data, and interact with application environments.
That creates an important infrastructure question:
Where should an agent execute its work?
Running agent workloads directly inside the application process is simple, but it creates security and isolation concerns. Running every task inside a dedicated sandbox provides stronger boundaries, but introduces startup and resource overhead.
Hosted agent environments are designed to address this problem by providing an execution environment where agent workloads can run with controlled isolation.
For engineering teams, however, security is only one part of the decision. A production system also needs to understand the performance characteristics of that isolation.
The most important questions are:
How long does a sandbox take to become ready?
How much latency does startup add?
Does a warm environment behave differently from a cold environment?
How much memory and CPU does isolation consume?
How does startup overhead affect short-lived tasks?
Does stronger isolation reduce throughput?
How does concurrency change the results?
This article explains how to benchmark sandbox startup and isolation overhead for hosted AI agents and how to interpret the results without confusing infrastructure overhead with model performance.
What Is a Hosted Agent Environment?
A hosted agent environment can be thought of as a controlled execution boundary around an agent workload.
Conceptually:
User Request
|
v
Agent
|
v
Hosted Execution Environment
|
+--> Files
+--> Tools
+--> Commands
+--> Runtime
+--> Network Policy
|
v
Task ResultInstead of executing potentially risky operations directly inside the primary application process, the workload runs inside an isolated environment.
The exact implementation can vary, but the architectural goal is generally the same:
Agent Workload
|
v
Isolation Boundary
|
v
Controlled ExecutionThis separation is particularly useful when an agent needs to execute code or interact with resources that should not have unrestricted access to the host application.
Why Startup Overhead Matters
Sandboxing introduces infrastructure work before the actual task begins.
A simplified lifecycle looks like this:
Request
|
v
Allocate Environment
|
v
Initialize Runtime
|
v
Prepare Workspace
|
v
Load Required Resources
|
v
Environment Ready
|
v
Agent TaskFor a long-running task, an additional 1–2 seconds of startup may be insignificant.
For a short task, it can dominate the total response time.
Consider an illustrative example:
Task Execution: 2 seconds
Sandbox Startup: 1 second
Total: 3 secondsStartup represents one-third of the total elapsed time.
For another workload:
Task Execution: 60 seconds
Sandbox Startup: 1 second
Total: 61 secondsThe same startup overhead is now much less significant.
Therefore, sandbox overhead should always be evaluated relative to task duration.
Cold Start vs Warm Start
The first benchmark distinction should be between cold and warm execution.
Cold Start
A cold start means the execution environment is not already available.
Request
|
v
Create Environment
|
v
Initialize
|
v
Execute TaskThis represents the highest startup overhead.
Warm Start
A warm environment can reduce initialization work.
Existing Environment
|
v
Execute TaskA benchmark that mixes cold and warm executions without recording the state can produce misleading averages.
Always classify each execution.
Benchmark Lifecycle Phases
Instead of measuring only total latency, break the execution into phases.
T0
|
+--> Environment Allocation
|
+--> Runtime Initialization
|
+--> Workspace Preparation
|
+--> Tool Initialization
|
+--> Agent Execution
|
+--> Cleanup
|
T1A useful metric model is:
Total Time =
Startup Time
+ Initialization Time
+ Agent Execution Time
+ Cleanup TimeThis decomposition helps identify the actual source of latency.
Core Benchmark Metrics
At minimum, record:
| Metric | Description |
|---|---|
| Cold startup | Time to create a fresh environment |
| Warm startup | Time to reuse an available environment |
| Ready latency | Time until execution can begin |
| Task latency | Time spent executing the task |
| Total latency | End-to-end duration |
| CPU usage | CPU consumed during execution |
| Memory usage | Memory footprint |
| Failure rate | Failed environment/task starts |
| Cleanup time | Time required to release resources |
For production analysis, also capture:
P50
P95
P99
Maximum observed latency
Average startup time alone is not sufficient.
Why Percentiles Matter
Suppose 100 sandbox starts produce:
Average: 900 ms
P50: 700 ms
P95: 1.8 s
P99: 4.5 sThe average looks reasonable.
However, 1% of requests taking several seconds may be significant for an interactive agent.
This is why infrastructure benchmarks should focus heavily on tail latency.
Designing a Controlled Benchmark
The benchmark should use repeatable tasks.
For example:
Task A:
Read a small file and return its contents.
Task B:
Search several files and summarize matching code.
Task C:
Modify a file and run a small test.
Task D:
Build a medium-sized .NET project.
Task E:
Run a complete test suite.These tasks represent different execution durations.
The benchmark should execute each task under controlled conditions.
Establish a Baseline
Before measuring hosted sandbox performance, measure the same workload without the sandbox boundary where it is safe and technically appropriate.
For example:
Baseline
Application
|
v
Task
Hosted
Application
|
v
Sandbox
|
v
TaskThe baseline gives you an estimate of the infrastructure overhead.
The comparison should not be interpreted as a recommendation to remove isolation. The purpose is to quantify what the isolation boundary costs.
Calculate Isolation Overhead
A simple measurement is:
Isolation Overhead =
Hosted Execution Time
-
Baseline Execution TimeYou can also calculate relative overhead:
Relative Overhead =
(Hosted - Baseline)
-------------------
Baseline
× 100For example, using illustrative values:
Baseline: 2.0 seconds
Hosted: 2.5 seconds
Overhead:
0.5 seconds
Relative:
25%The absolute and relative measurements tell different stories.
Benchmark Harness in .NET
A simple C# model can capture the important measurements.
public sealed record SandboxBenchmarkResult(
string TaskId,
string ExecutionMode,
bool ColdStart,
long StartupMs,
long ExecutionMs,
long CleanupMs,
long TotalMs,
long PeakMemoryBytes,
bool Succeeded);The benchmark runner can then execute multiple samples and aggregate them.
var grouped = results
.GroupBy(x => new
{
x.TaskId,
x.ExecutionMode,
x.ColdStart
})
.Select(group => new
{
group.Key.TaskId,
group.Key.ExecutionMode,
group.Key.ColdStart,
Samples = group.Count(),
AverageStartupMs = group.Average(x => x.StartupMs),
AverageExecutionMs = group.Average(x => x.ExecutionMs),
AverageTotalMs = group.Average(x => x.TotalMs),
SuccessRate = group.Average(x => x.Succeeded ? 1.0 : 0.0)
});This provides a useful starting point for comparing execution modes.
Measuring Startup Precisely
Do not measure startup from the wrong point.
For example:
Wrong:
Request received -> final response
Better:
Environment creation -> environment readyThe benchmark should define clear timestamps:
var allocationStart = Stopwatch.GetTimestamp();
await AllocateEnvironmentAsync();
var environmentReady = Stopwatch.GetTimestamp();
await ExecuteTaskAsync();
var taskCompleted = Stopwatch.GetTimestamp();Then calculate separate durations.
This prevents model execution time from being accidentally included in the startup metric.
Task Duration Matters
Consider two tasks:
Task A
Startup: 1.0s
Execution: 0.5s
Total: 1.5sand:
Task B
Startup: 1.0s
Execution: 30s
Total: 31sThe same infrastructure overhead has dramatically different significance.
A good benchmark should therefore report:

Join the conversation! Your thoughts help the community grow.