It's used to introduce an event or situation that happens occasionally, but not always.
For example:
* "Me gusta el chocolate, y a veces lo como." (I like chocolate, and sometimes I eat it.)
* "Ella es muy tímida, y a veces le cuesta hablar en público." (She is very shy, and sometimes she has trouble speaking in public.)