Would/could PIs hire a consulting company to do partial work that's not in his/her field I understand that it is usually not difficult for PI to find another professor in the same campus or city for collaboration on a multi-field project (e.g. computational chemistry). However, when the demand of long term collaboration is not huge, would PIs consider to hire some outsiders or consulting companies to do the work? And is it allowed under NIH funding systems?

(For example, a task may only require a few hundreds line of coding, which can be done by an experienced programmer in the field. The work may be a bit too lack of rewards for a new collaborator. Wouldn't it be cheaper and more realistic for a chemistry PI to hire a consultant in this case, than getting a new PhD student or post-doc in programming? )

Thanks.
Do you exclusively mean non-academics? Sometimes a collaborator is included in another department or another academic institution to bring in such expertise. This can have it's downsides depending on which agency you are including since there may be costs to subcontracting or collaborating with another entity. It's possible that a Computer Scientist or Engineer down the hall or across campus has the student that can do the work without having to write in a professional contractor, though it is certainly possible to use a contractor. My wife works for a web firm and is currently responding to an RFP from a university to do user experience work for a web-based NSF project.