Patients must have documented presence of an EGFR exon 19 deletion or exon 21 (L858R) substitution mutation; T790M mutation or other molecular abnormality will be allowed as long as it accompanies one of the mutations listed above; EGFR testing must be performed using a Food and Drug Administration (FDA)-approved test or in a Clinical Laboratory Improvement Amendments (CLIA)-certified laboratory. NSCLC must harbor at least one of the following EGFR activating mutations: Exon 21 L858R, Exon 19 deletion, Exon 18 G719X, Exon 21 L861Q or for EGFR Exon 20 insertion expansion cohort D, NSCLC must harbor an EGFR Exon 20 insertion performed by a Clinical Laboratory Improvement Act (CLIA) certified test For Dose Expansion Cohort D: patient must 1) tumor that harbors an EGFR Exon 20 insertion by a CLIA certified test, and 2) have progressive disease on or after platinum based chemotherapy, and 3) be treatment naive to both EGFR-TKI and EGFR monoclonal antibody NSCLC must harbor an EGFR activating mutation (Exon 21 L858R, Exon 19 deletion, Exon 18 G719X, Exon 21 L861Q) Prior genotyping positive for an EGFR activating mutation (L858R, exon 19 deletion, G719X, L861Q) PHASE I: Patients must have metastatic/recurrent, histologically confirmed NSCLC that harbors an EGFR activating mutation (exon 21 L858R, exon 19 deletion, exon 18 G719X, exon 21 L861Q) with progressive disease by RECIST 1.1 on a previous EGFR-tyrosine kinase inhibitor (TKI); OR patients must have metastatic/recurrent histologically confirmed NSCLC that harbors an EGFR exon 20 insertion with progressive disease on platinum containing chemotherapy PHASE II COHORT A: Patients must have metastatic/recurrent histologically confirmed NSCLC that harbors an EGFR activating mutation (exon 21 L858R, exon 19 deletion, exon 18 G719X, exon 21 L861Q) with stable disease by RECIST 1.1 as best response on erlotinib compared to pre-treatment erlotinib imaging by RECIST 1.1 or progressive disease compared to pre-treatment imaging by RECIST 1.1 after a minimum duration of treatment on erlotinib of 12-weeks; patients must be enrolled within 6 months of initiation of erlotinib PHASE II COHORT B: Patients must have metastatic/recurrent histologically confirmed NSCLC that harbors an EGFR exon 20 insertion with progressive disease on or after platinum doublet chemotherapy FOR PHASE II COHORT B: (EGFR exon 20 insertions): Prior EGFR-TKIs including erlotinib is allowed; if patient is on erlotinib at the time of signed consent, erlotinib does NOT need to be discontinued prior to initiation of erlotinib and onalespib Non-squamous tumors must not be positive for epidermal growth factor receptor (EGFR) exon 19 deletion or exon 21 L858R mutation and anaplastic lymphoma receptor tyrosine kinase (ALK) rearrangement (results ascertained in centrally as part of ALCHEMIST-SCREEN protocol) All patients must have a somatic PIK3CA gene mutation (i.e., R88Q in exon 1, N345K in exon 4, C420R in exon 7, E542K, E545X [E545A, E545D, E545G, and E545K], Q546X [Q546E, Q546K, Q546L, and Q546R] in exon 9, and M1043I, H1047X [H1047L, H1047R, and H1047Y], or G1049R in exon 20) in a representative primary or metastatic tumor sample confirmed by the Roche COBAS PIK3CA Mutation Test at Q^2 Solutions Non-small cell lung cancer (NSCLC) with an activating EGFR mutation (exon 19 deletion, L858R point mutation, or any other mutation known to be associated with EGFR TKI sensitivity); presence of an activating EGFR mutation may be documented in tumor tissue or by plasma testing if performed in a Clinical Laboratory Improvement Act (CLIA)-certified laboratory; AND