Skip to content

patterns/remote-computers.halo ​

examples/patterns/remote-computers.halo tools: policies

Open in the playground and play with it →

halo
// Remote computers: cloud sandboxes for running code, sandbox agents, and a server over SSH.
//
//   E2B_API_KEY=...  halo run examples/patterns/remote-computers.halo -p TryIt --arg code='print(sum(range(10)))'
//   halo run examples/patterns/remote-computers.halo -p Build --arg task='a CLI that counts words, with tests'   (Docker, or E2B_API_KEY)
//   halo run examples/patterns/remote-computers.halo -p Install --arg package=requests   (Docker)
//   halo run examples/patterns/remote-computers.halo -p Disk --arg host_dir=/var/log
//   halo run examples/patterns/remote-computers.halo -p TryLocally --arg code='print(sum(range(10)))'   (Docker, no key)

policy LookOnly : AllowEffects(read)

// A fresh sandbox for each run, deleted when the run ends.
tool Lab : Remote("e2b")

// ... or a container on this machine: no account, no network.
tool Local : Remote("docker", image: "python:3.12-slim", network: false)

// A container that can reach PyPI and nothing else: pip works, nothing else gets out.
tool Deps : Remote("docker", image: "python:3.12-slim", hosts: ["pypi.org", "*.pythonhosted.org"])

// A server you already have, over your own SSH keys and ~/.ssh/config.
tool Box : Remote("deploy@build.example.com", connect_timeout: 10)

// A sandbox agent: its own fresh sandbox for each run, with nothing else to declare.
// "auto" is Docker when it's running, else E2B or Daytona.
agent Dev [anthropic/claude-sonnet-4-5, preset: Coder, sandbox: "auto"]

// This one works in Lab, so the pipeline can put files in before and take them out after.
agent Fixer [anthropic/claude-sonnet-4-5, preset: Coder, sandbox: Lab]

agent Inspector [anthropic/claude-haiku-4-5, tools: auto]
  system "Answer from what you find on the server. Don't guess."
  equips Box
  requires LookOnly

// Run a snippet in the sandbox: no model, just the tool.
pipeline TryIt(code: String) -> Result:
  code
    |> Lab.write(path: "main.py", content: code) as saved
    |> Lab.run(command: "python3 main.py", timeout_ms: 30000)

// The same, in a local Docker container.
pipeline TryLocally(code: String) -> Result:
  code
    |> Local.write(path: "main.py", content: code) as saved
    |> Local.run(command: "python3 main.py", timeout_ms: 30000)

// Install a package from PyPI; any other host the install tried would show up in `blocked`.
pipeline Install(package: String) -> Result:
  package
    |> Deps.run(command: "pip install --quiet --disable-pip-version-check {{package}} && pip show {{package}} | head -2", timeout_ms: 120000)

// Let a coder build and test something in its own sandbox.
pipeline Build(task: String) -> Result:
  task |> Dev.work("Run it, and the tests, before you say it's done.")

// Hand a script to the fixer in Lab, then read back what it changed.
pipeline Fix(script: String, error: String) -> Result:
  script
    |> Lab.write(path: "main.py", content: script) as given
    |> Fixer.work("main.py fails with this error. Fix it and run it until it works.", error) as report
    |> Lab.read(path: "main.py")

// {{host_dir}} is shell-quoted, so it can't run as a command.
pipeline Disk(host_dir: String) -> Result:
  host_dir
    |> Box.run(command: "du -sh {{host_dir}}/* | sort -h | tail -5") as usage
    |> Inspector.explain("Which of these is growing, and is it worth worrying about?", context.data.usage.stdout, tools: [Box])

curl -fsSL https://halolang.com/install.sh | sh