diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php
index 54c6db27ac..a6220466a4 100644
--- a/src/wp-admin/includes/plugin.php
+++ b/src/wp-admin/includes/plugin.php
@@ -2125,6 +2125,7 @@ function wp_clean_plugins_cache( $clear_update_cache = true ) {
  * @param string $plugin Path to the plugin file relative to the plugins directory.
  */
 function plugin_sandbox_scrape( $plugin ) {
+	define( 'WP_SANDBOX_SCRAPING', true );
 	wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin );
 	include( WP_PLUGIN_DIR . '/' . $plugin );
 }
diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
index 1ab7959e5f..98391123aa 100644
--- a/src/wp-admin/includes/theme.php
+++ b/src/wp-admin/includes/theme.php
@@ -859,6 +859,7 @@ function resume_theme( $theme, $redirect = '' ) {
 
 			// Load the theme's functions.php to test whether it throws a fatal error.
 			ob_start();
+			define( 'WP_SANDBOX_SCRAPING', true );
 			include $functions_path;
 			ob_clean();
 		}
diff --git a/src/wp-includes/class-wp-fatal-error-handler.php b/src/wp-includes/class-wp-fatal-error-handler.php
index 8ec87c9e24..270bb9e444 100644
--- a/src/wp-includes/class-wp-fatal-error-handler.php
+++ b/src/wp-includes/class-wp-fatal-error-handler.php
@@ -26,6 +26,10 @@ class WP_Fatal_Error_Handler {
 	 * @since 5.2.0
 	 */
 	public function handle() {
+		if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) {
+			return;
+		}
+
 		try {
 			// Bail if no error found.
 			$error = $this->detect_error();
diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php
index f2c9318da6..1915fbde17 100644
--- a/src/wp-includes/load.php
+++ b/src/wp-includes/load.php
@@ -1444,6 +1444,7 @@ function wp_start_scraping_edited_file_errors() {
 		echo "###### wp_scraping_result_end:$key ######";
 		die();
 	}
+	define( 'WP_SANDBOX_SCRAPING', true );
 	register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
 }
 
