The most serious obstacle in further proliferation of wireless sensor networks is their low level of security, where the insider attacks are the most challenging issue. In this work we propose a holistic solution for detecting and confining insider attacks that couples reputation systems with clustering techniques, namely unsupervised genetic algorithm and selforganizing maps, trained for detecting outliers in data. The novelty of this work is the redundancy in detecting agents, their evaluation based on the majority voting and the calculation of the reputation as the average value, which makes it more robust to different attack scenarios and their parameter variations. The algorithms use the feature space based on sequences of sensor outputs (both temporal and spatial), as well as the routing paths used to forward the data to the base station, and designed with the idea of introducing the ability to detect a wide range of attacks. The solution performs both attack detection and recovery from attacks, and it offers many benefits: scalable solution, fast response to adversarial activities, ability to detect unknown attacks, high adaptability and high ability in detecting and confining attacks.