How to Detect is a Character is in a specific nav mesh, then making it only move within the nav mesh?

I want an AI that moves around a place randomly, until it reaches a specific nav mesh, It then won’t be able to leave the Nav Mesh Unless a specific condition is met.

Here is a diagram