CLI Usage
The ERA Agent CLI provides direct command-line access to all VM management features. Perfect for quick testing, automation scripts, and manual session management.
Installation
Section titled “Installation”# Clone and buildgit clone https://github.com/yourusername/era-agentcd era-agentgo build -o agent
# Make it executablechmod +x agent
# Optional: Add to PATHsudo mv agent /usr/local/bin/Command Structure
Section titled “Command Structure”agent [global-options] <command> [command-options]Global Options
Section titled “Global Options”--log-level <level> # Set log level: debug, info, warn, errorExamples:
agent --log-level debug vm listagent --log-level info vm create --language pythonAvailable Commands
Section titled “Available Commands”agent vm create - Create VM Session
Section titled “agent vm create - Create VM Session”Create a new isolated VM session for code execution.
Syntax:
agent vm create --language <lang> [options]Required:
--language <lang>- Language: python, node, typescript, go, deno
Optional:
--image <image>- Custom rootfs image (advanced)--cpu <count>- CPU count (default: 1)--mem <mib>- Memory in MiB (default: 256)--network <mode>- Network mode: none (default), allow_all--persist- Enable persistence for this session
Examples:
Basic Python session:
agent vm create --language python# Output: Created session: abc-123-xyzHigh-resource Node.js session:
agent vm create \ --language node \ --cpu 2 \ --mem 512Session with network access:
agent vm create \ --language python \ --network allow_allPersistent session:
agent vm create \ --language python \ --persistagent vm run - Execute Code
Section titled “agent vm run - Execute Code”Run code in an existing VM session.
Syntax:
agent vm run --vm <id> [--cmd <command>] [--file <path>] [options]Required:
--vm <id>- Session ID fromvm create
Execution Method (choose one):
--cmd <command>- Direct command to execute--file <path>- Path to file to execute
Optional:
--timeout <seconds>- Execution timeout (default: 30)
Examples:
Execute direct command:
agent vm run \ --vm abc-123-xyz \ --cmd "python -c 'print(2 + 2)'"Execute from file:
agent vm run \ --vm abc-123-xyz \ --file ./script.pyWith timeout:
agent vm run \ --vm abc-123-xyz \ --cmd "python long_running.py" \ --timeout 60Output Format:
Exit Code: 0
Stdout:4
Stderr:(empty)
Duration: 1.23sagent vm list - List Sessions
Section titled “agent vm list - List Sessions”List all active VM sessions.
Syntax:
agent vm listExample:
agent vm listOutput:
[ { "id": "abc-123-xyz", "language": "python", "cpu_count": 1, "memory_mib": 256, "network_mode": "none", "persist": false, "status": "ready", "created_at": "2025-01-15T10:30:00Z", "last_run_at": "2025-01-15T10:35:00Z" }]agent vm get - Get Session Details
Section titled “agent vm get - Get Session Details”Get detailed information about a specific session.
Syntax:
agent vm get --vm <id>Example:
agent vm get --vm abc-123-xyzOutput:
{ "id": "abc-123-xyz", "language": "python", "rootfs_image": "python:3.11", "cpu_count": 1, "memory_mib": 256, "network_mode": "none", "persist": false, "status": "ready", "created_at": "2025-01-15T10:30:00Z", "last_run_at": "2025-01-15T10:35:00Z"}agent vm stop - Stop Session
Section titled “agent vm stop - Stop Session”Stop a running session (keeps state for later restart).
Syntax:
agent vm stop --vm <id>Example:
agent vm stop --vm abc-123-xyzagent vm clean - Delete Session
Section titled “agent vm clean - Delete Session”Permanently delete a session and clean up resources.
Syntax:
agent vm clean --vm <id> [--keep-persist]Options:
--keep-persist- Keep persistent storage even after deletion
Examples:
Delete session completely:
agent vm clean --vm abc-123-xyzDelete but keep persistent data:
agent vm clean --vm abc-123-xyz --keep-persistagent serve - Start HTTP Server
Section titled “agent serve - Start HTTP Server”Start ERA Agent as an HTTP API server.
Syntax:
agent serveEnvironment Variables:
PORT=8787 # Server port (default: 8787)AGENT_LOG_LEVEL=info # Log levelExample:
PORT=9000 agent serveSee HTTP Server Mode for complete API documentation.
agent mcp - Start MCP Server
Section titled “agent mcp - Start MCP Server”Start ERA Agent as an MCP server for Claude Desktop integration.
Syntax:
agent mcpEnvironment Variables:
AGENT_LOG_LEVEL=info # Log levelAGENT_STATE_DIR=/path # State directoryExample:
AGENT_LOG_LEVEL=debug agent mcpSee MCP Server Setup for Claude Desktop configuration.
agent --help / agent -h / agent help
Section titled “agent --help / agent -h / agent help”Display help information.
agent --helpCommon Workflows
Section titled “Common Workflows”Quick Script Execution
Section titled “Quick Script Execution”Run a one-off Python script:
# Create sessionSESSION_ID=$(agent vm create --language python | grep -o '[a-z0-9-]*')
# Run scriptagent vm run --vm $SESSION_ID --file script.py
# Clean upagent vm clean --vm $SESSION_IDStateful Multi-Step Execution
Section titled “Stateful Multi-Step Execution”Execute multiple steps with shared state:
# Create persistent sessionSESSION_ID=$(agent vm create --language python --persist | grep -o '[a-z0-9-]*')
# Step 1: Initialize dataagent vm run --vm $SESSION_ID --cmd "python -c 'data = [1, 2, 3, 4, 5]; print(data)'"
# Step 2: Process data (state persists)agent vm run --vm $SESSION_ID --cmd "python -c 'result = sum(data); print(f\"Sum: {result}\")'"
# Step 3: More processingagent vm run --vm $SESSION_ID --cmd "python -c 'avg = sum(data) / len(data); print(f\"Average: {avg}\")'"
# Clean up when doneagent vm clean --vm $SESSION_IDPackage Installation
Section titled “Package Installation”Install packages in a session:
# Create sessionSESSION_ID=$(agent vm create --language python --network allow_all | grep -o '[a-z0-9-]*')
# Install packagesagent vm run --vm $SESSION_ID --cmd "pip install requests numpy"
# Use packagesagent vm run --vm $SESSION_ID --cmd "python -c 'import requests; print(requests.get(\"https://api.github.com\").status_code)'"
# Clean upagent vm clean --vm $SESSION_IDTesting Multiple Languages
Section titled “Testing Multiple Languages”Test code across different runtimes:
#!/bin/bash
# Test in PythonPY_ID=$(agent vm create --language python | grep -o '[a-z0-9-]*')agent vm run --vm $PY_ID --cmd "python -c 'print(\"Hello from Python\")'"agent vm clean --vm $PY_ID
# Test in Node.jsNODE_ID=$(agent vm create --language node | grep -o '[a-z0-9-]*')agent vm run --vm $NODE_ID --cmd "node -e 'console.log(\"Hello from Node.js\")'"agent vm clean --vm $NODE_ID
# Test in DenoDENO_ID=$(agent vm create --language deno | grep -o '[a-z0-9-]*')agent vm run --vm $DENO_ID --cmd "deno eval 'console.log(\"Hello from Deno\")'"agent vm clean --vm $DENO_IDShell Integration
Section titled “Shell Integration”Bash Helper Functions
Section titled “Bash Helper Functions”Add to your ~/.bashrc or ~/.bash_profile:
# Quick Python executionera-python() { local session_id=$(agent vm create --language python | grep -o '[a-z0-9-]*') agent vm run --vm $session_id --cmd "python -c '$1'" agent vm clean --vm $session_id}
# Quick Node.js executionera-node() { local session_id=$(agent vm create --language node | grep -o '[a-z0-9-]*') agent vm run --vm $session_id --cmd "node -e '$1'" agent vm clean --vm $session_id}
# Create and remember sessionera-session() { local language=$1 export ERA_SESSION=$(agent vm create --language $language | grep -o '[a-z0-9-]*') echo "Created session: $ERA_SESSION"}
# Run in current sessionera-run() { agent vm run --vm $ERA_SESSION --cmd "$1"}
# Clean up current sessionera-done() { agent vm clean --vm $ERA_SESSION unset ERA_SESSION}Usage:
# Quick executionera-python "print(2 + 2)"
# Session workflowera-session pythonera-run "python -c 'x = 42; print(x)'"era-run "python -c 'print(x * 2)'" # State persistsera-doneFish Shell Functions
Section titled “Fish Shell Functions”Add to your ~/.config/fish/config.fish:
function era-python set session_id (agent vm create --language python | grep -o '[a-z0-9-]*') agent vm run --vm $session_id --cmd "python -c '$argv'" agent vm clean --vm $session_idend
function era-session set -gx ERA_SESSION (agent vm create --language $argv[1] | grep -o '[a-z0-9-]*') echo "Created session: $ERA_SESSION"end
function era-run agent vm run --vm $ERA_SESSION --cmd "$argv"end
function era-done agent vm clean --vm $ERA_SESSION set -e ERA_SESSIONendAutomation Scripts
Section titled “Automation Scripts”CI/CD Integration
Section titled “CI/CD Integration”#!/bin/bash# test-runner.sh - Run tests in isolated environment
set -e
echo "Creating test environment..."SESSION_ID=$(agent vm create \ --language python \ --network allow_all \ | grep -o '[a-z0-9-]*')
echo "Installing dependencies..."agent vm run --vm $SESSION_ID --cmd "pip install -r requirements.txt"
echo "Running tests..."agent vm run --vm $SESSION_ID --cmd "pytest tests/" --timeout 300
echo "Cleaning up..."agent vm clean --vm $SESSION_ID
echo "Tests passed! ✅"Batch Processing
Section titled “Batch Processing”#!/bin/bash# process-files.sh - Process multiple files
SESSION_ID=$(agent vm create --language python | grep -o '[a-z0-9-]*')
for file in data/*.csv; do echo "Processing $file..." agent vm run \ --vm $SESSION_ID \ --file process.py \ --timeout 60done
agent vm clean --vm $SESSION_IDScheduled Tasks
Section titled “Scheduled Tasks”#!/bin/bash# cron-task.sh - Run scheduled data processing
SESSION_ID=$(agent vm create \ --language python \ --persist \ --network allow_all \ | grep -o '[a-z0-9-]*')
# Fetch and process dataagent vm run --vm $SESSION_ID --cmd "python fetch_data.py"agent vm run --vm $SESSION_ID --cmd "python process_data.py"agent vm run --vm $SESSION_ID --cmd "python send_report.py"
agent vm clean --vm $SESSION_IDAdd to crontab:
# Run every day at 2 AM0 2 * * * /path/to/cron-task.sh >> /var/log/era-agent.log 2>&1Tips and Tricks
Section titled “Tips and Tricks”Session ID Management
Section titled “Session ID Management”Save session IDs for later use:
# Save to fileagent vm create --language python | grep -o '[a-z0-9-]*' > session.txt
# Use lateragent vm run --vm $(cat session.txt) --cmd "python script.py"Output Parsing
Section titled “Output Parsing”Extract specific output:
# Get exit codeagent vm run --vm $ID --cmd "python script.py" | grep "Exit Code:" | awk '{print $3}'
# Get stdout onlyagent vm run --vm $ID --cmd "python script.py" | sed -n '/Stdout:/,/Stderr:/p' | grep -v "Stdout:" | grep -v "Stderr:"Error Handling
Section titled “Error Handling”#!/bin/bash
SESSION_ID=$(agent vm create --language python | grep -o '[a-z0-9-]*')
# Run with error checkingif agent vm run --vm $SESSION_ID --cmd "python script.py" | grep -q "Exit Code: 0"; then echo "Success!"else echo "Failed!" exit 1fi
agent vm clean --vm $SESSION_IDTimeout Management
Section titled “Timeout Management”For long-running tasks:
# Set generous timeoutagent vm run \ --vm $SESSION_ID \ --cmd "python long_task.py" \ --timeout 600 # 10 minutesTroubleshooting
Section titled “Troubleshooting”Command Not Found
Section titled “Command Not Found”# Check if agent is in PATHwhich agent
# If not, use full path/path/to/agent vm create --language pythonSession Not Found
Section titled “Session Not Found”# List all sessionsagent vm list
# Verify session IDagent vm get --vm <id>Timeout Errors
Section titled “Timeout Errors”# Increase timeoutagent vm run --vm $ID --cmd "..." --timeout 120
# Or create session with higher defaultagent vm create --language python # Use session-level timeout via APIPermission Denied
Section titled “Permission Denied”# Make binary executablechmod +x agent
# Check Docker/Firecracker permissionsdocker ps # macOSls -l /dev/kvm # LinuxNext Steps
Section titled “Next Steps”- MCP Server Setup - Use with Claude Desktop
- HTTP Server Mode - API integration
- API Reference - Full API documentation
- Language Examples - Language-specific guides