| 4071 | } |
| 4072 | |
| 4073 | fn build_guest_environment( |
| 4074 | sandbox: &Sandbox, |
| 4075 | config: &VmDriverConfig, |
| 4076 | endpoint_override: Option<&str>, |
| 4077 | ) -> Vec<String> { |
| 4078 | let openshell_endpoint = endpoint_override.map_or_else( |
| 4079 | || guest_visible_openshell_endpoint(&config.openshell_endpoint), |
| 4080 | String::from, |
| 4081 | ); |
| 4082 | // 1. User-supplied environment (lowest priority). |
| 4083 | let user_env = merged_environment(sandbox); |
| 4084 | let mut environment: HashMap<String, String> = HashMap::new(); |
| 4085 | environment.extend(user_env.clone()); |
| 4086 | if !user_env.is_empty() |
| 4087 | && let Ok(json) = serde_json::to_string(&user_env) |
| 4088 | { |
| 4089 | environment.insert( |
| 4090 | openshell_core::sandbox_env::USER_ENVIRONMENT.to_string(), |
| 4091 | json, |
| 4092 | ); |
| 4093 | } |
| 4094 | |
| 4095 | // 2. Required driver vars (highest priority -- always overwrite). |
| 4096 | environment.insert("HOME".to_string(), "/root".to_string()); |
| 4097 | environment.insert( |
| 4098 | "PATH".to_string(), |
| 4099 | "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".to_string(), |
| 4100 | ); |
| 4101 | environment.insert("TERM".to_string(), "xterm".to_string()); |
| 4102 | environment.insert( |
| 4103 | openshell_core::sandbox_env::ENDPOINT.to_string(), |
| 4104 | openshell_endpoint, |
| 4105 | ); |
| 4106 | environment.insert( |
| 4107 | openshell_core::sandbox_env::SANDBOX_ID.to_string(), |
| 4108 | sandbox.id.clone(), |
| 4109 | ); |
| 4110 | environment.insert( |
| 4111 | openshell_core::sandbox_env::SANDBOX.to_string(), |
| 4112 | sandbox.name.clone(), |
| 4113 | ); |
| 4114 | environment.insert( |
| 4115 | openshell_core::sandbox_env::SSH_SOCKET_PATH.to_string(), |
| 4116 | GUEST_SSH_SOCKET_PATH.to_string(), |
| 4117 | ); |
| 4118 | environment.insert( |
| 4119 | openshell_core::sandbox_env::SANDBOX_COMMAND.to_string(), |
| 4120 | "tail -f /dev/null".to_string(), |
| 4121 | ); |
| 4122 | environment.insert( |
| 4123 | openshell_core::sandbox_env::LOG_LEVEL.to_string(), |
| 4124 | openshell_core::driver_utils::sandbox_log_level(sandbox, &config.log_level), |
| 4125 | ); |
| 4126 | if config.requires_tls_materials() { |
| 4127 | environment.insert( |
| 4128 | openshell_core::sandbox_env::TLS_CA.to_string(), |
| 4129 | GUEST_TLS_CA_PATH.to_string(), |
| 4130 | ); |