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

# Execute Code

> Run a command inside the sandbox workspace.

## Endpoint

```http theme={null}
POST /v1/sandboxes/{id}/exec
```

## Parameters

| Parameter | Type   | Required | Description                      |
| --------- | ------ | -------- | -------------------------------- |
| `id`      | string | Yes      | Sandbox ID returned from create. |

## Request

```json theme={null}
{
  "command": "python app.py",
  "test": false
}
```

| Field     | Type    | Required | Description                                                                                                               |
| --------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| `command` | string  | Yes      | The command to run inside the workspace. Mirrors what you would type in your terminal.                                    |
| `test`    | boolean | No       | When `true`, Petri runs the command, waits 2 seconds, then runs the language-appropriate test suite. Defaults to `false`. |

## Response

```json theme={null}
{
  "output": "hello from jhansi.io\n"
}
```

## Examples

### Run a script

```bash theme={null}
curl -X POST http://localhost:8000/v1/sandboxes/sb_abc123/exec \
  -H "Content-Type: application/json" \
  -d '{"command": "python app.py"}'
```

### Run a server and test it

```bash theme={null}
curl -X POST http://localhost:8000/v1/sandboxes/sb_abc123/exec \
  -H "Content-Type: application/json" \
  -d '{"command": "uvicorn app:app", "test": true}'
```

## Test runners

When `test: true`, Petri runs the appropriate test suite automatically:

| Language | Runner   | Discovery             |
| -------- | -------- | --------------------- |
| Python   | pytest   | `tests/` directory    |
| Node     | jest     | `*.test.js` files     |
| Go       | go test  | `./...`               |
| Java     | mvn test | Maven/Gradle standard |

<Note>
  `filename` has been replaced by `command` in v0.4.0 — a breaking change.
  Pass the full command you would run in your terminal, e.g. `python app.py` or `uvicorn app:app`.
</Note>
