Skip to content

HopxExecutionEnvironmentConfig

Base classes

Name Children Inherits
BaseExecutionEnvironmentConfig
exxec_config.configs
Base execution environment configuration.

â‹” Inheritance diagram

graph TD
  1197897779["configs.HopxExecutionEnvironmentConfig"]
  2844377061["configs.BaseExecutionEnvironmentConfig"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  2844377061 --> 1197897779
  330168112 --> 2844377061
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseExecutionEnvironmentConfig

Hopx execution environment configuration.

Executes code in Hopx cloud VM sandboxes for secure, ephemeral execution environments.

Source code in src/exxec_config/configs.py
class HopxExecutionEnvironmentConfig(BaseExecutionEnvironmentConfig):
    """Hopx execution environment configuration.

    Executes code in Hopx cloud VM sandboxes for secure, ephemeral execution environments.
    """

    model_config = ConfigDict(json_schema_extra={"x-doc-title": "Hopx Execution Environment"})
    type: Literal["hopx"] = Field("hopx", init=False)
    template: str | None = Field(
        default=None,
        title="Hopx Template",
        examples=["code-interpreter", "base"],
    )
    """Hopx template name to use."""

    template_id: str | None = Field(
        default=None,
        title="Hopx Template ID",
    )
    """Hopx template ID (alternative to template name)."""

    api_key: SecretStr | None = Field(
        default=None,
        title="Hopx API Key",
    )
    """Hopx API key (or use HOPX_API_KEY env var)."""

    base_url: str = Field(
        default="https://api.hopx.dev",
        title="API Base URL",
    )
    """Hopx API base URL."""

    region: str | None = Field(
        default=None,
        title="Region",
    )
    """Preferred region for sandbox creation."""

    sandbox_timeout: float = Field(
        default=300.0,
        gt=0.0,
        title="Sandbox Lifetime",
        examples=[300.0, 600.0, 3600.0],
    )
    """How long the sandbox stays alive in seconds."""

    keep_alive: bool = Field(default=False, title="Keep Alive")
    """Keep sandbox running after execution."""

    internet_access: bool | None = Field(
        default=None,
        title="Internet Access",
    )
    """Enable internet access in the sandbox."""

    language: Language = Field(
        default="python",
        title="Programming Language",
        examples=["python", "javascript", "typescript"],
    )
    """Programming language to use."""

    def get_provider(
        self, lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None
    ) -> HopxExecutionEnvironment:
        """Create Hopx execution environment instance."""
        from exxec.hopx_provider import HopxExecutionEnvironment

        return HopxExecutionEnvironment(
            lifespan_handler=lifespan_handler,
            dependencies=self.dependencies,
            template=self.template,
            template_id=self.template_id,
            timeout=self.sandbox_timeout,
            default_command_timeout=self.default_command_timeout,
            keep_alive=self.keep_alive,
            language=self.language,
            cwd=self.cwd,
            env_vars=self.env_vars,
            inherit_env=self.inherit_env,
            api_key=self.api_key.get_secret_value() if self.api_key else None,
            base_url=self.base_url,
            region=self.region,
            internet_access=self.internet_access,
        )

api_key class-attribute instance-attribute

api_key: SecretStr | None = Field(default=None, title='Hopx API Key')

Hopx API key (or use HOPX_API_KEY env var).

base_url class-attribute instance-attribute

base_url: str = Field(default='https://api.hopx.dev', title='API Base URL')

Hopx API base URL.

internet_access class-attribute instance-attribute

internet_access: bool | None = Field(default=None, title='Internet Access')

Enable internet access in the sandbox.

keep_alive class-attribute instance-attribute

keep_alive: bool = Field(default=False, title='Keep Alive')

Keep sandbox running after execution.

language class-attribute instance-attribute

language: Language = Field(
    default="python", title="Programming Language", examples=["python", "javascript", "typescript"]
)

Programming language to use.

region class-attribute instance-attribute

region: str | None = Field(default=None, title='Region')

Preferred region for sandbox creation.

sandbox_timeout class-attribute instance-attribute

sandbox_timeout: float = Field(
    default=300.0, gt=0.0, title="Sandbox Lifetime", examples=[300.0, 600.0, 3600.0]
)

How long the sandbox stays alive in seconds.

template class-attribute instance-attribute

template: str | None = Field(
    default=None, title="Hopx Template", examples=["code-interpreter", "base"]
)

Hopx template name to use.

template_id class-attribute instance-attribute

template_id: str | None = Field(default=None, title='Hopx Template ID')

Hopx template ID (alternative to template name).

get_provider

get_provider(
    lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None,
) -> HopxExecutionEnvironment

Create Hopx execution environment instance.

Source code in src/exxec_config/configs.py
def get_provider(
    self, lifespan_handler: AbstractAsyncContextManager[ServerInfo] | None = None
) -> HopxExecutionEnvironment:
    """Create Hopx execution environment instance."""
    from exxec.hopx_provider import HopxExecutionEnvironment

    return HopxExecutionEnvironment(
        lifespan_handler=lifespan_handler,
        dependencies=self.dependencies,
        template=self.template,
        template_id=self.template_id,
        timeout=self.sandbox_timeout,
        default_command_timeout=self.default_command_timeout,
        keep_alive=self.keep_alive,
        language=self.language,
        cwd=self.cwd,
        env_vars=self.env_vars,
        inherit_env=self.inherit_env,
        api_key=self.api_key.get_secret_value() if self.api_key else None,
        base_url=self.base_url,
        region=self.region,
        internet_access=self.internet_access,
    )

:fa-brands-github: Show source on GitHub