Coding and Software-Engineering Agents › Safety: executing untrusted code and provenance

Michael BrenndoerferDecember 1, 20264 min read
Language AI HandbookAll chapters
Part 49 of 67Long-Horizon Agents and Interoperability
Chapter 374Coding and Software-Engineering Agents › Safety: executing untrusted code and provenance
Reading section 9 of 12 · Safety: executing untrusted code and provenance · 4 minSection 9 of 12 · 4 min

Section 9 of 12 · 4 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A repository test run can execute code from the repository and its dependencies. A production service that accepts untrusted repositories needs a boundary to control where that code runs and what it can access.

Use the same execution policy for code run by test hooks as for any other user-controlled program.

The agent's verifier is attacker-controlled

When a coding agent runs a repository's tests, the tests come from the repository being edited, which may be a user-supplied or third-party codebase. Test files, conftest.py, setup.py, and imported modules are all code that executes during a test run. Treat every test runner invocation as executing untrusted code, and sandbox accordingly.

Least privilege for the agent

Give the test runner the permissions, data and resources the task needs. Layer controls that match the application’s threat model so the runner cannot reach unrelated assets or consume unbounded resources.

  • Filesystem isolation: limit access to the task repository and supporting files needed by the runner. Keep unrelated directories and host credentials outside that boundary.
  • Network access: deny outbound connections by default. Grant only destinations and credentials the authorized task needs.
  • Resource limits: use memory, CPU and elapsed-time limits to bound the impact of runaway work.
  • Drop privileges: run as an unprivileged user with no ability to sudo, and use a fresh container per run.
  • Ephemeral state: give each run a clean snapshot and keep retained results separate from its writable environment.
  • Egress allowlist, if you must allow some networking (package installation), limited to the package registry, and pinned.

The notebook runs only trusted local fixture code. Its clean temporary directories, fixed command, environment variables, and timeout are for a repeatable teaching example. A service that runs untrusted code needs a separate enforcement boundary with minimal permissions and explicit filesystem, network, and resource controls.

Filesystem access, network access, privileges, resource limits and clean snapshots control different parts of the job. Overlapping controls can limit some failures. Verify each boundary against the actual execution environment and the task’s threat model.

Dependency provenance

Dependency installation adds another trust decision. Review registry, package identity, artifact integrity and resolution policy, including transitive dependencies. A pinned name or version alone cannot establish that a package is appropriate.

Use a reviewed dependency specification, a trusted registry or build source, and integrity checks. Install needed dependencies in a controlled build separate from running the task. The fixture introduces no third-party dependency and permits only the parser source file to change.

Limit installation to the dependency artifacts the project has approved. A new dependency needs its own approval and a fresh build using the intended source.

Defensive review of generated code

Finally, the review step itself is a safety control. A human (or a separate reviewer model) should look for the failure modes we have been cataloguing, in roughly this order:

  • Did the tests change, and if so, why? Any modification, deletion, skip, or assertion weakening is a red flag until explained.
  • Is the change minimal and local? A one-line fix to a subtle bug should be roughly one line. Large diffs deserve large review.
  • Does the change special-case the tests? Look for literal inputs from the test file in the source, or conditionals keyed on specific values.
  • Does it introduce dangerous constructs? eval, exec, os.system, subprocess, dynamic imports, or network calls in a function that had none.
  • Does it match repo conventions? A patch in a style foreign to the codebase is suspicious, or at best needs reformatting.
  • Are the held-out checks green? Always re-run them independently of the agent's claim.

This is a review checklist, not a substitute for human judgment. The human owns the approve button; the agent owns the proposal.

Start with changed paths, verifier integrity and expected patch scope. Then review the behavior and its coverage. A passing scope check can still leave a wrong change in the one allowed file.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy