use super::AgentRunTime;
use crate::{core::FailureKind, observability, sandbox::Sandbox, state::AgentState};
use std::sync::Arc;
use tokio_util::sync::CancellationToken;
impl AgentRunTime {
pub(super) async fn open_sandbox(
&self,
ctx: &AgentState,
cancellation_token: CancellationToken,
) -> Result<Option<Arc<dyn Sandbox>>, String> {
tokio::select! {
_ = cancellation_token.cancelled() => Ok(None),
sandbox = self.sandbox.clone().open(&ctx.session_id) => {
sandbox.map(Some).map_err(|e| e.to_string())
}
}
}
pub(super) async fn persist_sandbox(&self, session_id: &str, sandbox: &Arc<dyn Sandbox>) {
if let Err(e) = sandbox.save().await {
observability::failed(
session_id,
FailureKind::SandboxSave.as_str(),
&format!("best-effort sandbox save failed: {}", e),
);
}
}
}