Leave a single opening at the far left of your maze, and a single opening at the far right.
The game’s enemy AI is programmed to dynamically calculate the shortest legal route from the spawn point to your base entrance. If you block their path entirely, they will simply destroy your towers. However, you can trick them into walking in endless loops by using the juggling exploit: xeno tactic cheat