Skip to main content

CliAgentEnv

An environment for executing full agent implementations inside sandboxes, intercepting their API calls to control model interactions.
CliAgentEnv is experimental and subject to breaking changes. The API may change in future releases.

Overview

CliAgentEnv enables running arbitrary agent code (Python scripts, Node.js apps, etc.) in isolated sandbox containers. It:
  • Intercepts the agent’s API requests via HTTP proxy
  • Translates requests to Verifiers’ multi-turn rollout loop
  • Manages sandbox lifecycle and resource provisioning
  • Monitors agent process completion and timeouts

Inheritance

Constructor

str
required
Command to start the agent inside the sandbox (e.g., "python agent.py").
int
default:"8765"
Local port for the HTTP interception server.
str | None
default:"None"
Optional external URL for interception. If None, uses Prime Tunnel.
int
default:"-1"
Maximum API calls per rollout. -1 for unlimited.
float
default:"3600.0"
Rollout timeout in seconds.
float
default:"5.0"
Interval for checking agent completion.
str
default:"python:3.11-slim"
Docker image for the sandbox.
str
default:"tail -f /dev/null"
Initial command to keep sandbox alive.
int
default:"1"
CPU cores allocated to sandbox.
int
default:"2"
Memory in GB allocated to sandbox.
int
default:"5"
Disk size in GB for sandbox.
int
default:"0"
Number of GPUs allocated to sandbox.
dict[str, str] | None
Custom environment variables for the sandbox.

How It Works

1. Interception Setup

2. Environment Variables

The agent receives:

3. Lifecycle

  1. Setup: Create sandbox, start tunnel, upload assets
  2. Execution: Launch agent via background job
  3. Interception: Handle each API request as a turn
  4. Completion: Detect agent exit or timeout
  5. Cleanup: Destroy sandbox, stop tunnel

Example Usage

Basic Python Agent

With Custom Asset Upload

Per-Task Docker Images

Key Methods

build_env_vars

Build environment variables for the sandbox. Override to add custom variables:

post_sandbox_setup

Hook called after sandbox creation but before agent starts. Use for file uploads, dependency installation, etc.

post_rollout

Hook called after agent completes but before sandbox destruction. Use for extracting artifacts or computing rewards that require sandbox access:

State Keys

CliAgentEnv adds these state keys:
str
Unique identifier for this rollout.
str
Prime Sandbox ID.
str
Full interception URL with rollout ID.
bool
Whether the agent process has finished.
int
Agent process exit code.
str
Captured stdout from agent.
str
Captured stderr from agent.
bool
Whether agent exceeded timeout.

Stop Conditions

Rollout stops when:
  1. Agent process exits (detected via background job polling)
  2. timeout_seconds is exceeded
  3. max_turns is reached

Error Handling

  • Sandbox creation failure: Raises SandboxCreationError
  • Tunnel failure: Raises TunnelError with frpc logs
  • Agent timeout: Sets state["agent_timed_out"] = True
  • Infrastructure errors: Sets state["error"] to InfraError instance

Debugging

Enable detailed logging:

Limitations

  • Streaming: Agent must use non-streaming API calls (streaming synthesis is WIP)
  • Tool calls: Agent can use tools, but schemas are normalized to OpenAI format
  • Timeouts: Long-running agents may hit sandbox timeout limits

See Also