"""FastAPI application for the DNS-Env OpenEnv environment. Exposes the DNS zone-file debugging environment over HTTP so that remote agents (or a HuggingFace Spaces front-end) can interact with it via the standard OpenEnv ``/reset``, ``/step``, ``/state`` endpoints. """ from __future__ import annotations from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse # --------------------------------------------------------------------------- # Dual-import pattern -- works as a sub-package *and* when run directly. # --------------------------------------------------------------------------- try: from .dns_environment import DNSEnvironment except ImportError: from dns_environment import DNSEnvironment # type: ignore[no-redef] try: from ..models import Action, Observation, State except ImportError: from models import Action, Observation, State # type: ignore[no-redef] try: from .tasks import TASK_IDS except ImportError: from tasks import TASK_IDS # type: ignore[no-redef] # --------------------------------------------------------------------------- # Application setup # --------------------------------------------------------------------------- app = FastAPI( title="DNS-Env", description="DNS Zone File Debugging Environment for OpenEnv", version="0.1.0", ) # Allow all origins so HuggingFace Spaces (and other frontends) can call us. app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # --------------------------------------------------------------------------- # Session management # --------------------------------------------------------------------------- environments: dict[str, DNSEnvironment] = {} def get_env(session_id: str = "default") -> DNSEnvironment: """Return the environment for *session_id*, creating one if needed.""" if session_id not in environments: environments[session_id] = DNSEnvironment() return environments[session_id] # --------------------------------------------------------------------------- # Endpoints # --------------------------------------------------------------------------- _LANDING_HTML = """\
DNS Zone File Debugging Environment for OpenEnv — Train AI agents to diagnose and fix real-world DNS misconfigurations.
Fix broken records in example.com — missing trailing dots, invalid IPs, malformed MX. The classic DNS gotchas that cause real outages.
Set up complete email delivery for acme.co — MX records, SPF authorization, DMARC policy. 80% of domains get this wrong.
Repair broken NS delegation across parent.org and dev.parent.org — fix glue records, NS consistency, SOA serials.
Deterministic grading via zone-file parsing and record matching. Partial credit for incremental progress.
| Method | Endpoint | Description |
|---|---|---|
| GET | /health | Liveness probe |
| POST | /reset | Start a new episode with a task |
| POST | /step | Execute an action (view, edit, dig, submit) |
| GET | /state | Current episode state |
| GET | /tasks | List available tasks |
| GET | /docs | Interactive Swagger UI |
Click to run a live interaction against this environment: