Even though ants and cockroaches do not have brain, they perform their work with the help of some organs.
Their head contains many sensory organs.They have compound eyes made from numerous tiny lenses which are attached together.This helps in acute movement detection and light level detection.
Antennas are attached to the head which detect chemicals,air currents and vibration.Antenna can transmit and receive signals through touch.
So ants and cockroaches work with the help of such sensory organs.They do not receive any orders from any organ since each sensory organ can work on its own.