Skip to content

feat(agent): upload a pinned local OpenCode binary into the sandbox - #6232

Draft
ananthsub wants to merge 2 commits into
mainfrom
ananthsub/opencode-local-binary
Draft

ananthsub wants to merge 2 commits into
mainfrom
ananthsub/opencode-local-binary

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

opencode_sandboxed_agent gets two config fields, local_opencode_binary_path and local_opencode_binary_sha256. Together they upload an OpenCode executable from the agent-server host into each sandbox, so the agent doesn't download OpenCode there.

  • At startup: the config checks the local file's SHA-256 against local_opencode_binary_sha256. It refuses one field without the other. It also refuses the upload together with any remote_opencode_* path or preinstalled_opencode, which the upload would otherwise silently override.
  • Per rollout: the binary is uploaded to a fresh /tmp/nemo-gym-opencode-binary-* path before the launch command runs. A timed-out upload is retried at a new path.
  • In the sandbox: the setup step runs opencode_agent's staging script (STAGE_EXECUTABLE in responses_api_agents/opencode_agent/pinned.py). It copies the upload, keeps the copy only if its SHA-256 matches, checks that it answers --version, and then installs it as $HOME/.opencode/bin/opencode. The staging copy has a unique name, because rollouts may share $HOME on the local and Apptainer providers. The existing check that the installed version equals opencode_version still runs after that.
  • Shared upload helper: the ripgrep upload helper now stages either binary, keeping the same retry and per-process concurrency limit (_stage_ripgrep became _stage_binary). The ripgrep log lines and failure reasons read as before.
  • Upload removal: setup removes each uploaded binary once it is staged, OpenCode's and ripgrep's, whatever the outcome, and keeps the staging step's exit status. On the local and Apptainer providers, an absolute /tmp upload lands in the host's /tmp, and closing the sandbox doesn't remove it, so each rollout used to leave its copies behind (about 167 MB for OpenCode 1.17.11). A removal that fails is ignored: a non-root user can't remove a root-owned upload in a sticky /tmp.
  • The README documents the option, where to get the Linux x86_64 binary, and that the one binary must match the C library of every image.

Why

Without a mounted binary or preinstalled_opencode, the agent runs curl https://opencode.ai/install inside the sandbox. A sandbox without internet access fails at that step, before the model is ever called. One example is the SWE agent sandbox with egress blocked (#6177). The recipes that already run without network mount OpenCode from deployment storage, but an OpenSandbox deployment with no such mount had no way to get the binary in. Checking the digest in the sandbox, not only on the host, catches a truncated or altered upload.

No issue: this unblocks the OpenCode rollout with egress blocked for #6177.

Compatibility

Both fields default to null, so existing configs behave as before. opencode_sandboxed_agent is deprecated. This option supports the setups the deprecation notice still sends here: SWE resources servers that return only a sandbox_handle.

Validation

  • pytest responses_api_agents/opencode_sandboxed_agent/tests/ (the worktree venv, with PYTHONPATH set to the checkout): all pass.
  • The config tests cover:
    • a missing digest, a wrong digest, and a digest without a binary;
    • each conflict with the other install ways, including the musl binary and the install script paths;
    • an upper-case digest, which is normalized.
  • One test runs the generated launch command in a local shell, with a read-only upload in place of the staged path:
    • with the pinned bytes, OpenCode is installed with mode 755 and the agent starts;
    • with altered bytes, setup fails with a SHA-256 mismatch, nothing is installed, and the agent never starts;
    • a removable upload is gone after setup, for both pinned and altered bytes, and a read-only upload that can't be removed doesn't fail setup;
    • each launch stages OpenCode under its own name.
  • The ripgrep test checks the same removal behavior. A unit test checks that the cleanup wrapper keeps the wrapped command's exit status and removes the upload.
  • Mutation checks: replacing the staging script with a plain copy, dropping the removal, or dropping the kept exit status each make a test fail.
  • The import-boundary test now allows opencode_agent.pinned, which uses only the standard library.
  • pre-commit run on the changed files passes.

Rollout evidence

Pending. The first real run will be the OpenCode smoke for #6177 with egress blocked, on a Slurm CPU node against OpenSandbox. Its results will be added here, including the logged upload duration and queue time at the run's concurrency.

opencode_sandboxed_agent installs OpenCode by downloading it from
opencode.ai inside the sandbox unless a binary is mounted or
preinstalled. A sandbox without internet access, such as the SWE
agent sandbox with its egress blocked, then fails at setup.

local_opencode_binary_path and local_opencode_binary_sha256 upload a
host-local executable instead, the way local_ripgrep_binary_path
uploads rg. The digest is checked at startup, and the sandbox installs
the uploaded copy only if its SHA-256 matches and it answers --version,
using opencode_agent's staging script. The ripgrep upload helper now
stages either binary, with the same retry and concurrency bound.

Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

On the local and Apptainer providers an absolute /tmp upload lands in
the host's /tmp, and closing the sandbox does not remove it, so every
rollout left its OpenCode binary (about 167 MB) and its ripgrep copy
behind. Setup now removes each upload once it is staged, whatever the
outcome, and keeps the staging status. A removal that fails, as for a
root-owned upload in a sticky /tmp, is ignored.

The OpenCode staging copy gets a unique name, since rollouts may share
$HOME on those providers. The config also refuses the musl binary and
the install script paths next to a local binary, which would otherwise
be ignored, and the README says the uploaded binary serves one C
library.

Signed-off-by: Ananth Subramaniam <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Nov 16, 2026
@yaoyu-33
yaoyu-33 marked this pull request as ready for review November 16, 2026 20:43
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 16, 2026 20:44

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP WITH CARE

I completed the source review of all three changed files and their affected installation and cleanup paths. I did not execute tests or verify current CI results.

RISK: Supply the required real smoke-rollout evidence

The PR's rollout-evidence section still says “Pending.” The new installation test uses a shell-script executable and a mocked sandbox. It does not validate the real OpenCode runtime, provider upload, model connection or verifier in the intended egress-blocked deployment. This is missing validation, not a demonstrated runtime failure. AGENTS.md requires representative real model rollouts for behavior-changing agent work.

Could you run the planned smoke on the final head and attach its command, effective configuration, binary version/digest and rollout artifacts, including the inspected agent/verifier outcome? Acceptance is installation through the new local-binary fields without downloading OpenCode, a real model/tool interaction, a captured trajectory and completed verification with sandbox egress blocked. Include the upload timing at the tested concurrency as planned. Supplying that evidence is the correction; no implementation rewrite is requested.

Keep the existing digest/conflict validation and the default installation behavior when neither new field is configured. Retain the successful-install and altered-upload assertions alongside the real smoke.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

install_str = ":"
if not self.config.preinstalled_opencode:
if self.config.local_opencode_binary_path is not None:
opencode_remote_path = await self._stage_binary(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK: Clean up the completed OpenCode upload when later preparation fails.

After this upload succeeds, configuration creation and the remaining uploads can still raise before the setup shell runs. For a minimal trigger, configure a valid pinned local binary and opencode_plugins=["missing.js"]: _plugin_uploads raises during configuration creation, so the removal embedded in install_str never executes. The local provider writes the absolute path into host /tmp, while stop() deletes only its workspace. Each failed rollout therefore leaves another full OpenCode executable behind, rather than removing the completed upload where permitted.

Could you give the completed OpenCode upload cleanup ownership inside responses, with bounded, cancellation-safe best-effort removal on preparation failures before caller teardown? Fixing only _run would miss the inherited VibenchAgent.run caller. Keep the original preparation exception, never remove the installed executable, and continue tolerating permission-denied removal. Do not delete an ambiguous timeout path while its upload may still be writing. The exact cancellation-safe implementation needs verification against the provider contracts, so I am not proposing replacement code.

Proposed regression: after a successful local OpenCode upload, trigger the missing-plugin error and assert that its removable upload is absent after /run fails, the original error propagates, no agent or verifier starts, and the sandbox is stopped. Also cover cancellation after a completed upload and failure while staging optional ripgrep. Retain successful installation, SHA-256 rejection, read-only-upload tolerance and fresh-path retry behavior.

upload_dir.chmod(0o755)
assert completed.returncode == 0, completed.stderr
# A read-only upload cannot be removed, and that does not fail setup.
assert uploaded.is_file()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK: Allow successful cleanup when this test runs as root.

With ordinary root DAC-override capability, the generated rm -f removes uploaded despite the directory's 0555 mode. This new assertion then fails, and the following uploaded.read_bytes() cannot succeed. The cleanup is correct; directory permissions do not make the fixture undeletable for root. This affects the stage_ripgrep=True cases, including execution in the Gym image, which defaults to root.

Replace the existence assertion and chained byte comparison with:

installed = bin_dir / "rg"
assert installed.read_bytes() == binary.read_bytes()

Keep the mode, owner and agent-start assertions. Before changing opencode to report wrong-version, recreate the upload if the first launch removed it:

if not uploaded.is_file():
    shutil.copyfile(binary, uploaded)

That keeps the second launch testing version rejection rather than failing because its upload is missing. Retain its assertions that the agent never starts and the now-removable upload disappears.

Proposed acceptance: run the stage_ripgrep=True cases as both an ordinary user and root. Both must install identical 0755 bytes and start the first invocation; the second invocation must reach the version check, reject wrong-version, remove the upload and not start the agent. This failure is source-derived, not an executed result.


removable = run_launch_command(binary.read_bytes(), tmp_path / "removable", read_only=False)
assert removable.returncode == 0, removable.stderr
assert not (tmp_path / "removable/uploads/opencode").exists()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE, suggested test correction: make these assertions inspect the real filesystem.

This test calls _mock_sandbox, which replaces Path.exists globally with a function returning False. Both removable-upload assertions therefore pass even if the local OpenCode branch stops removing uploads. The tampered-install absence assertion at line 929 is ineffective for the same reason.

For these regular-file fixtures, replace .exists() with .is_file() in the assertions at lines 929, 934 and 940. For example:

assert not (tmp_path / "removable/uploads/opencode").is_file()

This keeps the sandbox mock intact while restoring the filesystem checks. Retain the installed-byte/mode assertions, SHA-256 mismatch diagnostic and agent-start marker checks.

Proposed acceptance: temporarily bypass _then_remove_upload only in the local OpenCode installation branch. The removable-upload assertion must then fail because the file is still present. Restore the wrapper and require both valid and altered removable uploads to disappear, while altered bytes still fail without installing or starting OpenCode. I did not execute this mutation.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 16, 2026
@yaoyu-33
yaoyu-33 requested a review from athitten November 16, 2026 21:05
@yaoyu-33
yaoyu-33 marked this pull request as draft November 16, 2026 21:29

This branch has not been deployed

No deployments
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 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