If you can get some kind of primitive cell, with a very simple membrane, then natural selection can hone it into a selective filter, where there are pores in the cell that let certain things in and out, and so forth. 