I believe its restricted by a Geofence
To answer the initial question, the latest versions of ArduPilot implement terrain following (based on terrain data loaded into the flight computer before-hand). Additionally, there is also now support for range-finding instruments like Lidar Lite [0], although I don't believe those are currently being used in the terrain following mode. Such instruments could conceivably be used to implement "look-ahead" functionality to more accurately avoid obstacles.