6. Exiting the sandbox

Depending on how you run the sandbox (see this step), you have to adjust the way you terminate the sandbox, and thus also the Sandboxee.

Exiting a sandbox running synchronously

If the sandbox has been running synchronously, then Run will only return when the Sandboxee is finished. Therefore no additional step for termination is required. The code snippet below shows this scenario:

Sandbox2::Result result = s2.Run();
LOG(INFO) << "Final execution status: " << result.ToString();

Exiting a sandbox running asynchronously

If the sandbox has been running asynchronously, then two options are available for termination. First, you can just wait for the completion of the Sandboxee and receive the final execution status:

sandbox2::Result result = s2.AwaitResult();
LOG(INFO) << "Final execution status: " << result.ToString();

Alternatively, you can kill the Sandboxee at any time, but it's still recommended to call AwaitResult() because the Sandboxee might terminate because of another reason in the meantime:

s2.Kill();
sandbox2::Result result = s2.AwaitResult();
LOG(INFO) << "Final execution status: " << result.ToString();