How to Run AI Coding Agents in Isolated Sandboxes
AI coding agents need more than model access. Each task needs an isolated execution environment, temporary permissions, controlled external access, and a clear cleanup path.
Make the decision visible before the workflow makes it permanent.
Inside this Insight
What the article follows
Written by
The agent can edit the repository. The execution boundary decides how much damage a bad run can do.
If an AI coding agent can edit your repository and execute commands, it should not run directly inside the same environment that operates your main product. Give each agent task its own isolated sandbox, short-lived access, defined network and service boundaries, and a clear end to the session.
For a founder, that is the difference between adding an AI feature that can write code and building a product that can safely let AI act. The agent may fix a bug, run tests, prepare a pull request, inspect a failure, or change files, but the surrounding software still has to control where it runs, what it can access, what happens when it fails, and what is allowed to survive afterward.
A sandbox is simply a separate execution environment created for that task. The agent can work inside it without automatically receiving access to the rest of the product infrastructure. When the job finishes, the application keeps the intended result, such as a patch, commit, test result, or review artifact, and removes the temporary execution environment.
A September 3, 2026 release from Vercel provides a useful current example of this architecture. Cursor Cloud Agents can now use Vercel Sandbox as their execution environment. Cursor keeps the agent harness and inference loop, while each request can receive an isolated Firecracker microVM. Vercel Functions and Vercel Workflow sit around the worker for provisioning, monitoring, retries, and cleanup.
That release is the current trigger, but the engineering question is broader than either vendor. Once an AI coding agent is allowed to execute commands, isolation, credentials, network access, retries, persistence, verification, and teardown become part of the product design.
Start by separating the agent loop from the execution environment
The model or agent loop decides what to do next. The execution environment is where those decisions become filesystem changes, shell commands, package installs, tests, browser actions, and calls to other systems. Keeping those responsibilities separate gives the application a place to enforce controls outside model-generated instructions.
That separation is visible in the new Cursor and Vercel integration. Cursor manages the agent harness and inference loop, while Vercel Sandbox supplies the machine where repository and command execution happens. The control plane sits around the worker instead of living inside the prompt.
A production design does not have to use those exact products, but it should preserve the boundary. The agent can request an action. Infrastructure decides which environment receives it, which identity is attached, which destinations are reachable, how long the worker may run, and what happens when the task finishes.
Keep orchestration, execution, and durable product state in separate zones.
The agent should be able to work inside a capable environment without becoming the authority that defines its own permissions or persistence.
Own the task and policy
- Task ID and user identity
- Repository and branch scope
- Execution policy and timeout
- Retry and cancellation state
Run untrusted commands
- Dedicated filesystem and process space
- Short-lived credentials
- Restricted network access
- Logs and command results
Accept only intentional outputs
- Commit or patch
- Test and verification results
- Review artifacts
- Audit and task outcome
Give every run a clear isolation boundary
A sandbox limits the blast radius of code the agent did not fully understand before executing. Vercel describes each Sandbox as an isolated Firecracker microVM with its own filesystem, network, and process space. Cursor likewise documents per-agent VM isolation for its hosted Cloud Agents.
Isolation matters because repositories are not passive text. A package install can execute lifecycle scripts. A test suite can start subprocesses or connect to services. A browser test can submit forms. A generated script can consume CPU, write large files, or call an external endpoint. The safest default is to assume that code execution deserves its own boundary even when the repository itself is trusted.
The sandbox does not solve every risk by itself. If the worker receives a production database credential and unrestricted outbound network access, strong VM isolation still leaves the agent with powerful capabilities inside that VM. Infrastructure controls have to work together.
A useful sandbox boundary has to cover more than the filesystem.
Think about what the run can read, what it can call, and what authority it can carry beyond the machine itself.
Compute and filesystem
Identity and secrets
Network and services
Decision point
Short-lived credentials should follow the user and task
Coding agents often need more than repository access. Tests may call a staging API, read from object storage, connect to a cloud account, or query a development database. Giving every agent the same long-lived secret is simple, but it makes the execution boundary much weaker.
The September 3 Vercel architecture specifically calls out short-lived, user-scoped credentials inside each Sandbox. Cursor's current Cloud Agent documentation also supports OIDC tokens so an agent can obtain temporary identity without storing long-lived cloud keys in the environment. Its repository access model is designed so an agent inherits the triggering user's repository permissions rather than expanding them.
The design principle is broader than OIDC. Credentials should answer four questions before they enter the worker: who started this task, what resource does the task need, what actions are allowed, and when should the authority expire? If the answer is simply "everything this team can access," the credential scope is too broad for an autonomous executor.
Temporary task identity is easier to contain than a shared static secret.
Both approaches can make a test pass. They create very different failure consequences when the agent follows a bad instruction or the repository executes unexpected code.
The worker receives standing authority
Scope
Lifetime
Failure consequence
The worker receives temporary authority
Scope
Lifetime
Failure consequence
What this means
Retries belong in the control plane, not inside an endless agent loop
A long-running agent task can fail before the model produces a useful result. The worker may fail to start, repository cloning may fail, dependency installation may time out, a package registry may be unavailable, tests may fail, the model may stop, or the worker may reach its execution limit.
Vercel's reference architecture puts durable retries around the sandbox worker. That is the right direction because the product needs to know which stage failed and whether repeating that stage is safe. A retry should be a state transition owned by orchestration, not an instruction to "try everything again" without context.
This becomes especially important when the run can create side effects outside the sandbox. Opening a pull request, pushing a branch, applying a migration, posting a comment, or triggering a deployment should not happen twice because an infrastructure retry replayed an earlier step.
Track the agent task as a stateful job around a disposable worker.
The exact implementation can vary, but the product should know which stage it is in, which steps are repeatable, and which outputs have already crossed into durable systems.
Accept and scope the task
Create the isolated worker
Execute and verify
Export the intended result
Stop and clean up
Route principle
Make the task idempotent before you make the worker retryable
A retryable worker is only useful when the product can distinguish repeatable work from consequential work. Cloning the same repository into a fresh sandbox is normally easy to repeat. Creating a second pull request or running a database migration may not be.
Give each agent task a stable job ID and attach idempotency to external actions. If a run has already pushed agent/task-1842, a replacement worker should be able to discover that state instead of blindly creating another branch. If the product needs to post a review artifact, record whether that artifact already exists before the retry begins.
The same principle applies to approvals. A worker can prepare a deployment or migration, but the authorization to perform that action should remain outside the sandbox when the consequence is high. Isolation limits execution. Approval boundaries limit what an automated run can commit to durable systems.
A sandbox needs an explicit end
Short-lived execution is useful only when the lifecycle is actually closed. Vercel Sandbox has a default session timeout, and its documentation recommends stopping a sandbox promptly instead of waiting for the timeout to clean up idle resources.
The application should therefore treat cleanup as part of the task contract. A success path stops the worker after exporting its result. A failure path still stops it after capturing diagnostics. A cancellation path should revoke or let temporary credentials expire and prevent new commands from entering the worker.
A minimal lifecycle wrapper can make that rule visible in code:
Stop the worker in `finally`, even when the command fails.
This example shows the execution lifecycle, not a complete coding-agent implementation. Authentication, network rules, repository policy, and external side effects still need their own controls.
import { Sandbox } from "@vercel/sandbox"; type CommandResult = {exitCode: number;stdout: string;stderr: string;}; export async function runIsolatedCommand(): Promise<CommandResult> {const sandbox = await Sandbox.create({ persistent: false, timeout: 10 * 60 * 1000,}); try {const result = await sandbox.runCommand("npm", ["test"]); return { exitCode: result.exitCode, stdout: await result.stdout(), stderr: await result.stderr(), }; } finally {await sandbox.stop();}}Decide what is allowed to survive the run
Not every agent task should start from an empty machine, and not every task should preserve its entire workspace. The useful distinction is between execution state and durable output.
Execution state includes cloned repositories, installed packages, caches, temporary credentials, local logs, and processes that only exist to complete the run. Durable output is the result the product intentionally wants to keep: a commit, patch, test report, screenshot, build artifact, review summary, or task audit record.
Persistent sandboxes and snapshots can be useful for large repositories or follow-up sessions, but persistence changes the threat and cleanup model. Old files, cached credentials, build outputs, and environment assumptions can survive into a later run. Use persistence because the product needs continuity, not because cleanup was omitted.
Keep execution temporary by default, then preserve only the state the next task actually needs.
A faster resume can be valuable, but the application should know exactly what crosses the boundary between runs.
Fresh worker for each task
Benefits
Cost
Resume from approved state
Benefits
Control required
What this means
When should execution stay inside your own perimeter?
Hosted agent sandboxes are convenient when the repository and required services can safely run in that environment. Some teams have a different boundary: policy may require code execution to stay on company-managed infrastructure, a critical service may be unreachable from the hosted environment, or the task may require special hardware or persistent local storage.
Cursor's current runtime guidance uses those conditions to separate its hosted Cloud Agents from Self-Hosted Machines. The broader decision is useful for any agent platform. Choose the execution location from policy and dependency constraints, not from a general preference for "more control."
A self-hosted worker also transfers more operational responsibility back to the team. Host patching, worker updates, VM resets, capacity, secret distribution, network access, monitoring, and incident response become part of the system you own. The location may satisfy a perimeter requirement while increasing the reliability work around the agent fleet.
Keep the worker hosted unless a concrete requirement moves it inside your infrastructure.
The correct boundary depends on what must remain private, what the agent must reach, and what infrastructure the team is prepared to operate.
Perimeter requirement
Private dependency reach
Special compute or storage
Decision point
Production checklist for an AI coding-agent sandbox
The execution layer is ready when the team can explain both the happy path and the failure path without relying on the model to remember a safety rule. The product should know which identity started the task, where the code ran, which resources were reachable, what was changed, what was verified, and how the worker ended.
Use the checklist below as an architecture review rather than a provider-specific requirement.
Check the boundaries before giving the agent broader execution access.
Start with the smallest authority that lets the agent complete the task, then expand only when a concrete workflow requires more.
One task has one traceable owner
Execution is isolated per run or agent
Credentials are short-lived and scoped
Network access matches the task
External writes are idempotent
Verification is captured before cleanup
Persistence is intentional
Cleanup runs on success, failure, timeout, and cancellation
Before moving on
The durable lesson is the boundary around the agent
The September 3 Cursor and Vercel integration is one implementation of a pattern that will matter across coding-agent products: autonomous code execution needs an infrastructure contract around it.
A useful agent needs enough freedom to install, run, test, and inspect. A dependable product keeps that freedom inside an isolated worker, gives the worker temporary and narrow authority, treats retries as explicit job states, preserves only intended outputs, and closes the execution environment when the work is over.
That design does not make every generated command safe. It makes the consequence of a bad command easier to contain, observe, and recover from. As coding agents gain more ability to act, those boundaries become part of the product architecture rather than an infrastructure detail added later.
References used for this Insight
Sources support the factual basis of the article. Product interpretation and frameworks are presented separately as Ascent's analysis.
- 01Source
Vercel
Official sourceSep 3, 2026Cursor Cloud Agents can now run in Vercel Sandbox
Primary source for the new integration, the split between Cursor's agent loop and Vercel execution, per-request Firecracker sandboxes, durable retries, cleanup, and short-lived user-scoped credentials.
- 02Source
Vercel
DocumentationChecked Sep 5, 2026Vercel Sandbox
Current product documentation for isolated microVM execution, supported runtimes, session duration, exposed ports, and observability.
- 03Source
Vercel
Official sourceJan 30, 2026Run untrusted code with Vercel Sandbox, now generally available
Background on the microVM execution model, isolated filesystem/network/process space, ephemeral agent workloads, and snapshots.
- 04Source
Cursor
DocumentationChecked Sep 5, 2026Cloud Agents
Current documentation for isolated cloud-agent environments, repository execution, secrets, network controls, and environment setup.
- 05Source
Cursor
DocumentationChecked Sep 5, 2026Cloud Agent security overview
Source for per-agent VM isolation, repository access boundaries, runtime data handling, and current security model.
- 06Source
Cursor
DocumentationChecked Sep 5, 2026OIDC tokens for Cloud Agents
Source for short-lived OIDC identity that can replace stored long-lived cloud credentials in supported workflows.
- 07Source
Cursor
DocumentationChecked Sep 5, 2026Choose where Cloud Agents run
Source for the hosted versus self-hosted decision conditions around perimeter policy, private dependencies, hardware, storage, and operational ownership.
Source links support the facts they are attached to. They do not imply that the source publisher endorses Ascent's interpretation or recommendations.
