Cloud computing is one of the major platforms that that maintains high levels of agility, scalability, and resilience while offering users and organizations a wide range of services, including data analytics and computational storage. However, effectively scheduling and managing user-requested workloads across the available cloud resources has become more complex due to the rapid growth in cloud adoption. However, determining the optimal task scheduling solution is thought to be an NP-hard problem, especially when handling large task sizes in a cloud environment. To solve this issue a novel Cockroach swarm Optimization based Task Scheduling (COTS) has been proposed to address this problem and improve the cloud environment's overall responsiveness and efficiency. Finding the best inputs to produce the highest or lowest output at the lowest cost is known as optimization. Cockroach Swarm Optimization can schedule tasks more quickly and find a much better distribution of solutions. The recommended method guarantees that the appropriate task is carried out on the appropriate resource at the appropriate time, improving the cloud environment's overall performance. Measures like CPU time, SLR performance, and waiting time obtained are used to assess the effectiveness of the recommended strategy. The COTS model outperforms the current A2C, EPOSA and GENETIC methods with an accuracy of 97% respectively