Gives 3 levels of sandbox error message under different flags.
 1. no flag: only the direct reason is given (command execution termination status), and also the instruction to use "--verbose_failures"
 2. flag "--verbose_failures": gives failed execution command and the instruction to use "--sandbox_debug --strategy"
 3. flag "--verbose_failures --sandbox_debug": gives failed execution command, debugging message from sandboxing, and the instruction to use "--strategy"

Also removes "cd <sandbox_path>" in given failed command, since debugging is only necessary with flag "--verbose_failures --sandbox_debug" and the path is already given in sandboxing debugging message.

Addresses #2174.

Fixes bazel_sandboxing_test.sh and bazel_test_test.sh for the new error message.
Fixes timeout.

--
PiperOrigin-RevId: 144285435
MOS_MIGRATED_REVID=144285435
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java
index b91d3dd..18df3d0 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java
@@ -28,6 +28,7 @@
 import com.google.devtools.build.lib.buildtool.BuildRequest;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.util.io.OutErr;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import java.io.IOException;
@@ -69,13 +70,15 @@
       throws ExecException, InterruptedException {
     EventHandler eventHandler = actionExecutionContext.getExecutor().getEventHandler();
     ExecException execException = null;
+    OutErr outErr = actionExecutionContext.getFileOutErr();
     try {
       runner.run(
           spawn.getArguments(),
           spawnEnvironment,
-          actionExecutionContext.getFileOutErr(),
+          outErr,
           Spawns.getTimeoutSeconds(spawn),
-          SandboxHelpers.shouldAllowNetwork(buildRequest, spawn));
+          SandboxHelpers.shouldAllowNetwork(buildRequest, spawn),
+          sandboxOptions.sandboxDebug);
     } catch (ExecException e) {
       execException = e;
     }
@@ -102,6 +105,10 @@
     }
 
     if (execException != null) {
+      outErr.printErr(
+          "Use --strategy="
+          + spawn.getMnemonic()
+          + "=standalone to disable sandboxing for the failing actions.\n");
       throw execException;
     }
   }