Skip to navigation

nemo_gym.agents.utils.agent_context

View as MarkdownOpen in Claude

Resolve the files an agent session’s agent_context names.

Module Contents

Functions

NameDescription
resolve_agent_context_artifactThe artifact’s path under root, checked to stay inside it, through symlinks too, and to be a kind.

Data

_PATH_ERRNOS

API

nemo_gym.agents.utils.agent_context.resolve_agent_context_artifact(
root: pathlib.Path,
kind: typing.Literal['file', 'directory']
) -> pathlib.Path

The artifact’s path under root, checked to stay inside it, through symlinks too, and to be a kind.

Raises AgentSeedRejectedError otherwise, or when the path cannot be looked up (too long, no permission), so an agent that resolves its artifacts while seeding refuses the session with a terminal 422 instead of failing its first activation. The check runs on resolved paths: a directory under root that is a symlink to other storage counts as outside, so configure the real directory as the root.

For a directory, only the directory itself is checked. Files under it can be symlinks to anywhere, so an agent that reads them resolves each one and checks that it stays under the returned directory.

nemo_gym.agents.utils.agent_context._PATH_ERRNOS = frozenset({errno.EACCES, errno.EPERM, errno.ENAMETOOLONG, errno.ELOOP, errno.ENO...