That's a great observation! What you're seeing is not typically a separate attachment you can add or remove, but rather an integrated feature of many modern urban trash cans. That small sand-filled container is specifically designed as a public ashtray or cigarette disposal unit.
Its primary purpose is safety and cleanliness. By providing a designated spot filled with sand or fine gravel to extinguish cigarettes, it helps prevent fires that could start if a lit cigarette were tossed directly into a bin full of dry paper and other flammable waste. The sand smothers the ember immediately. Secondly, it keeps sidewalks cleaner by containing cigarette butts in one place, preventing them from being littered on the ground. So, it's a built-in solution for cities to manage cigarette waste responsibly, address fire hazards, and maintain cleaner public spaces. You'll often find these on bins in high-traffic areas like outside office buildings, near transit stops, and in parks.