nat.tool.code_execution.code_sandbox#

Attributes#

Classes#

Sandbox

Code execution sandbox.

LocalSandbox

Locally hosted sandbox.

PistonSandbox

Piston sandbox (engineer-man/piston)

Functions#

get_sandbox([sandbox_type])

A helper function to make it easier to set sandbox through cmd.

Module Contents#

logger#
class Sandbox(*, uri: pydantic.HttpUrl)#

Bases: abc.ABC

Code execution sandbox.

Args:
host: Optional[str] = ‘127.0.0.1’ - Host of the sandbox server.

Can also be specified through NEMO_SKILLS_SANDBOX_HOST env var.

port: Optional[str] = ‘5000’ - Port of the sandbox server.

Can also be specified through NEMO_SKILLS_SANDBOX_PORT env var.

ssh_server: Optional[str] = None - SSH server for tunneling requests.

Useful if server is running on slurm cluster to which there is an ssh access. Can also be specified through NEMO_SKILLS_SSH_SERVER env var.

ssh_key_path: Optional[str] = None - Path to the ssh key for tunneling.

Can also be specified through NEMO_SKILLS_SSH_KEY_PATH env var.

url: str#
http_session: requests.Session#
_send_request(
request: dict[str, Any],
timeout_seconds: float,
) dict[str, str]#
abstractmethod _parse_request_output(output: requests.Response) dict[str, str]#
abstractmethod _get_execute_url(uri: pydantic.HttpUrl) str#
abstractmethod _prepare_request(
generated_code: str,
timeout_seconds: float,
) dict[str, Any]#
async execute_code(
generated_code: str,
timeout_seconds: float = 10.0,
language: str = 'python',
max_output_characters: int = 1000,
) dict[str, str]#
class LocalSandbox(*, uri: pydantic.HttpUrl)#

Bases: Sandbox

Locally hosted sandbox.

_get_execute_url(uri: pydantic.HttpUrl) str#
_parse_request_output(output: requests.Response) dict[str, str]#
_prepare_request(
generated_code: str,
timeout_seconds: float,
language: str = 'python',
**kwargs,
) dict[str, Any]#
async execute_code(
generated_code: str,
timeout_seconds: float = 10.0,
language: str = 'python',
max_output_characters: int = 1000,
) dict[str, str]#

Override execute_code to bypass the wrapper logic and send user code directly to our server.

class PistonSandbox(*, uri: pydantic.HttpUrl)#

Bases: Sandbox

Piston sandbox (engineer-man/piston)

_get_execute_url(uri: pydantic.HttpUrl) str#
_parse_request_output(output: requests.Response) dict[str, str]#
_prepare_request(
generated_code: str,
timeout_seconds: float,
**kwargs,
) dict[str, Any]#
get_sandbox(sandbox_type: str = 'local', **kwargs)#

A helper function to make it easier to set sandbox through cmd.