CliAgentEnv
An environment for executing full agent implementations inside sandboxes, intercepting their API calls to control model interactions.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
- Setup: Create sandbox, start tunnel, upload assets
- Execution: Launch agent via background job
- Interception: Handle each API request as a turn
- Completion: Detect agent exit or timeout
- Cleanup: Destroy sandbox, stop tunnel
Example Usage
Basic Python Agent
With Custom Asset Upload
Per-Task Docker Images
Key Methods
build_env_vars
post_sandbox_setup
post_rollout
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:- Agent process exits (detected via background job polling)
timeout_secondsis exceededmax_turnsis reached
Error Handling
- Sandbox creation failure: Raises
SandboxCreationError - Tunnel failure: Raises
TunnelErrorwith frpc logs - Agent timeout: Sets
state["agent_timed_out"] = True - Infrastructure errors: Sets
state["error"]toInfraErrorinstance
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
- HarborEnv - Specialized for Harbor benchmark tasks
- SandboxEnv - Base sandbox environment
- MultiTurnEnv - Parent multi-turn environment