Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 4 min read

Use case: an agent that upgrades dependencies and proves the tests still pass

Bots that open dependency-bump pull requests are common. What they usually cannot do is fix the code when a bump breaks it, so the pull request sits red until someone has time. A coding agent can do that part: read the c

Bots that open dependency-bump pull requests are common. What they usually cannot do is fix the code when a bump breaks it, so the pull request sits red until someone has time. A coding agent can do that part: read the changelog, adapt the call sites, run the tests. The catch is that upgrading a dependency means downloading and running new code from the internet, which is exactly the thing you want to keep away from your laptop and your CI secrets.

This post describes a design where each upgrade attempt runs in its own sandbox with narrow network access, and the only thing that comes out is a patch.

The shape of the job

For each candidate upgrade (one package, or one group of related packages):

  1. Start a sandbox from a snapshot of the repository with current dependencies installed.
  2. Let the agent change the version, install, and run the build and tests.
  3. If something breaks, let the agent read the error and the package's changelog and adapt the code.
  4. When the tests pass, or after a fixed budget of attempts, extract the diff and stop the sandbox.
  5. Your orchestrator opens a pull request from that diff, with the agent's notes, for a person to review.

The agent never pushes. The orchestrator turns a patch into a pull request using its own credentials, which the sandbox never sees.

Network: the registry and nothing else

An upgrade needs the package registry. It does not need anything else.

On Sandscale, a sandbox's network option is none by default, and allowlist uses your organization's egress allowlist where your plan includes it. For this job, the allowlist should contain your package registry, or better, your internal mirror or proxy of it, and nothing else. If the agent decides to curl a "fix" from a gist, the request fails.

Two details matter:

  • Install scripts run. npm install runs lifecycle scripts; pip install from a source distribution can run arbitrary code at build time. The sandbox is where that is acceptable, because it has no secrets and nowhere to send them. Supply-chain risk when agents install packages goes deeper.
  • Mirrors help. A proxy that only serves packages older than a set age, or that has been scanned, narrows the window for a freshly published malicious version. That is a property of your registry setup, not of the sandbox, but the sandbox's allowlist is how you make sure the agent cannot bypass it.

Designing an egress allowlist covers how to choose entries.

No secrets in the box

Private registries need a token. Keep it narrow:

  • A read-only token scoped to the registry, not your general CI token.
  • Delivered to the sandbox for that run only. Sandscale's Vault can hand named values to a sandbox's environment through the SDK's vaultEnv option; the values never pass through the SDK's answer or an audit entry.
  • Never in the prompt. The agent does not need to know the token exists.

And no Git push credentials at all. The orchestrator handles the pull request.

Giving the agent what it needs to fix breakage

The agent's success rate depends on information:

  • The old and new versions, and the package's changelog or release notes between them. Your orchestrator can fetch these and write them into the sandbox as a file, so the agent does not need web access to read them.
  • Test output it can act on. Structured results, such as JUnit XML or go test -json, are easier for a model to use than a wall of log. See test results a coding agent can act on.
  • A budget. A fixed number of edit-and-test cycles. If the tests are not green by then, stop and report what broke. A partly fixed upgrade with a clear note is still useful to a person.

Checking the result

Before a pull request is opened:

  • Run the full suite yourself in the box, not just the tests the agent ran.
  • Diff the lockfile. The upgrade should change the packages you asked for and their dependencies, not swap unrelated ones. A surprise new dependency deserves a person's attention.
  • Check the diff for things an upgrade should not touch, such as CI configuration, test assertions changed to match new output, or tests deleted. Reviewing an agent's diff has a checklist.

Running many upgrades

One sandbox per upgrade keeps attempts independent: a failed major-version bump of one package does not leave a half-installed tree for the next. Your plan's boxes-at-once limit (3 on Free, 30 on Pro and Team) caps parallelism; queue the rest. Starting each from the same snapshot means the dependency install that every attempt shares is done once.

Label each box with the package and target version. When a pull request is questioned later, the labels connect it to the sandbox, its run records and the audit log. On paid plans, a spend cap on the project that runs these jobs bounds what a misbehaving batch can cost.

What a person still decides

The agent can make the tests pass. It cannot decide whether you want the new behaviour, whether the new license is acceptable, or whether now is the time to take a major version. Those stay with the reviewer. The design's job is to make sure that what reaches the reviewer is a clean, tested patch produced somewhere that could not leak anything.

Originally published on the Sandscale blog.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.