What are potential security risks of using the exec() function in PHP to run shell commands?

Using the exec() function in PHP to run shell commands can pose security risks such as command injection attacks if user input is not properly sanitized. To mitigate this risk, it is important to always validate and sanitize user input before passing it to the exec() function.

$user_input = $_POST['user_input'];
$clean_input = escapeshellarg($user_input);
exec("command $clean_input");