Move enemy only touching border

I want one of my enemy moves only at borders of surrounded area. My enemy must touch any side of border and continuously move around its limit.
Surrounded area is completely dynamic as per main player take its movement.

Following image give you more idea regarding this. I have to move on dotted path and path is dynamic.
I need some suggestion about this type of implementation.

I’m not sure how familiar you are with AI pathfinding techniques …but you could make a script that will generate a series of path nodes (depending on how your walls are generated you could use them to generate nodes in front of them?) and then just use an algorithm like A* to path around the nodes to the desired locations.