mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
Port the complete infrastructure for agent sandbox execution and skill system: Sandbox & Virtual Environment (core/sandbox/, core/virtual_environment/): - Sandbox entity with lifecycle management (ready/failed/cancelled states) - SandboxBuilder with fluent API for configuring providers - 5 VM providers: Local, SSH, Docker, E2B, AWS CodeInterpreter - VirtualEnvironment base with command execution, file transfer, transport layers - Channel transport: pipe, queue, socket implementations - Bash session management and DifyCli binary integration - Storage: archive storage, file storage, noop storage, presign storage - Initializers: DifyCli, AppAssets, DraftAppAssets, Skills - Inspector: file browser, archive/runtime source, script utils - Security: encryption utils, debug helpers Skill & App Assets (core/skill/, core/app_assets/, core/app_bundle/): - Skill entity and manager - App asset accessor, builder pipeline (file, skill builders) - App bundle source zip extractor - Storage and converter utilities API Endpoints: - CLI API blueprint (controllers/cli_api/) for sandbox callback - Sandbox provider management (workspace/sandbox_providers) - Sandbox file browser (console/sandbox_files) - App asset management (console/app/app_asset) - Skill management (console/app/skills) - Storage file endpoints (controllers/files/storage_files) Services: - Sandbox service, provider service, file service - App asset service, app bundle service Config: - CliApiConfig, CreatorsPlatformConfig, CollaborationConfig - FILES_API_URL for sandbox file access Note: Controller route registration temporarily commented out (marked TODO) pending resolution of deep dependency chains (socketio, workflow_comment, command node, etc.). Core sandbox modules are fully ported and syntax-validated. 110 files changed, 10,549 insertions. Made-with: Cursor
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass, field
|
|
from typing import TYPE_CHECKING
|
|
|
|
from core.sandbox.sandbox import Sandbox
|
|
|
|
if TYPE_CHECKING:
|
|
from core.app_assets.entities.assets import AssetItem
|
|
|
|
|
|
@dataclass
|
|
class SandboxInitializeContext:
|
|
"""Shared identity context passed to every ``SandboxInitializer``.
|
|
|
|
Carries the common identity fields that virtually every initializer
|
|
needs, plus optional artefact slots that sync initializers populate
|
|
for async initializers to consume.
|
|
|
|
Identity fields are immutable by convention; artefact slots are
|
|
written at most once during the sync phase and read during the
|
|
async phase.
|
|
"""
|
|
|
|
tenant_id: str
|
|
app_id: str
|
|
assets_id: str
|
|
user_id: str
|
|
|
|
# Populated by DraftAppAssetsInitializer (sync) for
|
|
# DraftAppAssetsDownloader (async) to download into the VM.
|
|
built_assets: list[AssetItem] | None = field(default=None)
|
|
|
|
|
|
class SandboxInitializer(ABC):
|
|
@abstractmethod
|
|
def initialize(self, sandbox: Sandbox, ctx: SandboxInitializeContext) -> None: ...
|
|
|
|
|
|
class SyncSandboxInitializer(SandboxInitializer):
|
|
"""Marker class for initializers that must run before async setup."""
|
|
|
|
|
|
class AsyncSandboxInitializer(SandboxInitializer):
|
|
"""Marker class for initializers that can run in the background."""
|