> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.sandbox.process_supervisor

Standalone Linux process supervisor to upload beside a sandboxed harness.

Uses only the standard library; Gym need not be installed in the task sandbox.
The receipt confirms descendant cleanup independently of the worker's result.

## Module Contents

### Classes

| Name                                                                    | Description                                                        |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [`CleanupReceipt`](#nemo_gym-sandbox-process_supervisor-CleanupReceipt) | Outcome written only after supervision and bounded cleanup finish. |

### Functions

| Name                                                                          | Description                                                                      |
| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [`_drain_children`](#nemo_gym-sandbox-process_supervisor-_drain_children)     | Reap tool descendants, including processes that detached with setsid().          |
| [`_positive_seconds`](#nemo_gym-sandbox-process_supervisor-_positive_seconds) | -                                                                                |
| [`_supervise`](#nemo_gym-sandbox-process_supervisor-_supervise)               | Enforce a worker deadline, then acknowledge cleanup after all descendants exit.  |
| [`exec_timeout`](#nemo_gym-sandbox-process_supervisor-exec_timeout)           | Leave room for TERM grace, worker reaping, descendant draining, and receipt I/O. |
| [`main`](#nemo_gym-sandbox-process_supervisor-main)                           | Run COMMAND and atomically write its cleanup receipt outside the task workdir.   |

### Data

[`DEFAULT_CLEANUP_TIMEOUT`](#nemo_gym-sandbox-process_supervisor-DEFAULT_CLEANUP_TIMEOUT)

### API

```python
class nemo_gym.sandbox.process_supervisor.CleanupReceipt
```

**Bases:** `typing.TypedDict`

Outcome written only after supervision and bounded cleanup finish.

**`cleanup_confirmed`** `bool`

---

**`error`** `str | None`

---

**`return_code`** `int | None`

---

**`timed_out`** `bool`

---

```python
nemo_gym.sandbox.process_supervisor._drain_children(
    timeout: float
) -> None
```

Reap tool descendants, including processes that detached with setsid().

```python
nemo_gym.sandbox.process_supervisor._positive_seconds(
    value: str
) -> float
```

```python
nemo_gym.sandbox.process_supervisor._supervise(
    command: list[str],
    timeout: float,
    cleanup_timeout: float = DEFAULT_CLEANUP_TIMEOUT,
    stop_path: pathlib.Path | None = None
) -> nemo_gym.sandbox.process_supervisor.CleanupReceipt
```

Enforce a worker deadline, then acknowledge cleanup after all descendants exit.

```python
nemo_gym.sandbox.process_supervisor.exec_timeout(
    timeout: float,
    cleanup_timeout: float = DEFAULT_CLEANUP_TIMEOUT
) -> float
```

Leave room for TERM grace, worker reaping, descendant draining, and receipt I/O.

```python
nemo_gym.sandbox.process_supervisor.main() -> int
```

Run COMMAND and atomically write its cleanup receipt outside the task workdir.

```python
nemo_gym.sandbox.process_supervisor.DEFAULT_CLEANUP_TIMEOUT = 10.0
```