Skip to content

About

Run Claude Code in a DigitalOcean Harness Runtime sandbox from the TypeScript SDK, verify its fix in a second sandbox, preview it through a port-forward, and prove the model key dies on cleanup.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

do-sandbox-coding-agent

Run Claude Code in a DigitalOcean Harness Runtime sandbox from TypeScript, with @digitalocean/dots 1.28.0. The scripts create the session, clone a repository, give the agent a failing test to fix, check the fix outside the agent's control, open the fixed app through a port-forward, and delete everything, including the model key.

npm ci
export DIGITALOCEAN_ACCESS_TOKEN=...   # from your shell or a secrets manager, never on the command line
npm run create && npm run clone && npm run agent && npm run verify && npm run preview && npm run cleanup
npm run sweep -- --dry-run            # anything left behind?

Node 20 or later. Each stage writes its result to runs/<run id>/ and the next stage reads it, so a failed stage can be re-run on its own. Stages refuse to mix runs made by different code.

What each script does

Script What it does
01-create.ts Creates a Claude Code session from agent.yaml and waits until it is ready. The SDK asks the API to mint a model access key for the session, so no Anthropic key is involved.
02-clone.ts Lists the variable names the agent can see, clones this repository into /workspace/repo, hands only fixture/src to the agent's user, and records the failing baseline (3 of 6 tests fail).
03-agent.ts Sends the task, streams the agent's text and every event to 03-events.jsonl, and answers each approval request with lib/approve.ts, a short allowlist.
04-verify.ts Takes one file from the agent's sandbox and tests it in a new bare sandbox cloned at the original commit. verify/probe.mjs prints the agent's answers for 220 inputs (200 random from a new seed), and this machine compares them with lib/reference.ts.
05-preview.ts Starts the fixed app in the sandbox as the agent's user and reaches it from 127.0.0.1:18080 through session.portForward. Harness Runtime has no public preview URL.
07-idle.ts Optional: waits for idle_timeout to pause the session, then checks whether an exec wakes it.
06-cleanup.ts Destroys the session, deletes the config the API saved for it, and checks from outside that the managed model key stops working.
sweep.ts Destroys every session and config whose name starts with dd-sandbox-agent.
breaks/egress.ts A bare sandbox whose egress allowlist only names github.com tries npm, PyPI and curl. The errors do not say that the network policy blocked them.

Results

The recorded runs are in runs/. The measured run is the newest folder directly in runs/; runs/checks/ holds earlier sessions that broke, each with a NOTE.md that says what broke. Wall-clock timings stay local (timings.local.jsonl is gitignored), because the Harness Runtime public preview terms do not allow publishing benchmarks.

The walkthrough and what we found: https://devops-daily.com/posts/run-claude-code-digitalocean-sandbox-typescript-sdk

Safety notes

  • The approval allowlist is a convenience, not the boundary. The sandbox and its egress allowlist are. The agent can still write files and run node --test, which runs code.
  • The managed model key is a plain environment variable inside the sandbox, and it works from outside the sandbox. Treat everything in the sandbox as readable, and keep egress tight.
  • Verification never runs git or the repository's tests in the agent's sandbox.
  • redact() in lib/run.ts strips secret values and credential shapes from everything written to runs/.

License

MIT

About

Run Claude Code in a DigitalOcean Harness Runtime sandbox from the TypeScript SDK, verify its fix in a second sandbox, preview it through a port-forward, and prove the model key dies on cleanup.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages