Skip to content

MicrosandboxExecutionEnvironmentConfig

Base classes

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

â‹” Inheritance diagram

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

🛈 DocStrings

Bases: BaseExecutionEnvironmentConfig

Microsandbox execution environment configuration.

Executes code in lightweight microVMs for strong isolation.

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

    Executes code in lightweight microVMs for strong isolation.
    """

    model_config = ConfigDict(
        json_schema_extra={"x-doc-title": "Microsandbox Execution Environment"}
    )

    type: Literal["microsandbox"] = Field("microsandbox", init=False)

    namespace: str = Field(default="exxec", title="Namespace")
    """Prefix for the sandbox name (a unique suffix is appended)."""

    api_key: SecretStr | None = Field(default=None, title="API Key")
    """API key for authentication (uses MSB_API_KEY env var if None)."""

    memory: int = Field(default=512, ge=128, title="Memory (MiB)")
    """Memory limit in MiB."""

    cpus: int = Field(default=1, ge=1, title="Virtual CPUs")
    """Number of virtual CPUs."""

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

    image: str | None = Field(
        default=None,
        title="Docker Image",
        examples=["python:3.13-slim", "node:20-alpine"],
    )
    """Custom Docker image (uses default for language if None)."""

    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."""

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

        api_key_str = self.api_key.get_secret_value() if self.api_key else None
        return MicrosandboxExecutionEnvironment(
            lifespan_handler=lifespan_handler,
            dependencies=self.dependencies,
            namespace=self.namespace,
            api_key=api_key_str,
            memory=self.memory,
            cpus=self.cpus,
            timeout=self.sandbox_timeout,
            default_command_timeout=self.default_command_timeout,
            language=self.language,
            image=self.image,
            cwd=self.cwd,
            env_vars=self.env_vars,
            inherit_env=self.inherit_env,
        )

api_key class-attribute instance-attribute

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

API key for authentication (uses MSB_API_KEY env var if None).

cpus class-attribute instance-attribute

cpus: int = Field(default=1, ge=1, title='Virtual CPUs')

Number of virtual CPUs.

image class-attribute instance-attribute

image: str | None = Field(
    default=None, title="Docker Image", examples=["python:3.13-slim", "node:20-alpine"]
)

Custom Docker image (uses default for language if None).

language class-attribute instance-attribute

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

Programming language to use.

memory class-attribute instance-attribute

memory: int = Field(default=512, ge=128, title='Memory (MiB)')

Memory limit in MiB.

namespace class-attribute instance-attribute

namespace: str = Field(default='exxec', title='Namespace')

Prefix for the sandbox name (a unique suffix is appended).

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.

get_provider

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

Create Microsandbox execution environment instance.

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

    api_key_str = self.api_key.get_secret_value() if self.api_key else None
    return MicrosandboxExecutionEnvironment(
        lifespan_handler=lifespan_handler,
        dependencies=self.dependencies,
        namespace=self.namespace,
        api_key=api_key_str,
        memory=self.memory,
        cpus=self.cpus,
        timeout=self.sandbox_timeout,
        default_command_timeout=self.default_command_timeout,
        language=self.language,
        image=self.image,
        cwd=self.cwd,
        env_vars=self.env_vars,
        inherit_env=self.inherit_env,
    )

:fa-brands-github: Show source on GitHub