Skip to content

epic: canonical sandbox patterns #2763

Open
0 of 1 issue completed
Open

Description

@cwing-nvidia

Problem

The Sandbox API documentation explains the provider-neutral API, provider configuration, lifecycle, and direct AsyncSandbox/Sandbox usage. It says that agents and Resources servers can call the same API, but it does not answer the architectural questions a new user faces:

Where should the agent run, what exactly should be sandboxed, who should own each sandbox, and which NeMo Gym implementation should I follow?

There are two common high-level patterns:

  1. Agent in sandbox: The complete agent/harness runtime executes inside a task sandbox.
  2. Sandbox as tool/environment: Selected shell, code, or file operations are delegated to a separately managed sandbox. The agent loop may run on the Agent server host or inside its own sandbox.

These patterns are composable rather than mutually exclusive. For example, an agent loop can run in sandbox A while a Resources-server tool executes operations in sandbox B. Sandbox A isolates the harness runtime, while sandbox B provides a separately owned execution boundary for tool state, permissions, image, and lifecycle.

The repository contains several implementations and sub-variants:

  • anyswe_agent and the agentic cvdp_agent package a selected Gym agent runtime and execute it inside each task sandbox.
  • opencode_sandboxed_agent installs and runs the OpenCode harness inside a sandbox.
  • mini_swe_agent_2 keeps the harness outside the sandbox and adapts mini-swe-agent's command environment to nemo_gym.sandbox.Sandbox.
  • litmus_agent exposes a Resources-server tool backed by a per-session AsyncSandbox.
  • swebench plus opencode_sandboxed_agent demonstrate a shared-sandbox-handle lifecycle split between Resources and Agent servers.
  • anyterminal_agent, Harbor integrations, and older SWE integrations contain direct Apptainer/Singularity or framework-managed container paths that do not all model the current provider-neutral API.

These are useful implementations, but they make different choices about:

  • process and trust boundaries;
  • sandbox ownership and lifetime;
  • configuration shape and provider resolution;
  • runtime/dependency staging;
  • model connectivity and credentials;
  • tool routing and session state;
  • artifact and trajectory collection;
  • verification in the same or a fresh sandbox;
  • timeouts, concurrency, errors, and cleanup.

A new user may copy an implementation that appears relevant without realizing that it contains benchmark-specific, legacy, or transitional design choices.

This is not only a documentation gap. Multiple implementations also repeat infrastructure for resolving providers, building specs, tracking per-session sandboxes, packaging guest runtimes, starting guest entrypoints, transferring artifacts, handling failures, and cleaning up. Documentation can identify the preferred designs, but reusable infrastructure and templates can make those designs substantially easier to implement correctly.

Related work:

Goal

Establish supported, sandbox architectures and make each recommended path easy to adopt
through reusable infrastructure, starter templates, and documentation validated by real rollouts.

Guiding principles:

  • Do not treat the Agent server or harness as trusted by default. Sandbox every process context in which
    model-influenced capabilities can execute code or access sensitive resources.
  • A host-side agent with a separate tool sandbox is sufficient only when the agent is intentionally a minimal trusted control plane and every risky operation is delegated.
  • Placing tools in a Resources server can improve ownership and reuse, but placement alone is not a security boundary.
  • Treat isolation boundaries, ownership, lifetime, and composition as separate architecture decisions.

Potential workstreams

  • Inventory and architecture decision: Classify current implementations, define the supported topologies and trust boundaries, and select canonical references.
  • Shared lifecycle and handle infrastructure: Identify repeated sandbox ownership, connection, session, error, and cleanup behavior that should become reusable infrastructure.
  • Agent-in-sandbox support: Evaluate a common runner or guest protocol using existing implementations such as cvdp_agent and anyswe_agent.
  • Sandbox-backed tool support: Evaluate reusable support for agents or Resources servers that delegate selected operations to a sandbox, using implementations such as litmus_agent and mini_swe_agent_2.
  • Configuration and starter templates: Provide simple starting points for agent, tool, and verifier sandbox roles without creating a second provider-configuration system.
  • Documentation and examples: Publish a decision guide, runnable examples, security considerations, and links from the Sandbox API, Agent server, environment tutorials, docs: comprehensive agent harness reference and selection guide #2372, and canonical implementation READMEs.

Design questions

  • Which existing implementation should be the primary reference for each pattern?
  • Which repeated behavior is stable enough for core infrastructure, and which should remain example/template code?
  • Should sandbox B always be owned by a Resources server, or are there supported cases where sandbox A directly owns B?
  • What information can safely cross server boundaries in a sandbox descriptor?
  • How should ownership and teardown work when one server creates a sandbox and another reconnects to it?
  • Should the default lifetime be one sandbox per rollout, one per Gym session, or selected explicitly by the caller?
  • What is the minimum guest runtime contract needed to run arbitrary Gym agents inside a sandbox?
  • Should runtime packaging be standardized, or should core infrastructure only define the guest protocol?
  • How should sandbox-backed tools declare filesystem, command, network, and output policies?
  • Should agent, tool, and verifier sandbox roles be first-class config concepts or documented conventions over named provider blocks?
  • Do starter templates provide enough DX, or should Gym add scaffolding commands?

Delivery approach

Start with the inventory, threat model, and a reviewed engineering proposal. That proposal should decide which gaps belong in core infrastructure, shared helpers, templates, or documentation before implementation work is split into linked issues and PRs.

Infrastructure should be extracted from demonstrated common behavior rather than hypothetical use cases. Each new abstraction should be adopted by a real implementation and tested with a real sandbox-backed rollout.

Acceptance criteria

  • A reviewed architecture decision defines the supported patterns, threat boundaries, ownership model, safe defaults, and whether composed sandbox A plus sandbox B topologies are supported.
  • A reviewed engineering proposal identifies which improvements belong in core infrastructure, shared helpers, templates, or documentation, with follow-up implementation work linked from this issue.
  • Each recommended pattern has a maintained implementation path through agreed infrastructure, templates, or a canonical example.
  • Any new abstraction is adopted by at least one real implementation rather than existing only as an unused API.
  • Canonical paths keep provider credentials in the trusted owner by default and handle timeout, cancellation, failure, and cleanup safely.
  • Automated tests and inspected real rollouts validate each canonical path, including the composed topology if it is supported.
  • The documentation provides a decision guide, runnable examples, security and operability considerations, and links from the Sandbox API, Agent server, environment tutorials, docs: comprehensive agent harness reference and selection guide #2372, and canonical READMEs.

Out of scope

  • Completing every existing agent or benchmark migration in this issue. The inventory should capture required migrations as linked follow-up tech-debt issues.
  • Adding or redesigning sandbox providers.

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    usability
    documentation
    on Aug 25, 2026
  2. changed the title [-]docs: define and demonstrate canonical agent/sandbox patterns[/-] [+]epic: canonical agent/sandbox patterns[/+] on Aug 25, 2026
  3. changed the title [-]epic: canonical agent/sandbox patterns[/-] [+]epic: canonical sandbox patterns[/+] on Aug 25, 2026
  4. removed
    usability
    documentation
    on Sep 5, 2026
  5. moved this from Dev Todo to Dev WIP in NeMo Gym 0.7.0 - Oct 7on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions