A virus is a piece of code that inserts itself into an application and executes when the app is run, allowing it to steal data, launch attacks, or conduct ransomware attacks. Viruses require an infected application to run but worms can operate independently. Computer viruses and worms are often spread through email attachments and downloads and exploit vulnerabilities in software and security settings. Antivirus software, firewalls, updating systems regularly, and caution about suspicious files and emails can help prevent infection.