| 2160 | } |
| 2161 | |
| 2162 | fn build_environment(sandbox: &DriverSandbox, config: &DockerDriverRuntimeConfig) -> Vec<String> { |
| 2163 | let mut environment = HashMap::from([ |
| 2164 | ("HOME".to_string(), "/root".to_string()), |
| 2165 | ("PATH".to_string(), SUPERVISOR_PATH.to_string()), |
| 2166 | ("TERM".to_string(), "xterm".to_string()), |
| 2167 | ( |
| 2168 | "OPENSHELL_LOG_LEVEL".to_string(), |
| 2169 | openshell_core::driver_utils::sandbox_log_level(sandbox, &config.log_level), |
| 2170 | ), |
| 2171 | ]); |
| 2172 | |
| 2173 | if let Some(spec) = sandbox.spec.as_ref() { |
| 2174 | let mut user_env = HashMap::new(); |
| 2175 | if let Some(template) = spec.template.as_ref() { |
| 2176 | user_env.extend(template.environment.clone()); |
| 2177 | } |
| 2178 | user_env.extend(spec.environment.clone()); |
| 2179 | environment.extend(user_env.clone()); |
| 2180 | if !user_env.is_empty() |
| 2181 | && let Ok(json) = serde_json::to_string(&user_env) |
| 2182 | { |
| 2183 | environment.insert( |
| 2184 | openshell_core::sandbox_env::USER_ENVIRONMENT.to_string(), |
| 2185 | json, |
| 2186 | ); |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | environment.insert( |
| 2191 | openshell_core::sandbox_env::ENDPOINT.to_string(), |
| 2192 | config.grpc_endpoint.clone(), |
| 2193 | ); |
| 2194 | environment.insert( |
| 2195 | openshell_core::sandbox_env::SANDBOX_ID.to_string(), |
| 2196 | sandbox.id.clone(), |
| 2197 | ); |
| 2198 | environment.insert( |
| 2199 | openshell_core::sandbox_env::SANDBOX.to_string(), |
| 2200 | sandbox.name.clone(), |
| 2201 | ); |
| 2202 | environment.insert( |
| 2203 | openshell_core::sandbox_env::SSH_SOCKET_PATH.to_string(), |
| 2204 | config.ssh_socket_path.clone(), |
| 2205 | ); |
| 2206 | environment.insert( |
| 2207 | openshell_core::sandbox_env::SANDBOX_COMMAND.to_string(), |
| 2208 | SANDBOX_COMMAND.to_string(), |
| 2209 | ); |
| 2210 | environment.insert( |
| 2211 | openshell_core::sandbox_env::TELEMETRY_ENABLED.to_string(), |
| 2212 | openshell_core::telemetry::enabled_env_value().to_string(), |
| 2213 | ); |
| 2214 | // The root supervisor executes namespace helpers during bootstrap; keep |
| 2215 | // their search path driver-owned even when the template/spec set PATH. |
| 2216 | environment.insert("PATH".to_string(), SUPERVISOR_PATH.to_string()); |
| 2217 | if config.guest_tls.is_some() { |
| 2218 | environment.insert( |
| 2219 | openshell_core::sandbox_env::TLS_CA.to_string(), |