Skip to content
Product Decision

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.

Cloud and OperationsAI Coding AgentsSandbox Isolation
Continue to the analysis
Control point

Make the decision visible before the workflow makes it permanent.

Inside this Insight

What the article follows

1Rules
2Review
3Release
Cloud and Operations

Written by

Shruti SaraswatAscent Innovate Software
Published
Cloud and Operations
Agent execution

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.

Execution boundary

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.

Control plane01

Own the task and policy

Accept the job, bind it to a user and repository, choose the execution policy, track state, and decide whether a retry is safe.
  • Task ID and user identity
  • Repository and branch scope
  • Execution policy and timeout
  • Retry and cancellation state
provision
Sandbox02

Run untrusted commands

Clone code, install dependencies, edit files, run tests, and start local services inside an isolated worker.
  • Dedicated filesystem and process space
  • Short-lived credentials
  • Restricted network access
  • Logs and command results
export
Durable systems03

Accept only intentional outputs

Preserve the artifacts the product needs after the worker disappears, while keeping unrelated sandbox state temporary.
  • Commit or patch
  • Test and verification results
  • Review artifacts
  • Audit and task outcome
The execution worker can be disposable even when the task record is durable. That distinction makes cleanup much easier to reason about.

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.

Isolation model

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.

01

Compute and filesystem

Keep each run away from the host and from other agent sessions. A failed or hostile command should not expose another task's checkout or process state.
Prefer a dedicated VM or microVM boundary for code execution rather than a shared long-lived shell used by many tasks.
02

Identity and secrets

Give the worker only the credentials required for the current user, repository, environment, and task.
Short-lived identity is safer than copying broad static keys into every agent environment.
03

Network and services

Decide which package registries, APIs, databases, private services, and public destinations the worker may reach.
Use outbound restrictions or private connectivity when the task does not need unrestricted internet access.

Decision point

A sandbox reduces execution risk. Least-privilege identity and network policy reduce what an isolated worker can do outside its own machine.

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.

Credential boundary

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.

Broad static secret

The worker receives standing authority

A reusable key often survives beyond one run and may carry access that is unrelated to the current task.

Scope

Frequently team-wide, environment-wide, or difficult to narrow.

Lifetime

Remains valid until somebody rotates or revokes it.

Failure consequence

A leaked value can outlive the sandbox that exposed it.
Task-scoped identity

The worker receives temporary authority

The control plane binds credentials to the current user, task, resource, and expected lifetime.

Scope

Limited to the repository, service, role, or environment the task needs.

Lifetime

Expires automatically and can be refreshed only through an approved identity path.

Failure consequence

Authority disappears even if a token is copied from the worker.

What this means

Do not let convenience turn the sandbox into a container for permanent infrastructure credentials.

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.

Run lifecycle

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.

01
queued

Accept and scope the task

Create a task ID, bind the user and repository, choose the sandbox policy, and record cancellation or timeout rules.
02
provisioning

Create the isolated worker

Start the sandbox, attach short-lived credentials, and prepare only the repositories and services required for this run.
03
running

Execute and verify

Let the agent edit and run code while the product captures command results, tests, failures, and useful artifacts.
04
finalizing

Export the intended result

Persist the patch, commit, test record, review artifacts, and task outcome before the execution environment disappears.
05
closed

Stop and clean up

Remove the worker, expire temporary authority, and leave the task record in a clear succeeded, failed, cancelled, or timed-out state.

Route principle

Retry a known state with a known idempotency rule. Do not replay an entire autonomous session after an ambiguous external side effect.

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:

Lifecycle pattern

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.

sandbox-task.ts
typescript
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();}}
Vercel's current examples use the same create, command, and explicit stop lifecycle. For an agent runner, wrap repository preparation, commands, test execution, and artifact collection inside the same cleanup boundary.

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.

Persistence decision

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.

Ephemeral run

Fresh worker for each task

Best when tasks are independent and the setup cost is acceptable.

Benefits

Simpler cleanup, less cross-run state, clearer credential lifetime.

Cost

Repository cloning and dependency setup may repeat.
Deliberate persistence

Resume from approved state

Useful when rebuild cost is high or a user needs to continue the same task later.

Benefits

Faster resume and less repeated environment preparation.

Control required

Retention, snapshot ownership, secret hygiene, invalidation, and deletion need explicit rules.

What this means

Persistence is a product feature with retention and security consequences, not merely an optimization switch.

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.

Execution location

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.

01

Perimeter requirement

Written policy requires repository checkout and command execution to stay inside company-managed infrastructure.
Use a self-hosted execution path that satisfies that policy.
02

Private dependency reach

The task needs internal services that cannot be safely exposed through approved private networking or outbound rules.
Run the worker where those dependencies are already reachable.
03

Special compute or storage

The task needs hardware, operating-system behavior, disk, or local tooling the hosted worker cannot provide.
Move execution only when the requirement is concrete and ongoing.

Decision point

Self-hosting changes where code executes. It does not remove the need for sandboxing, least privilege, lifecycle control, or observability.

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.

Architecture review

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

Bind the job to a user, repository, branch, and policy so every external action has an accountable context.

Execution is isolated per run or agent

Do not let unrelated tasks share a mutable shell, checkout, or process space without a deliberate isolation boundary.

Credentials are short-lived and scoped

Prefer temporary identity tied to the task over long-lived keys copied into every environment.

Network access matches the task

Restrict outbound destinations or private-service reach when broad internet access is unnecessary.

External writes are idempotent

Branch creation, pull requests, artifacts, deployments, and other side effects survive infrastructure retries safely.

Verification is captured before cleanup

Keep test results, command failures, relevant logs, and review artifacts with the durable task record.

Persistence is intentional

Know which files or snapshots survive, for how long, who can resume them, and what invalidates old environment state.

Cleanup runs on success, failure, timeout, and cancellation

The worker should not depend on a successful model response to stop consuming resources or carrying temporary authority.

Before moving on

The model can decide how to work on the code. The product still owns the permissions, execution boundary, durable side effects, and end of the run.

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.

Sources

References used for this Insight

Sources support the factual basis of the article. Product interpretation and frameworks are presented separately as Ascent's analysis.

  1. 01

    Vercel

    Official sourceSep 3, 2026

    Cursor 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.

    Source
  2. 02

    Vercel

    DocumentationChecked Sep 5, 2026

    Vercel Sandbox

    Current product documentation for isolated microVM execution, supported runtimes, session duration, exposed ports, and observability.

    Source
  3. 03

    Vercel

    Official sourceJan 30, 2026

    Run untrusted code with Vercel Sandbox, now generally available

    Background on the microVM execution model, isolated filesystem/network/process space, ephemeral agent workloads, and snapshots.

    Source
  4. 04

    Cursor

    DocumentationChecked Sep 5, 2026

    Cloud Agents

    Current documentation for isolated cloud-agent environments, repository execution, secrets, network controls, and environment setup.

    Source
  5. 05

    Cursor

    DocumentationChecked Sep 5, 2026

    Cloud Agent security overview

    Source for per-agent VM isolation, repository access boundaries, runtime data handling, and current security model.

    Source
  6. 06

    Cursor

    DocumentationChecked Sep 5, 2026

    OIDC tokens for Cloud Agents

    Source for short-lived OIDC identity that can replace stored long-lived cloud credentials in supported workflows.

    Source
  7. 07

    Cursor

    DocumentationChecked Sep 5, 2026

    Choose where Cloud Agents run

    Source for the hosted versus self-hosted decision conditions around perimeter policy, private dependencies, hardware, storage, and operational ownership.

    Source

Source links support the facts they are attached to. They do not imply that the source publisher endorses Ascent's interpretation or recommendations.