DaytonaSandbox support shell env

This commit is contained in:
朱潮 2026-05-21 19:46:22 +08:00
parent 1d18a464c7
commit 776acc2373

View File

@ -311,6 +311,22 @@ async def init_agent(config: AgentConfig):
sandbox, sandbox_type, workspace_root = await sandbox_task
logger.info(f"init_agent sandbox ready, elapsed: {time.time() - create_start:.3f}s")
# Inject shell_env into Daytona sandbox via BASH_ENV file
if sandbox is not None and sandbox_type == "daytona":
_shell_env = {
"ASSISTANT_ID": config.bot_id,
"USER_IDENTIFIER": config.user_identifier,
"TRACE_ID": config.trace_id,
"ENABLE_SELF_KNOWLEDGE": str(config.enable_self_knowledge).lower(),
**(config.shell_env or {}),
}
env_lines = "\n".join(f'export {k}="{v}"' for k, v in _shell_env.items() if v is not None)
if env_lines:
from utils.daytona_sync import REMOTE_BASH_ENV_PATH, REMOTE_WORKSPACE_ROOT
bash_env_content = f"cd {REMOTE_WORKSPACE_ROOT}\n{env_lines}"
sandbox.execute(f"cat > {REMOTE_BASH_ENV_PATH} << 'ENVEOF'\n{bash_env_content}\nENVEOF")
logger.info(f"Injected {len(_shell_env)} env vars into Daytona BASH_ENV")
# Load sub-agents from skill directories
subagents = await load_subagents(
bot_id=config.bot_id,