The product owner prioritizes product backlog items based on which are needed soonest. Developers, influenced by the sprint goal, choose items for coming sprint, moving those items from the product backlog to the sprint backlog, which is the list of items they will build. Conceptually, the sprint goal is influenced by high-priority items at the top of the list, but it is not unusual to see developers taking some lower-priority items if there is time left within the sprint to accommodate more work.