It's not possible to opt-out of faction wars. However, there are a few tips to stay safe: 

1) The City Shield can come in handy when you are being targeted. It blocks all attacks and spies going forward. All new players are gifted with several City Shield items when joining the game, use it when necessary.

2) As a new player, you may consider teleporting your city away from the War Zone area. However, the downside is that you are also teleporting away from the high-level high-production resource tiles which can only be found in the War Zone.

3) Joining a Guild! Join a guild and fight alongside with your battle buddies is the ultimate way to protect yourself and others. Together, we are strong!