As the integration of the internet of things (IoT) and industrial internet of things (IIoT) technologies continues to increase across various industries, ensuring strong cybersecurity measures becomes essential. In smart and agile cybersecurity for IoT and IIoT environments, foundational principles like risk management, security controls, governance, and a code of ethics are required. Risk management involves proactively identifying and mitigating potential threats, and ensuring the resilience of interconnected systems against cyber-attacks and vulnerabilities. Similarly, robust security controls, including encryption protocols and access management tools, provide essential layers of defense, safeguarding sensitive data and preventing unauthorized access. Furthermore, effective governance structures establish clear responsibility and guide policy implementation, enabling adherence to regulatory requirements and organizational objectives. Eventually, a strict code of ethics emphasizes the ethical imperatives basics in cybersecurity practices, enabling integrity, transparency, and respect for privacy rights. Through a comprehensive study of these topics, this chapter aims to provide readers with the necessary knowledge and strategies to steer the complexity of cybersecurity in IoT and IIoT environments efficiently, enabling resilience and adaptability against evolving threats.