['pipe', 'w'], // stdout 2 => ['pipe', 'w'], // stderr ]; // Execute the PHP code using proc_open $process = proc_open($command, $descriptorspec, $pipes); if (!is_resource($process)) { unlink($tempFile); throw new Exception('Failed to execute sandboxed PHP code.'); } // Capture stdout and stderr $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); // Get the exit code $exitCode = proc_close($process); // Cleanup temporary file unlink($tempFile); return $exitCode; }