Use sudo only if prevent_sudo is not set

@sethvargo I accidentally closed #1655 so here is the updated branch with tests added. Sorry about that... :fearful: