初始化提交

This commit is contained in:
chenxin committed 2026-08-21 16:00:13 +08:00
commit 887c1f449e
963 files changed
+166869

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
"""乾坤沙箱配置。
从环境变量加载(与根目录 ``.env`` 统一)。字段名与 env 名一一对应(去除前缀后 snake_case
即 env 名),由 ``pydantic-settings`` 自动绑定,无需手动 ``os.getenv``。
- ``rust_sandbox_url`` 取自 ``RUST_SANDBOX_URL``(后端连沙箱的地址)。
- ``sandbox_auth_secret`` 与沙箱端 ``SANDBOX_AUTH_SECRET`` 共享,用于 HMAC 授权凭证签发。
"""
from __future__ import annotations
from pydantic_settings import BaseSettings
class SandboxSettings(BaseSettings):
"""沙箱客户端运行配置。"""
rust_sandbox_url: str = "http://127.0.0.1:8090" # RUST_SANDBOX_URL:后端连沙箱的地址
sandbox_auth_enabled: bool = True # SANDBOX_AUTH_ENABLED:是否启用 HMAC 授权
sandbox_auth_secret: str = "" # SANDBOX_AUTH_SECRET:与沙箱端共享的 HMAC 密钥
sandbox_default_timeout_ms: int = 30_000 # SANDBOX_DEFAULT_TIMEOUT_MS:默认执行超时
sandbox_auth_ttl_seconds: int = 30 # SANDBOX_AUTH_TTL_SECONDS:授权凭证有效期
def http_timeout(self, exec_timeout_ms: int | None) -> float:
"""HTTP 读取超时:执行超时 + 5s 余量,下限 10s。"""
exec_ms = (
exec_timeout_ms if exec_timeout_ms is not None else self.sandbox_default_timeout_ms
)
return max(exec_ms / 1000 + 5.0, 10.0)