@@ -45,7 +45,11 @@ func IsSandboxed() bool {
4545func Run (ctx context.Context , cfg Config , stdout , stderr io.Writer ) error {
4646 runscPath , err := lookPathFunc (RuntimeBinary )
4747 if err != nil {
48- return fmt .Errorf ("security critical: '%s' not found in PATH: %w" , RuntimeBinary , err )
48+ if stderr != nil {
49+ fmt .Fprintf (stderr , "::warning::[Security] '%s' not found. Falling back to direct execution.\n " , RuntimeBinary )
50+ }
51+ // Fallback: Execute directly without sandbox
52+ return runDirect (ctx , cfg , stdout , stderr )
4953 }
5054
5155 bundleDir , err := os .MkdirTemp ("" , "sfw-sandbox-*" )
@@ -320,3 +324,32 @@ func generateSpec(ctx context.Context, cfg Config, selfExe string) (*Spec, error
320324 },
321325 }, nil
322326}
327+
328+ // runDirect executes the logic directly when sandbox is unavailable.
329+ func runDirect (ctx context.Context , cfg Config , stdout , stderr io.Writer ) error {
330+ // Re-construct the command to call self with the same arguments
331+ // but without the sandbox wrapper logic (which is handled by the caller checking IsSandboxed)
332+ // Actually, the 'worker' logic needs to be invoked.
333+ // Since 'Run' is called to WRAP the execution, we need to run the underlying logic.
334+ // However, the current architecture likely calls 'Run' which spawns 'sfw' again inside the sandbox.
335+ // So we can just spawn 'sfw' again with the same arguments, but ensure we don't loop.
336+ // The worker logic is triggered when the command is run.
337+
338+ selfExe , err := os .Executable ()
339+ if err != nil {
340+ return fmt .Errorf ("failed to locate self executable: %w" , err )
341+ }
342+
343+ // We need to set EnvSandboxID to prevent infinite recursion if the called process tries to sandbox itself again.
344+ // But wait, IsSandboxed() checks this env var.
345+ // If we set it, the child process will think it's already sandboxed and proceed with logic.
346+
347+ cmd := execCmdFunc (ctx , selfExe , cfg .Args ... )
348+ cmd .Env = os .Environ ()
349+ cmd .Env = append (cmd .Env , fmt .Sprintf ("%s=1" , EnvSandboxID ))
350+ cmd .Dir = cfg .WorkDir
351+ cmd .Stdout = stdout
352+ cmd .Stderr = stderr
353+
354+ return cmd .Run ()
355+ }
0 commit comments