The paper presents an approach based on principles of immune systems to the anomaly detection problem. Flexibility and efficiency of the anomaly detection system are achieved by building a model of network behavior based on the selfnonself space paradigm. Covering both self and nonself spaces by hyperrectangular structures is proposed. Structures corresponding to self-space are built using a training set from this space. Hyperrectangular detectors covering nonself space are created using niching genetic algorithm. A coevolutionary algorithm is proposed to enhance this process. Results of experiments show a high quality of intrusion detection, which outperform the quality of recently proposed approach based on hypersphere representation of self-space. Categories and Subject Descriptors: I.2.8 [Problem Solving, Control Methods, and Search]: Heuristic methods General Terms: Algorithms, Experimentation.