Skip to main content

Example: Vendor coding agent CLIs in a sandbox

You use this pattern when you want real terminal coding agents (for example GitHub Copilot CLI, Claude Code, OpenCode, or Kilo Code, sometimes written “Kilocode”) to work inside an isolated Linux VM instead of on a developer laptop. The sandbox gives you a clean Node-capable environment (typically the code system image), a persistent workspace directory, and the same exec / filesystem APIs you use for any other automation.

What you accomplish

  1. You create a sandbox with enough memory for npm install -g (often 4 GB or more).
  2. You create a workspace under /work/.... If mkdir is denied for the default user, you use sudo mkdir and sudo chown "$(id -u):$(id -g)" so the sandbox user can read and write (and fs.uploadFile works).
  3. You install the vendor CLI with sudo npm install -g so packages land in the default global prefix (for example /usr/local/bin) without relying on /tmp as an install location.
  4. You pass provider secrets with envVars on createSandbox, or env on each exec, so keys never live in the command string.
  5. For interactive full-screen TUIs, you attach a PTY (or SSH/VNC per your deployment). For CI-style runs, you use each vendor’s non-interactive or headless flags from their docs.

Tools this guide matches

Install methods change; always confirm the current command on the vendor’s site. Alternatives include curl | bash installers (Copilot: https://gh.io/copilot-install) or brew, which you can run inside a max image if you need apt/brew-style workflows.

Concepts you use

  • code image: Fast TTI with Node and many runtimes; good default for npm-based CLIs. If a binary needs glibc-heavy dependencies, try max or a custom image.
  • sudo: Use it when /work or the global npm prefix is root-owned. After sudo mkdir, chown the tree to the interactive user so uploads and git writes succeed.
  • Secrets: Map orchestrator secrets into createSandbox({ envVars: { … } }) so every shell in the VM sees them, or pass env only on the exec that starts the agent.
  • Interactive vs headless: TUIs expect a terminal; use Interactive PTY. Unattended jobs need the vendor’s documented flags (print mode, CI, --help output).
  • Performance: Repeated npm install -g in every sandbox is slow; for production, bake the CLI into a custom image and create sandboxes from that image.

Prerequisites

You completed Examples overview. You set VR_API_KEY. Outbound npm registry access must be allowed for installs inside the VM (see Internet access if you restrict egress). Your image must ship sudo (and typically passwordless rules for the sandbox user) if you follow this pattern.

Reference script (TypeScript SDK repo)

The SDK includes ts-sdk/example/coding-agent-sandbox.ts, which:
  • Creates a code sandbox (4 GB RAM default).
  • Runs sudo mkdir -p /work/agent-project and sudo chown to the current user, then seeds README.md via fs.uploadFile.
  • Runs sudo npm install -g for claude, opencode, kilo, or copilot (first CLI argument).
  • Copies known provider env vars from the host into envVars when set (never prints their values).
Export collectProviderEnvForSandbox and setupVendorCliInSandbox from that file if you want to reuse the same steps from your own orchestrator.

Minimal shape in your own app

Practices you should follow

  • You never commit provider tokens; you inject them from a secret store at runtime.
  • You pin CLI versions (sudo npm install -g package@x.y.z) when reproducibility matters.
  • You read exit codes from exec after install and after agent runs; surface stderr in your logs.
  • You combine this with Untrusted user code when the agent can execute arbitrary commands suggested by an end user.

Interactive PTY

Terminal UI for CLIs that need a real TTY

Ephemeral dev environment

Throwaway VMs with tooling pre-installed

Custom images

Bake CLIs into the image to skip repeated installs

Multi-step job

Shared disk across clone, install, test