API Reference
This guide provides detailed information about the core API services provided by the ROCK platform, including sandbox environment management and GEM environment interaction.
Table of Contents
1. Overview
The ROCK platform provides two core API services:
- Sandbox API: Sandbox environment management
- GEM API: GEM environment interaction
All API interfaces follow RESTful design principles and support JSON format data exchange.
2. Sandbox API
Full lifecycle management functions for sandbox environments:
Sandbox Management Interfaces
-
Start Sandbox - Start a sandbox environment
- Create a new sandbox instance
- Support specifying image, resource configuration and other parameters
-
Start Sandbox Async - Asynchronously start a sandbox environment
- Asynchronously create a sandbox instance
- Suitable for scenarios requiring quick response
-
Check Sandbox Alive Status - Check sandbox alive status
- Verify if the sandbox is running normally
-
Get Sandbox Statistics - Get sandbox statistics
- Get resource usage statistics of the sandbox
-
Get Sandbox Status - Get detailed sandbox status
- Get complete status information of the sandbox
-
Stop Sandbox - Stop sandbox environment
- Safely shut down the sandbox instance
-
Commit Sandbox - Commit sandbox as image
- Save current sandbox state as a new image
Command Execution Interfaces
-
Execute Command - Execute command in sandbox
- Run specified command directly in the sandbox
-
Create Bash Session - Create Bash session
- Create a persistent Bash session environment
-
Run Command in Session - Run command in session
- Execute command in a created session
-
Close Session - Close session
- Release session resources
File Operation Interfaces
-
Read File - Read sandbox file
- Read specified file content from the sandbox
-
Write File - Write sandbox file
- Write file to the sandbox
-
Upload File - Upload file to sandbox
- Upload local file to the sandbox
3. GEM API
GEM environment interaction functions:
-
Make Environment - Create GEM environment
- Initialize a new GEM environment instance
-
Reset Environment - Reset GEM environment
- Reset GEM environment to initial state
-
Step Environment - Execute GEM environment step
- Execute an action step in the GEM environment
-
Close Environment - Close GEM environment
- Release GEM environment resources
4. HTTP API Usage Examples
4.1 Sandbox API Examples
Start Sandbox
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/start' \
-H 'Content-Type: application/json' \
-d '{
"image": "python:3.11",
"resources": {
"cpu": "2",
"memory": "8g"
}
}'
Asynchronously Start Sandbox
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/start_async' \
-H 'Content-Type: application/json' \
-d '{
"image": "python:3.11",
"resources": {
"cpu": "2",
"memory": "8g"
}
}'
Execute Command
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/execute' \
-H 'Content-Type: application/json' \
-d '{
"sandbox_id": "sandbox-12345",
"command": "ls -la"
}'
Create Session
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/create_session' \
-H 'Content-Type: application/json' \
-d '{
"sandbox_id": "sandbox-12345",
"session": "my_session"
}'
Run Command in Session
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/run_in_session' \
-H 'Content-Type: application/json' \
-d '{
"sandbox_id": "sandbox-12345",
"session": "my_session",
"command": "python script.py"
}'
Upload File
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/upload' \
-F 'file=@./local_file.txt' \
-F 'target_path=./remote_file.txt' \
-F 'sandbox_id=sandbox-12345'
Stop Sandbox
curl -X POST 'http://localhost:8080/apis/envs/sandbox/v1/stop' \
-H 'Content-Type: application/json' \
-d '{
"sandbox_id": "sandbox-12345"
}'
4.2 GEM API Examples
# Create GEM environment
curl -X POST 'http://localhost:8080/apis/v1/envs/gem/make' \
-H 'Content-Type: application/json' \
-d '{"env_id": "game:Sokoban-v0-easy"}'
# Reset environment
curl -X POST 'http://localhost:8080/apis/v1/envs/gem/reset' \
-H 'Content-Type: application/json' \
-d '{"sandbox_id": "sandbox-12345", "seed": 42}'
# Execute step
curl -X POST 'http://localhost:8080/apis/v1/envs/gem/step' \
-H 'Content-Type: application/json' \
-d '{"sandbox_id": "sandbox-12345", "action": "random_action"}'
# Close environment
curl -X POST 'http://localhost:8080/apis/v1/envs/gem/close' \
-H 'Content-Type: application/json' \
-d '{"sandbox_id": "sandbox-12345"}'
Related Documents
- Quick Start Guide - Learn how to quickly get started with ROCK API
- SDK Documentation - Learn how to use the SDK to call APIs
- Configuration Guide - Learn about API-related configuration options
- Installation Guide - Detailed information about ROCK installation and setup