That's it! The IdorHuntEnv.from_docker_image() method handles:
Starting the Docker container
Waiting for the server to be ready
Connecting to the environment
Container cleanup when you call close()
Building the Docker Image
Before using the environment, you need to build the Docker image:
bash
1# From project root2docker build -t idor_hunt_env-env:latest -f server/Dockerfile .
Deploying to Hugging Face Spaces
You can easily deploy your OpenEnv environment to Hugging Face Spaces using the openenv push command:
bash
1# From the environment directory (where openenv.yaml is located)2openenv push
34# Or specify options5openenv push --namespace my-org --private
The openenv push command will:
Validate that the directory is an OpenEnv environment (checks for openenv.yaml)
Prepare a custom build for Hugging Face Docker space (enables web interface)
Upload to Hugging Face (ensuring you're logged in)
Prerequisites
Authenticate with Hugging Face: The command will prompt for login if not already authenticated
Options
--directory, -d: Directory containing the OpenEnv environment (defaults to current directory)
--repo-id, -r: Repository ID in format 'username/repo-name' (defaults to 'username/env-name' from openenv.yaml)
--base-image, -b: Base Docker image to use (overrides Dockerfile FROM)
--private: Deploy the space as private (default: public)
Examples
bash
1# Push to your personal namespace (defaults to username/env-name from openenv.yaml)2openenv push
34# Push to a specific repository5openenv push --repo-id my-org/my-env
67# Push with a custom base image8openenv push --base-image ghcr.io/meta-pytorch/openenv-base:latest
910# Push as a private space11openenv push --private
1213# Combine options14openenv push --repo-id my-org/my-env --base-image custom-base:latest --private
After deployment, your space will be available at:
https://huggingface.co/spaces/<repo-id>
The deployed space includes:
Web Interface at /web - Interactive UI for exploring the environment
API Documentation at /docs - Full OpenAPI/Swagger interface
Health Check at /health - Container health monitoring
WebSocket at /ws - Persistent session endpoint for low-latency interactions
Environment Details
Action
IdorHuntAction: Contains a single field
message (str) - The message to echo back
Observation
IdorHuntObservation: Contains the echo response and metadata
echoed_message (str) - The message echoed back
message_length (int) - Length of the message
reward (float) - Reward based on message length (length × 0.1)
done (bool) - Always False for echo environment
metadata (dict) - Additional info like step count
Reward
The reward is calculated as: message_length × 0.1
"Hi" → reward: 0.2
"Hello, World!" → reward: 1.3
Empty message → reward: 0.0
Advanced Usage
Connecting to an Existing Server
If you already have a Idor Hunt Env environment server running, you can connect directly:
python
1from idor_hunt_env import IdorHuntEnv
23# Connect to existing server4idor_hunt_envenv = IdorHuntEnv(base_url="<ENV_HTTP_URL_HERE>")56# Use as normal7result = idor_hunt_envenv.reset()8result = idor_hunt_envenv.step(IdorHuntAction(message="Hello!"))
Note: When connecting to an existing server, idor_hunt_envenv.close() will NOT stop the server.
Using the Context Manager
The client supports context manager usage for automatic connection management:
python
1from idor_hunt_env import IdorHuntAction, IdorHuntEnv
23# Connect with context manager (auto-connects and closes)4with IdorHuntEnv(base_url="http://localhost:8000")as env:5 result = env.reset()6print(f"Reset: {result.observation.echoed_message}")7# Multiple steps with low latency8for msg in["Hello","World","!"]:9 result = env.step(IdorHuntAction(message=msg))10print(f"Echoed: {result.observation.echoed_message}")
The client uses WebSocket connections for:
Lower latency: No HTTP connection overhead per request
Persistent session: Server maintains your environment state
Efficient for episodes: Better for many sequential steps
Concurrent WebSocket Sessions
The server supports multiple concurrent WebSocket connections. To enable this,
modify server/app.py to use factory mode:
python
1# In server/app.py - use factory mode for concurrent sessions2app = create_app(3 IdorHuntEnvironment,# Pass class, not instance4 IdorHuntAction,5 IdorHuntObservation,6 max_concurrent_envs=4,# Allow 4 concurrent sessions7)
Then multiple clients can connect simultaneously:
python
1from idor_hunt_env import IdorHuntAction, IdorHuntEnv
2from concurrent.futures import ThreadPoolExecutor
34defrun_episode(client_id:int):5with IdorHuntEnv(base_url="http://localhost:8000")as env:6 result = env.reset()7for i inrange(10):8 result = env.step(IdorHuntAction(message=f"Client {client_id}, step {i}"))9return client_id, result.observation.message_length
1011# Run 4 episodes concurrently12with ThreadPoolExecutor(max_workers=4)as executor:13 results =list(executor.map(run_episode,range(4)))
Development & Testing
Direct Environment Testing
Test the environment logic directly without starting the HTTP server:
bash
1# From the server directory2python3 server/idor_hunt_env_environment.py