OpenCode sandbox: permissions, hosted runtimes, and costs

Run OpenCode in an isolated hosted workspace. Compare permission versions, runtime choices, network controls, and compute plus retained-disk costs.

•

Published on

•

OpenCode sandbox: permissions, hosted runtimes, and costs
Do not index
Do not index
An OpenCode sandbox is an isolated environment around the coding agent: OpenCode's own security policy says its permission prompts do not provide security isolation. For hosted work, Agent37 runs OpenCode on standard gVisor instances or full VMs; choose the runtime around your build tools, network controls, and persistence needs. A standard 2 vCPU, 4 GB RAM, 4 GB disk instance costs $4.76 for 730 running hours, excluding model and tool usage.
The useful question is what the agent can reach after it follows a bad instruction. A test suite, dependency installer, or repository script can exercise the same authority as the process running it. Give that process a deliberately limited computer, then decide which approvals still need a person.
This guide covers version-specific permissions, hosted deployment choices, and a reproducible infrastructure budget. Documentation and rates were checked on October 29, 2026; the examples are configuration guidance, not a security certification or performance benchmark.

What an OpenCode sandbox must isolate

OpenCode's published threat model explicitly recommends a container or VM when you need isolation. That statement is stronger evidence than an old feature-request thread or the absence of a configuration field.
Design around four boundaries:
Boundary
What to decide before execution
Files
Which repository, caches, and output directories may the process read or change?
Network
Which model endpoints, registries, and Git remotes can it contact?
Credentials
Which scoped tokens are available, and can a proxy keep them outside the worker?
Lifetime
When does execution stop, and what survives restart or deletion?
A working directory is useful context, but it does not by itself confine a process. A fresh Git worktree helps review changes, but it does not remove access to other files. Likewise, an isolated filesystem does not prevent a process from sending the files it can read to an allowed destination.
For a hosted service, keep the job coordinator outside the worker. Give each trust domain its own environment, collect a diff and test output, and approve publication separately. That makes the authority granted to one job easier to inspect and revoke.

Check V1 versus V2 before copying permission rules

Run opencode --version in the actual worker. Your laptop, container image, and managed template can ship different versions. The V2 migration guide documents a different configuration surface; upgrading the binary and copying an old snippet are separate operations.
Configuration
V1
V2
Permission field
permission object
permissions array
Shell action
bash
shell
Delegation action
task
subagent
The V1 permission reference documents allow, ask, and deny, with later matching patterns taking precedence. Its --auto option approves requests that would otherwise ask, while explicit denials remain enforced. Treat that as approval behavior, not added isolation.
For V2, this project configuration asks before shell actions and denies direct edits to a production deployment directory:
{
  "$schema": "https://opencode.ai/config.json",
  "permissions": [
    { "action": "shell", "resource": "*", "effect": "ask" },
    { "action": "external_directory", "resource": "*", "effect": "ask" },
    { "action": "edit", "resource": "deploy/production/*", "effect": "deny" }
  ]
}
The V2 permissions documentation warns that shell commands retain the host user's filesystem, process, and network authority. An edit-tool denial therefore does not make that directory unwritable to an approved shell command. Enforce important filesystem restrictions outside the agent.
V2 also permits external-directory access by default unless you add a rule. Custom subagents have their own permissions rather than inheriting a restricted subset of their parent's. Review the effective configuration and each agent used by your workflow before unattended operation.

Choose the execution boundary your build actually needs

For a trusted, interactive project, an OS wrapper can restrict process access without provisioning a remote machine. Check which processes the wrapper covers: wrapping one shell tool is different from enclosing the entire agent, its plugins, and child processes. This route still depends on the machine staying available.
A conventional Docker or Podman container packages the whole agent and its dependencies. On a server, mount only the workspace it needs, keep state in an intentional volume, and avoid mounting the host Docker socket. Ordinary Linux containers share their host's kernel; privileged settings and broad mounts can defeat the separation you expected.
Docker Sandboxes is a separate product from running an ordinary container. Its OpenCode guide documents sbx run opencode ~/my-project for the local workflow. Docker's local/cloud comparison explains that cloud mode has separate secrets and network policies, no host-path mounts, and its own lifetime settings. Moving a local recipe to a server requires checking those differences.
For Agent37, standard gVisor instances add an application-kernel boundary and suit ordinary coding tasks that do not need a Docker daemon. Choose a full VM for Docker/Compose or other requirements needing a guest kernel. Our microVM versus container guide explains how to evaluate that tradeoff.

Hosted OpenCode options serve different workflows

Start with the integration you need, then compare costs for its actual lifecycle.
E2B's OpenCode guide provides a prebuilt opencode template for running the whole agent remotely. It also distinguishes that approach from keeping OpenCode local and using remote workspaces. Decide where the model loop runs before choosing which files and credentials to transfer.
Cloudflare's OpenCode runner follows a repository-to-diff workflow. Its example routes model calls through AI Gateway, adds the gateway token in the Worker, and restricts the sandbox to the gateway and GitHub. That is useful when your application already uses Workers and you want a coordinator around each coding task.
Vercel's OpenCode guide combines a microVM, authenticated agent server, outbound policy, and optional credential brokering. Inspect the network-layer secret handling if keeping provider keys out of the guest is a requirement.
Agent37 offers a persistent instance with a preinstalled OpenCode template, managed-model access, and the same lifecycle API used for other sandbox workloads. This fits a worker that repeatedly returns to its repository and installed tools.
These are deployment differences, not throughput measurements. For other providers, include required plans, current allowances, snapshots or volumes, session limits, and active-CPU versus allocated-resource billing. Multiplying a headline hourly price by 730 can miss most of that invoice.

Create a persistent OpenCode worker on Agent37

The OpenCode template documentation describes a lean image with no browser or desktop. It starts with the managed model, billed separately against your wallet, and supports bringing your own provider key.
With an API key in your local AGENT37_API_KEY environment variable, this request explicitly selects the resources used in the budget below:
curl --fail-with-body https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer $AGENT37_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "agent37-opencode",
    "type": "default",
    "resources": { "cpu": 2, "memory": 4, "disk": 4 },
    "name": "OpenCode review worker"
  }'
Use the returned instance URL for the template's chat API, or open its terminal. Record the installed OpenCode version before applying configuration. The example leaves outbound networking at its default and does not enable auto-sleep; configure both for your workload before running unattended jobs.
Managed model access avoids a separate provider setup, but it is not free inference. Keep the Agent37 control-plane key in the coordinator rather than writing it into the repository. Use narrowly scoped repository credentials and inspect the diff before granting a worker permission to push.
For Docker builds, use a VM. The VM documentation explains that agent37-ubuntu includes Docker and defaults to 12 GB disk. Other templates have different software. VM entrypoints do not provide systemd init, and durable Docker data must live on the billed disk. VM creation requires a funded workspace.

Configure network access separately from approvals

Agent37's network policy supports unrestricted internet access, deny-all, or an allowlist of IPv4 addresses and ranges. It is not a domain-name allowlist: hostnames and IPv6 entries are rejected. DNS also needs permitted resolver access.
There is a critical deployment constraint: the documentation says managed models and tools are unavailable under deny-all or an allowlist. Do not combine the managed-model quick start with a restricted policy and assume chat will keep working. Either use a deliberately reachable external inference endpoint or keep the model loop outside the restricted execution worker.
Keep credentials and outbound policy in the deployment design together. A provider token stored in an environment variable is still available to processes that can read that environment. An allowlisted Git host can still receive data through an authorized account. Scope the token to the repository and operations the task requires.
Test both directions: an intended dependency or inference request should succeed, while a request to an unrelated destination should fail. Repeat after lifecycle changes. A policy you have only saved, without checking its effect, is an unfinished deployment.

Budget running time and retained disk separately

At current Agent37 rates, standard compute costs $0.80 per vCPU plus $0.70 per GB RAM per 730-hour month. Disk costs $0.09 per GB over the same period. Full VM compute is 2.5 times standard compute; disk has no multiplier.
For 2 vCPU and 4 GB RAM, standard compute is $4.40 per 730 hours and VM compute is $11.00. The following examples retain disk for the entire 730-hour accounting period and assume the instance is stopped or sleeping outside the stated running time:
Runtime and allocated disk
60 running hours
730 running hours
No running hours, disk retained
Standard gVisor, 4 GB disk
$0.72
$4.76
$0.36
Full VM, 4 GB disk
$1.26
$11.36
$0.36
Full VM, 12 GB disk
$1.98
$12.08
$1.08
The standard 60-hour calculation is $4.40 × 60 / 730 + $0.09 × 4 = $0.7216, rounded to $0.72. This is an estimate from published rates, not a measured customer bill. Model tokens, paid tools, and any separately purchased services are excluded.
An awake but idle instance still bills compute. Auto-sleep must be enabled and configured appropriately; stopping or sleeping pauses compute while retained disk continues billing. Deletion ends the instance meter. See the billing rules for state transitions and wallet behavior.
Size disk for your checkout, dependencies, caches, and build outputs. The 4 GB example makes the arithmetic comparable, but a Docker-heavy project may need more. Eligible new Cloud accounts receive $5 starter credit after adding a card; this is trial credit, and VM funding requirements still apply.

Validate one job before scaling the worker fleet

Use a disposable copy of a representative repository. Ask OpenCode to make a small change and run its normal tests. Save the diff, exit codes, and relevant logs outside the worker before cleanup.
Then exercise the boundaries deliberately with harmless fixtures. Check that an unmounted private file is unavailable, an unrelated outbound destination is blocked under your chosen policy, and the agent cannot obtain a production credential it was never given. Confirm that expected model calls still work.
Finally, stop and restart the worker. Verify that committed work and required files survive, and that your coordinator can recover when an in-flight request ends without a response. Persistent disk does not guarantee that every running process or network connection survives a lifecycle event.
Start with one Agent37 sandbox, measure the resource use of your actual test job, and expand only after the boundaries and recovery behavior match your requirements.

OpenCode sandbox FAQ

Does OpenCode provide isolation by itself?

Its published security policy says no. Permission rules help control tool use, while a separately configured container, VM, or other enforced execution boundary limits the process's authority.

Can I use V1 permission snippets with V2?

Follow the migration guide for your installed version. V1's permission and bash names differ from V2's permissions and shell; verify effective behavior after upgrading.

Does a gVisor instance support Docker builds?

Agent37's standard gVisor runtime cannot run a Docker daemon. Choose its full VM runtime for Docker/Compose and allocate enough persistent disk for images and build caches.

Is $4.76 the total monthly cost of OpenCode?

It is the standard 2 vCPU, 4 GB RAM, 4 GB disk infrastructure estimate for 730 running hours. Model and tool usage are additional, and different resources or runtime choices change the total.
Vishnu

Written by

Vishnu

Founder at Agent37, which runs managed hosting for OpenClaw and Hermes agents for 1,000+ users. Writes about what actually breaks when you leave an AI agent running.