Sloths do have the ability to attack and kill a human if need be in defense.
However most sloths will do there best to avoid humans and other things they see as a threat because the main defense of a sloth is to avoid being preyed on or attacked.
But if they do need to defend themselves by attacking the human or other animal they can and will attack using their claws.
The sloth will defend themselves by slashing out at a predator with their huge claws or biting with their sharp cheek teeth.
Humans have also killed and eaten sloths for food years ago.