File size: 5,587 Bytes
9c7e353 b404de3 9c7e353 07a4a25 b404de3 9c7e353 b404de3 07a4a25 b404de3 07a4a25 b404de3 07a4a25 b404de3 07a4a25 b404de3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | ---
title: CloudEnv
emoji: ☁️
colorFrom: blue
colorTo: blue
sdk: docker
pinned: false
app_port: 8000
base_path: /web
tags:
- openenv
---
# CloudEnv
CloudEnv is a modular simulation environment for cloud infrastructure built on OpenEnv, backed by a local AWS emulator. It allows RL and LLM agents to interact with, diagnose, and repair realistic distributed cloud systems.
## Quick Start
```python
from cloudenv import CloudEnvAction, MyEnv
from cloudenv.server.providers.aws.services import AWSService
env = MyEnv.from_docker_image("cloudenv-env:latest")
env.reset()
# Initialize the environment session before taking AWS actions.
env.step(
CloudEnvAction(
episode_id="ep-1",
task_id="easy-task-1",
service=AWSService.INTERNAL,
operation="InitializeEnvironment",
payload={},
)
)
action = CloudEnvAction(
episode_id="ep-1",
task_id="easy-task-1",
service=AWSService.S3,
operation="CreateBucket",
payload={"Bucket": "test-bucket"},
)
result = env.step(action)
print(result.observation)
env.close()
```
## Core Concepts
### Action
```python
# Required once per episode: task_id == pipeline_id
CloudEnvAction(
episode_id="ep-1",
task_id="easy-task-1",
service=AWSService.INTERNAL,
operation="InitializeEnvironment",
payload={},
)
CloudEnvAction(
episode_id="ep-1",
task_id="easy-task-1",
service=AWSService.S3,
operation="PutObject",
payload={"Bucket": "b", "Key": "k", "Body": b"data"},
)
```
### Observation
```json
{
"task_id": "easy-task-1",
"episode_id": "easy-task-episode-1",
"step_count": 3,
"operation_result": {
"service": "s3",
"operation": "PutBucketPolicy",
"status": "SUCCESS"
},
"reward": 0.7,
"done": false,
"current_pipeline_state": {
"s3:bucket_1": [
{
"service": "s3",
"instance": "bucket1",
"policies": []
}
]
}
}
```
## Pipeline API
CloudEnv exposes a lightweight pipeline lifecycle API under `/api/pipelines`:
- `POST /api/pipelines` create and materialize a pipeline.
- `GET /api/pipelines` list pipelines with broken/ideal graphs.
- `GET /api/pipelines/{pipeline_id}` fetch a pipeline.
- `PUT /api/pipelines/{pipeline_id}` rename a pipeline ID.
- `DELETE /api/pipelines/{pipeline_id}` remove a pipeline.
- `GET /api/pipelines/{pipeline_id}/validate` validate policies/config vs ideal.
Example create request:
```bash
curl -X POST http://localhost:8000/api/pipelines \
-H "Content-Type: application/json" \
-d '{
"pipeline_id": "easy-task-1",
"broken_pipeline": { "s3:bucket_1": [{"service": "s3:bucket1","policies": []}] },
"ideal_pipeline": { "s3:bucket_1": [{"service": "s3:bucket1","policies": []}] }
}'
```
`task_id` in `CloudEnvAction` must match the `pipeline_id` created here.
## Inference Script
`cloudenv/inference.py` loads a task JSON (for example
`cloudenv/tasks/easy-task.json`), initializes the environment, registers the
pipeline via `/api/pipelines`, then runs an LLM loop to propose actions until
convergence. Key steps:
- `env.reset()` (no args) and `InitializeEnvironment` to start the episode.
- `register_pipeline()` to create + materialize the broken/ideal graphs.
- Loop guards for repeated actions and no state change.
Key env vars: `TASK_NAME`, `SERVER_URL`, `MODEL_NAME`, `MAX_STEPS`.
## Testing Pipelines
Pipeline test scenarios and solution steps live in
`cloudenv/docs/api/Pipeline Tests/`. Each solution sequence should end with
`done=true` and `reward=0.99` when replayed in order.
Initialize example (required before actions):
```bash
curl --request POST \
--url http://localhost:8000/step \
--header 'content-type: application/json' \
--data '{
"action": {
"service": "internal",
"operation": "InitializeEnvironment",
"task_id": "hard-task-1",
"episode_id": "hard-episode-1"
}
}'
```
Local tests (requires LocalStack/Ministack running at `localhost:4566`):
```bash
pytest cloudenv/tests/test_cloudenv_environment.py
```
## Environment Design
### Engines
- BuildEngine: Creates infrastructure from a sequence of steps
- CorruptionEngine: Injects failures
- RewardEngine: Rewards recovery and penalizes regressions
## Example Build Plan
```python
e, t = "ep-1", "easy-task-1"
steps = [
CloudEnvAction(
episode_id=e,
task_id=t,
service=AWSService.INTERNAL,
operation="InitializeEnvironment",
payload={},
),
CloudEnvAction(
episode_id=e, task_id=t, service=AWSService.IAM, operation="CreateRole", payload={}
),
CloudEnvAction(
episode_id=e,
task_id=t,
service=AWSService.LAMBDA,
operation="CreateFunction",
payload={},
),
CloudEnvAction(
episode_id=e,
task_id=t,
service=AWSService.S3,
operation="CreateBucket",
payload={},
),
]
```
## Running Locally
```bash
uv run --project . server
# or
python -m cloudenv.server.app --port 8000
```
## Docker
```bash
docker build -t cloudenv .
docker run \
--rm \
--name cloudenv \
-p 4566:4566 \
-p 8000:8000 \
cloudenv
```
## Project Structure
```
cloudenv/
├── client.py
├── inference.py
├── models.py
├── openenv.yaml
├── tasks/
├── docs/
│ └── api/Pipeline Tests/
├── tests/
├── server/
│ ├── app.py
│ ├── api/pipeline/
│ ├── cloudenv_environment.py
│ ├── managers/
│ └── providers/aws/
```
## Deployment
```bash
openenv push
``` |