As Mr Mud says, there are PLENTY of options for secure accommodation without living in the confines of a camp or managed estate.
Just use your common sense - look for a villa which isn't too remotely located, has a good external wall, remotely operated access entries, burglar bars fitted to ground floor (at the minimum) doors and windows. Most people employ a gate boy who will answer callers at the villa and do other stuff like washing your car and mowing the lawn.
Having lived in Lagos for many years, security for expats in Tripoli is much less of a concern.