Cyber-physical system is one of the essential components of wireless sensor network (WSN). WSN conjointly senses, collects, analyzes and communicates data on recognized items at service part before transmitting this data to the owner of the network. Blackhole, Grayhole, Flooding, Scheduling are the common WSN attacks that rapidly damage the system. Intrusion detection systems, such as WSN have drawbacks, like less detection rates, high computation costs and high percentage of false alarms, because sensor nodes have limited resources. Therefore, a Self Attention Generative Adversarial Capsule Network as an intrusion detection scheme for WSN (SAGACN-ID-WSN) is proposed in this paper to address the aforementioned issues. Initially, the data are amassed from WSN-DS dataset. Then, the data are sent for pre-processing. The input data are preprocessed using the Guided Box Filtering (GBF) method. Then, the preprocessed data are provided to the Atomic Orbital Search (AOS), Tasmanian Devil Optimization (TDO) and Ebola Optimization Search (EOS) algorithms for feature selection. The attacks are divided into four categories: normal, Grayhole attack, Black hole attack, flooding attack, and scheduling attack. The proposed ID-WSN is implemented in Network simulator 2 (NS-2) utilizing the dataset of WSN-DS. The metrics, like accuracy, precision, recall, F-measure, ROC and computational time are analyzed. The proposed SAGACN-ID-WSN technique attains 25.5%, 20.12% and 20.7% high accuracy, 51.136%, 59.04% and 32.81%; higher precision, 2.292%, 1.51% and 3.915% lower error rate compared to the existing models, like Dataset for Intrusion Detection Systems in WSN (SLGBM-ID-WSN), multi-layer machine learning-based ID-WSN (NB-RF-ID-WSN), deep learning and entity embedding-base intrusion detection systems in WSN, respectively.