@@ -1320,6 +1320,10 @@ mod linux {
13201320 provider_env_revision : u64 ,
13211321 provider_env : std:: collections:: HashMap < String , String > ,
13221322 ) -> Response {
1323+ let spec = match resolve_agent_spec ( spec) {
1324+ Ok ( spec) => spec,
1325+ Err ( error) => return guest_error ( "failed" , error) ,
1326+ } ;
13231327 let mut state = lock ( & self . state ) ;
13241328 let requested = StartedAgent {
13251329 sandbox_id : sandbox_id. clone ( ) ,
@@ -1669,6 +1673,24 @@ mod linux {
16691673 ca_file_paths : Option < ( std:: path:: PathBuf , std:: path:: PathBuf ) > ,
16701674 }
16711675
1676+ fn resolve_agent_spec ( mut spec : AgentSpecWire ) -> Result < AgentSpecWire , String > {
1677+ if !spec. program . is_empty ( ) {
1678+ return Ok ( spec) ;
1679+ }
1680+ if !spec. args . is_empty ( ) {
1681+ return Err ( "default agent command cannot include arguments" . to_string ( ) ) ;
1682+ }
1683+ let shell = openshell_core:: shell:: detect_login_shell ( ) ;
1684+ if !openshell_core:: shell:: is_executable ( & shell) {
1685+ return Err ( format ! (
1686+ "sandbox image does not provide an executable login shell at {shell}"
1687+ ) ) ;
1688+ }
1689+ spec. program = shell;
1690+ spec. args = vec ! [ "-l" . to_string( ) ] ;
1691+ Ok ( spec)
1692+ }
1693+
16721694 impl ManagedProcess {
16731695 fn spawn (
16741696 runtime : & tokio:: runtime:: Handle ,
@@ -1684,9 +1706,7 @@ mod linux {
16841706 provider_env,
16851707 ca_file_paths,
16861708 } = launch;
1687- if spec. program . is_empty ( ) {
1688- return Err ( "agent program must not be empty" . to_string ( ) ) ;
1689- }
1709+ debug_assert ! ( !spec. program. is_empty( ) ) ;
16901710 let boundary_runtime = BoundaryRuntimeState :: new_exclusive_pid_namespace ( ) ;
16911711 let entrypoint_pid = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
16921712 let provider_credentials = ProviderCredentialState :: from_child_env_snapshot (
@@ -2378,6 +2398,23 @@ mod linux {
23782398 assert_eq ! ( ledger. entries. len( ) , MAX_REPLAY_LEDGER_ENTRIES ) ;
23792399 }
23802400
2401+ #[ test]
2402+ fn scratch_agent_command_resolves_inside_the_workload_filesystem ( ) {
2403+ let resolved = resolve_agent_spec ( AgentSpecWire {
2404+ program : String :: new ( ) ,
2405+ args : Vec :: new ( ) ,
2406+ workdir : Some ( "/sandbox" . to_string ( ) ) ,
2407+ timeout_secs : 0 ,
2408+ interactive : true ,
2409+ } )
2410+ . expect ( "resolve scratch command" ) ;
2411+
2412+ assert ! ( openshell_core:: shell:: is_executable( & resolved. program) ) ;
2413+ assert_eq ! ( resolved. args, vec![ "-l" . to_string( ) ] ) ;
2414+ assert_eq ! ( resolved. workdir. as_deref( ) , Some ( "/sandbox" ) ) ;
2415+ assert ! ( resolved. interactive) ;
2416+ }
2417+
23812418 fn placeholder_server_tls ( ) -> BoundaryServerTls {
23822419 BoundaryServerTls {
23832420 certificate_chain_path : Path :: new ( "/tmp/openshell-sandbox.crt" ) . to_path_buf ( ) ,
0 commit comments