Skip to content

feat(kilocode): run Kilo in task sandboxes - #4305

Merged
yaoyu-33 merged 10 commits into
mainfrom
mkitov/kilocode-sandbox
Oct 20, 2026
Merged

yaoyu-33 merged 10 commits into
mainfrom
mkitov/kilocode-sandbox

Conversation

@mk-0

@mk-0 mk-0 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

This PR adds native task-sandbox sessions to the KiloCode agent. The design is the same as Pi (#3626) and Codex (#3640). Kilo runs inside the task sandbox that the Resources server supplies.

mk-0 and others added 2 commits October 9, 2026 18:37
Add native sandbox sessions to the KiloCode agent so it composes with any
Resources server through single_agent_turn_legacy, as Pi and Codex do.

- Session setup installs a checksum-verified Node 22 and the pinned
  @kilocode/cli into a private per-session directory (glibc and musl);
  task images need only Linux and Python 3.8+.
- The CLI runs under the shared SandboxSession supervisor in the task
  workdir with isolated HOME/config/database and no repo-level config.
- Close returns observations from a snapshot of Kilo's SQLite database
  (root and child sessions, tool timing, usage), annotated with the run
  outcome; CLI/API errors fail the episode instead of scoring zero.
- Kilo's stream watchdog (chunkTimeout) follows the harness timeout,
  since the Gym model server returns completions only once finished.
- Host installation becomes lazy, on the first local invocation.
- kilocode_sandboxed.yaml, SWE-bench Pro allowed_agents, and the legacy
  environment-server migration entry.

Validated on SWE-bench Pro with the stock Resources server: 5-task smoke
across Ubuntu/Node/Go/Python/Alpine images, and 731x3 at 51.30% mean
pass@1 (Nemotron 3.5 Super).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marat Kitov <[email protected]>
Keep the sections other native harnesses document; move run results and
limitations to the PR description.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marat Kitov <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@mk-0 mk-0 added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Oct 9, 2026
@yaoyu-33 yaoyu-33 added the complexity:medium Single-domain change with interacting parts or a moderate review surface label Oct 9, 2026
mk-0 and others added 2 commits October 12, 2026 13:17
Address review and match Pi, Codex, OpenCode and OpenClaw.

- Classify a run from the supervisor cleanup receipt. A runner exit,
  supervision error or missing exit status without a timeout fails the
  episode instead of returning an empty incomplete response. Supervised
  timeouts and length stops stay gradable.
- Run a POSIX sh bootstrap before the Bash installer, and check in the
  sandbox that the task workdir and session storage do not overlap after
  resolving symlinks.
- Return 422 for unsupported setup, require direct SandboxAccess, and
  return 409 for activation of a closing session or /run with a session.
- Snapshot the Kilo database only after confirmed cleanup, and report a
  gap when the receipt has no exit code.
- Add bootstrap, lifecycle-contract and exec-transport tests from the
  reference harness templates.

Validated on 250 SWE-bench Pro tasks with the stock Resources server:
250/250 graded, no agent or infrastructure failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marat Kitov <[email protected]>
@mk-0

mk-0 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @yaoyu-33, this time I explicitly checked test cases of the other sandboxes. I aligned dependency bootstrapping, runtime error propagation, and additionally HTTP error handling to match them.

mk-0 and others added 2 commits October 14, 2026 11:49
Sandbox sessions:
- A run that times out before any model call completed (for example an
  unreachable model server) now fails instead of being graded as a zero;
  the error carries the tail of Kilo's log, which names the cause.
- A retried close no longer cancels an activation that is already cancelling.
- The runner records its hostname and PID; responses report them with the
  Kilo version, and the sandbox record carries the sandbox id.

Local runs:
- Output is file-backed and the process group is killed on timeout and on
  request cancellation, so partial events survive and Kilo never outlives
  its request.
- CLI errors, nonzero exits and timeouts before any model call return a
  failed response with the reason; /run reads Kilo's session database and
  returns agent observations.

Shared:
- Use opencode_agent's session parser (maps bash outcomes from exit codes)
  instead of the deprecated opencode_sandboxed_agent.
- Disable Kilo's auxiliary session-title call by default for Gym-managed
  providers.
- Register Kilo in the harness conformance suite; rename setup_kilo to
  setup_kilocode to follow the setup_<harness> convention.
- Add a read-only AsyncSandbox.sandbox_id property.

Conformance (session mode, Linux): all checks pass in 6 of 7 scenarios;
model_error shows the session-mode gap shared by all harnesses (#4489).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marat Kitov <[email protected]>
mk-0 and others added 3 commits October 15, 2026 20:05
…state

Kilo's tool shells inherited the HOME and XDG directories that keep Kilo's own
state private, so files that tools wrote under the home directory landed in the
session directory and were deleted by agent close before verification. A plugin
now restores the task's HOME and XDG directories for every shell command through
Kilo's shell.env hook, as OpenCode does. Sandbox runs no longer pass --pure, which
would skip that plugin; codebase indexing stays off because kilo.json names no
indexing plugin. Kilo only logs a plugin that fails to load, so a run without the
plugin's receipt fails instead of being verified.

Also from review:
- A cancelled local caller no longer releases another caller to start a second
  installer; one shielded installation task is shared, as in Pi.
- An owned sandbox is retained in the session before start(), so close can stop a
  sandbox that start() allocated but failed to finish setting up.
- A child invocation that stopped on the output limit is reported as incomplete,
  not completed (require_terminal_finish=True).

Validation: Kilo tests pass locally, including the plugin loaded by the pinned
Kilo 7.4.15 binary; the Linux unit suite on AGA shows no new failures; a 5-task
SWE-bench Pro smoke returned and graded 5/5 (4 solved), with the plugin confirmed
in every run and no tool output referring to Kilo's private home.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marat Kitov <[email protected]>
…docs

Conformance CI install looked up kilocode_version, but Kilo's configs only
define kilo_version, so setup raised KeyError for the newly registered
harness. Map kilocode to kilo_version.

The README claimed musl support on aarch64, but install_kilo_runtime.sh
rejects it (the pinned Node musl build is x86_64 only). Document that.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Resolve the harness registry conflict by keeping both kilocode and stirrup.

Main made a negative cleanup receipt final for borrowed sandbox sessions:
close now releases the session for Resources teardown instead of staying
retryable. Update the KiloCode lifecycle test to match, as main did for
OpenCode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 2f09341

…mantics

Main now leaves detached tools from a natural CLI exit for the sandbox owner
to tear down, and treats a negative cleanup receipt as final: close releases
the borrowed session instead of staying retryable. Update the KiloCode exec
transport tests to match, as main did for Codex and OpenCode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 32983a5

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39499174630

Merged via the queue into main with commit bedf564 Oct 20, 2026
49 of 55 checks passed
@yaoyu-33
yaoyu-33 deleted the mkitov/kilocode-sandbox branch October 20, 2026 21:38
yaoyu-33 added a commit to yaoyu-33/Gym that referenced this pull request Oct 21, 2026
Resolves one conflict in `resources_servers/swebench_pro/configs/swebench_pro.yaml`.
NVIDIA-NeMo#4305 added `kilocode_agent` to SWE-Pro's `allowed_agents` while this branch removed
`hermes_sandboxed_agent` from it; the resolution keeps both changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 32983a52 Deployed Oct 20, 2026 by copy-pr-bot[bot] via release / finalize / notify #6042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants