Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

7.0 KB
Raw Blame
#
# Copyright 2026 The OpenSandbox Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.capabilities_response_hardening import CapabilitiesResponseHardening


T = TypeVar("T", bound="CapabilitiesResponse")


@_attrs_define
class CapabilitiesResponse:
    """
    Attributes:
        available (bool | Unset):
        isolator (str | Unset):
        version (str | Unset):
        message (str | Unset): Diagnostic message when isolation is unavailable or degraded (for example, share_net=true
            sessions work but no uid mode can create the private network namespace required by share_net=false)
        setpriv_available (bool | Unset): Whether sessions using uid_mode setpriv can be created with execd's default
            UID/GID. Requests that select different UID/GID values may still return 503 NOT_SUPPORTED when identity
            switching is unavailable.
        userns_available (bool | Unset): Whether sessions using uid_mode userns can be created
        setpriv_net_available (bool | Unset): Whether sessions using uid_mode setpriv can also create the private
            network namespace required by share_net=false (bwrap --unshare-net; its loopback setup needs CAP_NET_ADMIN in
            the execd container). Create rejects share_net=false requests with 503 NOT_SUPPORTED when the requested mode's
            flag is false.
        userns_net_available (bool | Unset): Whether sessions using uid_mode userns can also create the private network
            namespace required by share_net=false.
        commit_supported (bool | Unset):
        diff_supported (bool | Unset):
        hardening (CapabilitiesResponseHardening | Unset): execd init-mode and workload-hardening state (OSEP-0018):
            whether execd is the sandbox init and which of its controls are in effect. Not an isolation capability; reported
            here so operators see enforcement state in one place.
    """

    available: bool | Unset = UNSET
    isolator: str | Unset = UNSET
    version: str | Unset = UNSET
    message: str | Unset = UNSET
    setpriv_available: bool | Unset = UNSET
    userns_available: bool | Unset = UNSET
    setpriv_net_available: bool | Unset = UNSET
    userns_net_available: bool | Unset = UNSET
    commit_supported: bool | Unset = UNSET
    diff_supported: bool | Unset = UNSET
    hardening: CapabilitiesResponseHardening | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        available = self.available

        isolator = self.isolator

        version = self.version

        message = self.message

        setpriv_available = self.setpriv_available

        userns_available = self.userns_available

        setpriv_net_available = self.setpriv_net_available

        userns_net_available = self.userns_net_available

        commit_supported = self.commit_supported

        diff_supported = self.diff_supported

        hardening: dict[str, Any] | Unset = UNSET
        if not isinstance(self.hardening, Unset):
            hardening = self.hardening.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if available is not UNSET:
            field_dict["available"] = available
        if isolator is not UNSET:
            field_dict["isolator"] = isolator
        if version is not UNSET:
            field_dict["version"] = version
        if message is not UNSET:
            field_dict["message"] = message
        if setpriv_available is not UNSET:
            field_dict["setpriv_available"] = setpriv_available
        if userns_available is not UNSET:
            field_dict["userns_available"] = userns_available
        if setpriv_net_available is not UNSET:
            field_dict["setpriv_net_available"] = setpriv_net_available
        if userns_net_available is not UNSET:
            field_dict["userns_net_available"] = userns_net_available
        if commit_supported is not UNSET:
            field_dict["commit_supported"] = commit_supported
        if diff_supported is not UNSET:
            field_dict["diff_supported"] = diff_supported
        if hardening is not UNSET:
            field_dict["hardening"] = hardening

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.capabilities_response_hardening import CapabilitiesResponseHardening

        d = dict(src_dict)
        available = d.pop("available", UNSET)

        isolator = d.pop("isolator", UNSET)

        version = d.pop("version", UNSET)

        message = d.pop("message", UNSET)

        setpriv_available = d.pop("setpriv_available", UNSET)

        userns_available = d.pop("userns_available", UNSET)

        setpriv_net_available = d.pop("setpriv_net_available", UNSET)

        userns_net_available = d.pop("userns_net_available", UNSET)

        commit_supported = d.pop("commit_supported", UNSET)

        diff_supported = d.pop("diff_supported", UNSET)

        _hardening = d.pop("hardening", UNSET)
        hardening: CapabilitiesResponseHardening | Unset
        if isinstance(_hardening, Unset):
            hardening = UNSET
        else:
            hardening = CapabilitiesResponseHardening.from_dict(_hardening)

        capabilities_response = cls(
            available=available,
            isolator=isolator,
            version=version,
            message=message,
            setpriv_available=setpriv_available,
            userns_available=userns_available,
            setpriv_net_available=setpriv_net_available,
            userns_net_available=userns_net_available,
            commit_supported=commit_supported,
            diff_supported=diff_supported,
            hardening=hardening,
        )

        capabilities_response.additional_properties = d
        return capabilities_response

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties