> This page is for version 0.6.0.
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> 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.tasks.harbor.harbor_compat

Environment content hashing and image naming vendored from Harbor v0.22.0 (Apache-2.0).

Gym builds the images of Harbor tasks with its own tools (buildah, podman or docker; see
`nemo_gym.tasks.harbor.image_build`) but hashes the task's `environment/` folder and names the image
the way Harbor does, so a task prepared by either framework resolves to the same image name. Kept
byte-for-byte so Gym and Harbor compute the same image names for the same build context.

Vendored from [https://github.com/harbor-framework/harbor](https://github.com/harbor-framework/harbor) (Apache-2.0, see `ATTRIBUTIONS.md`):

* `environment_content_hash` and `_CONTENT_HASH_IGNORE_NAMES`:
  [https://github.com/harbor-framework/harbor/blob/v0.22.0/src/harbor/environments/definition.py](https://github.com/harbor-framework/harbor/blob/v0.22.0/src/harbor/environments/definition.py)
* `sanitize_docker_image_name` (`_sanitize_docker_image_name` upstream):
  [https://github.com/harbor-framework/harbor/blob/v0.22.0/src/harbor/environments/docker/docker.py](https://github.com/harbor-framework/harbor/blob/v0.22.0/src/harbor/environments/docker/docker.py)

Harbor's environment id is `environment_content_hash(environment_dir)` and its task image is
`sanitize_docker_image_name(f"hb__&#123;environment_id&#125;")`: `hb__&lt;32 hex characters&gt;`.

## Module Contents

### Functions

| Name                                                                                            | Description                                               |
| ----------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| [`environment_content_hash`](#nemo_gym-tasks-harbor-harbor_compat-environment_content_hash)     | Return a stable SHA-256 hash of the environment contents. |
| [`sanitize_docker_image_name`](#nemo_gym-tasks-harbor-harbor_compat-sanitize_docker_image_name) | Sanitize a name to be a valid Docker image name.          |

### Data

[`_CONTENT_HASH_IGNORE_NAMES`](#nemo_gym-tasks-harbor-harbor_compat-_CONTENT_HASH_IGNORE_NAMES)

### API

```python
nemo_gym.tasks.harbor.harbor_compat.environment_content_hash(
    environment_dir: pathlib.Path,
    docker_image: str | None = None,
    truncate: int = 32
) -> str
```

Return a stable SHA-256 hash of the environment contents.

The result is consistent across Linux and macOS. For an empty environment,
the Docker image reference is hashed instead.

```python
nemo_gym.tasks.harbor.harbor_compat.sanitize_docker_image_name(
    name: str
) -> str
```

Sanitize a name to be a valid Docker image name.

See: [https://github.com/opencontainers/distribution-spec/blob/5e57cc0a07ea002e507a65d4757e823f133fcb52/spec.md#pulling-manifests](https://github.com/opencontainers/distribution-spec/blob/5e57cc0a07ea002e507a65d4757e823f133fcb52/spec.md#pulling-manifests)

```python
nemo_gym.tasks.harbor.harbor_compat._CONTENT_HASH_IGNORE_NAMES = frozenset({'.DS_Store', '.git', '__pycache__'})
```