how does cell membrance know what allow and out cell

How does a cell membrance know what to allow in and out of the cell?