Reuse a sandbox
Keep an environment open for agent turns, commands and tests on the same files.
Start with the agent configuration and a project whose test command is available in the sandbox. Prepare dependencies before running the check. A command result must be checked: receiving stdout alone does not mean it succeeded.
Open a sandbox
Section titled “Open a sandbox”Open a sandbox with createSandbox() when several operations need the same files and installed dependencies. await using closes it at the end of the scope, including when an operation throws.
The agent edits the worktree, then npm test runs in the same sandbox against its changes. How this differs from a one-shot dispatch(), and who closes what, is explained in How it works.
Run agent turns
Section titled “Run agent turns”sandbox.dispatch() takes the same brief and turn options as dispatch(), without the repository and sandbox settings. Each call starts a new conversation: continue one with sandbox.resume(id, options) or sandbox.fork(id, options) (Conversations).
An agent passed to sandbox.dispatch() replaces the one given to createSandbox().
Run a command
Section titled “Run a command”sandbox.command() runs one executable with an array of arguments. No shell parses them: *, | and $HOME reach the program as plain text. Call a shell yourself when you need one.
sandbox.root is the repository path inside the sandbox and the default working directory.
API reference: Command.
Check the outcome
Section titled “Check the outcome”A command that exits resolves with status, stdout and stderr, whatever its exit code. A command Outpost had to stop rejects instead.
| Outcome | Result |
|---|---|
| Process exits, even with status 1 | Resolves; test result.status. |
deadlineMs elapses | Rejects with an OutpostError of code timeout; on Vercel and Daytona, with a TimeoutError. |
signal aborts | Rejects with the signal’s reason. |
| The sandbox closes during the command | Rejects; the process is stopped. |
The result waits for the process to exit, even if its output closes earlier. Host processes drain remaining output for at most 500 ms after exit, then close their readers if descendants still hold the pipes. The original exit status is preserved; late descendant output is not collected. For non-interactive host commands, cancellation and deadlines still stop the process group, including descendants that ignore the first termination signal. Read status rather than guessing success from stdout. Error codes are listed in Errors.
Stream a long command
Section titled “Stream a long command”observe shows output while the command runs. retain only bounds what the result keeps, not what observe receives.
Pass it to sandbox.command(build). Stopping a command terminates its process group and its descendants. The sandbox stays open for the next operation.
For this step, follow Open an interactive agent terminal.
Integrate the work yourself
Section titled “Integrate the work yourself”A sandbox you create never merges its branch on its own. With branch: { mode: "integrate" }, call sandbox.workspace.integrate() before closing to merge the work branch into its base.
With other branch modes, integrate() does nothing. A merge conflict, or a host branch switched during the run, rejects with code conflict and keeps the worktree. close({ preserve: true }) also keeps it for inspection (Recover work).
Share a sandbox between tasks
Section titled “Share a sandbox between tasks”defineAgentTask() and defineCommandTask() run in a sandbox you opened with createSandbox(). The tasks share its files; you close it.
test runs npm test on the agent’s edits. A nonzero exit status fails the task.
Host, container and Firecracker process cancellation allow 500 ms after SIGTERM before escalating to SIGKILL. Cleanup remains bounded; this grace period is not a guarantee that a non-cooperative program can finish saving its work.
File workspaces
Section titled “File workspaces”File sandboxes borrow an open FileWorkspace or own an explicit workspaceSource. Closing a borrowed sandbox leaves its workspace open. File workspaces explains provider bindings, output publication and retention.
Limits
Section titled “Limits”- A sandbox runs one operation at a time: a second call made while one runs is rejected, not queued. Use separate sandboxes for parallel work.
- Output is captured as text. Move binary files with the provider’s transfer methods (Cloud sandboxes).
API: createSandbox · Sandbox · Command · CommandResult · AttachOptions · attach.

