> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openreward.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Development

> Test environments locally before deploying to OpenReward

## Overview

You can develop and test OpenReward environments locally before deploying to production. This enables:

* **Rapid Iteration**: Test changes instantly without waiting for deployments
* **Debugging**: Use debuggers and inspect environment behavior
* **Offline Development**: Work without internet connection
* **Cost Savings**: No cloud resources used during development

## Quick Start: Testing Environments Locally

### 1. Install Dependencies

```bash theme={null}
pip install openreward
```

### 2. Write Your Environment Server

```python theme={null}
# server.py
from openreward.environments import Environment, Server, Split, TextBlock, ToolOutput, tool
from pydantic import BaseModel

class AnswerParams(BaseModel):
    answer: str

class MyEnvironment(Environment):
    """A simple math environment"""

    @classmethod
    def list_tasks(cls, split: str):
        return [
            {"id": "task-1", "problem": "What is 2+2?", "answer": 4},
            {"id": "task-2", "problem": "What is 5*3?", "answer": 15},
        ]

    @classmethod
    def list_splits(cls):
        return [Split(name="train", type="train"), Split(name="test", type="test")]

    def get_prompt(self):
        return [TextBlock(type="text", text=self.task_spec["problem"])]

    @tool
    def answer(self, params: AnswerParams) -> ToolOutput:
        """Submit your answer"""
        correct = str(self.task_spec["answer"]) == params.answer
        return ToolOutput(
            blocks=[TextBlock(type="text", text="Correct!" if correct else "Wrong!")],
            reward=1.0 if correct else 0.0,
            finished=True
        )

if __name__ == "__main__":
    Server([MyEnvironment]).run()
```

### 3. Run the Server

```bash theme={null}
python server.py
```

Output:

```
INFO:     Started server process [12345]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8080
```

### 4. Test the Environment

```python theme={null}
# test_environment.py
from openreward import OpenReward

or_client = OpenReward(base_url="http://localhost:8080") # you must point towards the environment if running locally

# Connect to local server (no namespace = localhost)
environment = or_client.environments.get(name="myenvironment")

# List tasks
tasks = environment.list_tasks(split="train")
print(f"Found {len(tasks)} tasks")

# Create session and test tool
with environment.session(task=tasks[0]) as session:
    prompt = session.get_prompt()
    print(f"Prompt: {prompt[0].text}")

    result = session.call_tool("answer", {"answer": "4"})
    print(f"Result: {result.blocks[0].text}")
    print(f"Reward: {result.reward}")
```

Alternatively, if you don't want the whole client to point to `http://localhost:8080`

just change the base\_url when getting the environment, like this:

```python theme={null}
environment = or_client.environments.get(name="myenvironment", base_url="http://localhost:8080")
```

Run:

```bash theme={null}
python test_environment.py
```

Output:

```
Found 2 tasks
Prompt: What is 2+2?
Result: Correct!
Reward: 1.0
```

## Local Development with Docker

### Build and Run Locally

```bash theme={null}
# Build Docker image
docker build -t my-environment:local .

# Run container
docker run -p 8080:8080 my-environment:local

# Test from another terminal
python test_environment.py
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Your First Environment" icon="rocket" href="/environments/your-first-environment">
    Complete tutorial for building an environment
  </Card>

  <Card title="GitHub Deployment" icon="github" href="/deployment/github-integration">
    Deploy your local environment to OpenReward
  </Card>

  <Card title="Secret Management" icon="key" href="/deployment/secrets">
    Manage secrets in local and production environments
  </Card>

  <Card title="Environments" icon="server" href="/concepts/environments">
    Understand environment architecture
  </Card>
</CardGroup>
