xautolock is a program that runs any script you want after a set time of inactivity. Read the man page on xautolock for more details, but basically you run xautolock in the background, and if you don’t touch your keyboard or mouse, it will launch any script you want, such as i3lock, to lock your system if you leave it alone. For example, to lock your screen after 3 mins use
xautolock -detectsleep -time 3 -locker "i3lock -n -c 000000"