aiq.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#
http_session#
_send_request(request, timeout)#
abstractmethod _parse_request_output(output)#
abstractmethod _get_execute_url(uri)#
abstractmethod _prepare_request(generated_code, timeout)#
async execute_code(
generated_code: str,
timeout: float = 10.0,
language: str = 'python',
max_output_characters: int = 1000,
) tuple[dict, str]#
class LocalSandbox(*, uri: pydantic.HttpUrl)#

Bases: Sandbox

Locally hosted sandbox.

_get_execute_url(uri)#
_parse_request_output(output)#
_prepare_request(generated_code, timeout, language='python', **kwargs)#
class PistonSandbox(*, uri: pydantic.HttpUrl)#

Bases: Sandbox

Piston sandbox (engineer-man/piston)

_get_execute_url(uri)#
_parse_request_output(output)#
_prepare_request(generated_code: str, timeout, **kwargs)#
sandboxes#
get_sandbox(sandbox_type: str = 'local', **kwargs)#

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