feat: add tenant_id support to Sandbox and VirtualEnvironment initialization

This commit is contained in:
Yeuoly
2026-01-08 16:19:29 +08:00
parent 94dbda503f
commit b09a831d15
8 changed files with 66 additions and 28 deletions
+3
View File
@@ -113,7 +113,10 @@ class SandboxLayer(GraphEngineLayer):
# Fallback to explicit configuration (backward compatibility)
sandbox_type = self._sandbox_type or SandboxType.DOCKER
logger.info("Initializing sandbox, sandbox_type=%s", sandbox_type)
# Use a placeholder tenant_id for backward compatibility when tenant_id is not provided
effective_tenant_id = self._tenant_id or "default"
self._sandbox = SandboxFactory.create(
tenant_id=effective_tenant_id,
sandbox_type=sandbox_type,
options=self._options,
environments=self._environments,
@@ -14,11 +14,25 @@ class VirtualEnvironment(ABC):
Base class for virtual environment implementations.
"""
def __init__(self, options: Mapping[str, Any], environments: Mapping[str, str] | None = None) -> None:
def __init__(
self,
tenant_id: str,
options: Mapping[str, Any],
environments: Mapping[str, str] | None = None,
user_id: str | None = None,
) -> None:
"""
Initialize the virtual environment with metadata.
Args:
tenant_id: The tenant ID associated with this environment (required).
options: Provider-specific configuration options.
environments: Environment variables to set in the virtual environment.
user_id: The user ID associated with this environment (optional).
"""
self.tenant_id = tenant_id
self.user_id = user_id
self.options = options
self.metadata = self._construct_environment(options, environments or {})
+7 -2
View File
@@ -3,7 +3,8 @@ Sandbox factory for creating VirtualEnvironment instances.
Example:
sandbox = SandboxFactory.create(
SandboxType.DOCKER,
tenant_id="tenant-uuid",
sandbox_type=SandboxType.DOCKER,
options={"docker_image": "python:3.11-slim"},
environments={"PATH": "/usr/local/bin"},
)
@@ -34,17 +35,21 @@ class SandboxFactory:
@classmethod
def create(
cls,
tenant_id: str,
sandbox_type: SandboxType,
options: Mapping[str, Any] | None = None,
environments: Mapping[str, str] | None = None,
user_id: str | None = None,
) -> VirtualEnvironment:
"""
Create a VirtualEnvironment instance based on the specified type.
Args:
tenant_id: Tenant ID associated with the sandbox (required)
sandbox_type: Type of sandbox to create
options: Sandbox-specific configuration options
environments: Environment variables to set in the sandbox
user_id: User ID associated with the sandbox (optional)
Returns:
Configured VirtualEnvironment instance
@@ -56,7 +61,7 @@ class SandboxFactory:
environments = environments or {}
sandbox_class = cls._get_sandbox_class(sandbox_type)
return sandbox_class(options=options, environments=environments)
return sandbox_class(tenant_id=tenant_id, options=options, environments=environments, user_id=user_id)
@classmethod
def _get_sandbox_class(cls, sandbox_type: SandboxType) -> type[VirtualEnvironment]: