# microsoft/orchard — AlpLab Radar Static Code Audit

- Ring: `trial`
- Category: `agents`
- Overall score: `3.6/5`
- Implementation check: `verified`
- Maturity: `early`
- Audited commit: `769f7460c8cb` (read-only; nothing from the repository was executed)
- Reviewed at: 2026-12-01T20:26:55Z
- Repository: https://github.com/microsoft/orchard
- Radar entry: https://radar.alplab.co/#repo/microsoft/orchard
- License: `MIT`
- Tags: `agents`, `sandbox`, `kubernetes`, `swe-bench`, `evaluation`, `orchestration`

## Summary

Orchard-Agentic: a Kubernetes-native sandbox service (orchard_env — multi-replica FastAPI orchestrator with Redis state/locks, init-container-injected in-pod agent for direct Pod-IP exec, sync/async Python SDK with auto-cleanup, and six preinstalled agent CLIs via a relocatable tools image) plus an eval kit (orchard_eval) that runs any harness against SWE-bench Verified/Pro on those sandboxes, graded with the official swebench package.

## Implementation Check

Every core README claim maps to working code — orchestrator/api.py (create/exec/files/apply_patch/network routes, verify_api_key, PTY WS proxy), agent/server.py (in-pod FastAPI exec agent), client/sandbox_client.py (sync/async SDK with atexit/signal cleanup and retry backoff), k8s_client.py create_pod (agent-injector init container + image-volume sandbox-tools), Dockerfile.tools (codex/claude/pi/opencode/hermes/mini payloads with private glibc runtime) — while the trainer is honestly documented as an empty git submodule and pause/resume/branching are clearly labeled roadmap, not shipped.

## When to Use

Use it when you need elastic, harness-agnostic sandbox fleets for agent rollouts, distillation, or SWE-bench-style evaluation on a Kubernetes cluster you operate yourself (the Azure AKS path is fully scripted). Not for teams wanting a hosted sandbox API, users without Redis/Calico/ACR plumbing or cluster-admin appetite, or multi-tenant clusters — every internal hop is plaintext HTTP and the in-pod agent is unauthenticated, so you must supply your own network-layer controls.

## Sub-scores

| Dimension | Score |
|---|---|
| quality | 4.5/5 |
| usability | 3.5/5 |
| reliability | 3.0/5 |
| security | 3.0/5 |
| integration | 4.0/5 |

## Code Evidence

orchard_env/orchard_env/orchestrator/api.py defines the full REST surface (create_sandbox, exec_command with server-side wait, upload/download/list_files, apply_patch, update_sandbox_network with NetworkAllowRule CIDR validation refusing /0, exec_pty_ws proxy with _verify_ws_api_key) behind X-API-Key auth; orchard_env/orchard_env/agent/server.py is the injected agent whose exec_command runs bash via asyncio.create_subprocess_exec with start_new_session=True and killpg on timeout, plus a documented WebSocket PTY protocol at /exec/pty; orchard_env/orchard_env/orchestrator/exec_manager.py serializes execs per sandbox under locks and retries agent connection failures over a budgeted window; orchard_env/orchard_env/orchestrator/sandbox_manager.py implements Redis-backed state, identity-fenced pod deletion (uid/resource_version preconditions), distributed network locks with renewal (renew_lock/ensure_lock_owned), TTL/pending/heartbeat cleanup, and K8s reconciliation; orchard_env/orchard_env/orchestrator/k8s_client.py create_pod injects the agent via init container into any image and mounts sandbox-tools read-only (image volume or emptyDir fallback), with _build_startup_command shimming the six CLIs into /usr/local/bin without shadowing image tools; orchard_env/Dockerfile.tools builds relocatable payloads (npm-extracted native binaries, GitHub-release pi, standalone-CPython hermes/mini) and verifies them on both glibc and Alpine stages; orchard_env/orchard_env/client/sandbox_client.py provides SandboxClient/AsyncSandboxClient with _register_cleanup (atexit + SIGINT/SIGTERM), 503/connection retry with backoff, and correct refusal to treat a 'running' server-wait response as complete; orchard_eval/orchard_evalkit/grading/swebench.py grades via the official swebench make_test_spec/get_logs_eval and diagnose_unparsable_log separates infra failures from wrong answers; orchard_eval/orchard_evalkit/harnesses/installed_cli.py renders CLI commands with shlex.quote and staged prompt files and probes that a resolved binary actually executes; offline unit tests exist in orchard_env/tests (test_exec_timeout.py, test_network_control.py, test_file_listing.py, test_resources.py) and a substantial suite under orchard_eval/tests.

## Issues Found

orchard_env/orchard_env/orchestrator/exec_manager.py _run_command joins list-form commands with a bare " ".join (same in client exec paths), corrupting any argument containing spaces or quotes — acknowledged as a known bug in orchard_env/tests/README.md ('list-form commands' quirk); orchard_env/orchard_env/agent/server.py listens on 0.0.0.0:9090 with zero authentication, so any workload that can reach a pod IP cluster-internally can execute arbitrary commands in that sandbox (deny-all-egress controls egress only, not ingress); all hops are plaintext HTTP by default (client→orchestrator, orchestrator→agent http://pod_ip), so exec env vars including model API keys transit unencrypted unless an TLS ingress is supplied; ExecManager.apply_patch interpolates patch content into a bash heredoc delimited by PATCH_EOF, so a patch containing that literal line injects commands; k8s_client.py upload_file/download_file embed file paths in single-quoted bash (breaks on quotes) and its legacy exec_command exports env values unquoted; no CI runs the test suites.

## Key Risks

Heavy operational prerequisites: an AKS-class cluster with Calico, Redis, a container registry, and four shell scripts to stand up; not pip-installable from PyPI (path dependency on this repo). No CI workflows exist at all (maturity ci: []), so the real test suites never run automatically and nothing was executed in this audit. Performance numbers in the README (0.28s latency, 1000 sandboxes, cost tables) are paper claims not verifiable statically. The RL trainer is an external submodule (MSR-Orchard/slime) absent from this tree. Default tools-image build uses 'latest' for codex/claude/opencode unless build-args are pinned. Spot-instance fleets and node-image upgrades (scripts/remediate_kernel_cve.sh, k8s/algif-aead-blacklist.yaml) are internal-ops-specific scripts shipped in the repo.

## Reviewed Files

- `README.md`
- `.gitmodules`
- `.github/copilot-instructions.md`
- `orchard_env/README.md`
- `orchard_env/pyproject.toml`
- `orchard_env/Dockerfile.tools`
- `orchard_env/orchard_env/__init__.py`
- `orchard_env/orchard_env/client/sandbox_client.py`
- `orchard_env/orchard_env/client/process.py`
- `orchard_env/orchard_env/agent/server.py`
- `orchard_env/orchard_env/agent/pty_runner.py`
- `orchard_env/orchard_env/orchestrator/api.py`
- `orchard_env/orchard_env/orchestrator/settings.py`
- `orchard_env/orchard_env/orchestrator/agent_client.py`
- `orchard_env/orchard_env/orchestrator/exec_manager.py`
- `orchard_env/orchard_env/orchestrator/sandbox_manager.py`
- `orchard_env/orchard_env/orchestrator/k8s_client.py`
- `orchard_env/tests/README.md`
- `orchard_env/tests/test_exec_timeout.py`
- `orchard_env/k8s/secret.example.yaml`
- `orchard_env/k8s/rbac.yaml`
- `orchard_env/k8s/algif-aead-blacklist.yaml`
- `orchard_env/scripts/remediate_kernel_cve.sh`
- `orchard_eval/pyproject.toml`
- `orchard_eval/orchard_evalkit/sandbox.py`
- `orchard_eval/orchard_evalkit/grading/swebench.py`
- `orchard_eval/orchard_evalkit/harnesses/installed_cli.py`
