Sandboxing applications will help you.
In computer security, a sandbox is a security mechanism for separating running programs. It is often used to execute untested code, or untrusted programs from unverified third parties, suppliers, untrusted users and untrusted websites. A sandbox typically provides a tightly controlled set of resources for guest programs to run in, such as scratch space on disk and memory. Network access, the ability to inspect the host system or read from input devices are usually disallowed or heavily restricted.
Apparmor is a default sandboxing application.
I recommend it to use.
Guide: Apparmor Documentation
See also:
Run an untrusted C program in a sandbox in Linux that prevents it from opening files, forking, etc.?
How to sandbox applications?