How to programmatically render a webform to display specific Elements I have tried this way but not able to hide "confirmation_id" element.

public function buildForm(array $form, FormStateInterface $form_state, $sid = NULL) {


$my_webform_machinename = 'request_form';
$my_form = \Drupal\webform\Entity\Webform::load($my_webform_machinename);
$my_form['elements']['flexbox_layout']['confirmation_id']['#access'] = FALSE;


return [      
    'form' =&gt; [
    '#type' =&gt; 'webform',
    '#webform' =&gt; $my_form,
    '#sid' =&gt; $sid, 
    ],

]; 

}
To hide custom field in webfrom you need to use the hook_form_FORM_ID_alter. 

function CUSTOM_MODULE_form_webform_submission_request_form_add_form_alter(array &amp;$form, FormStateInterface $form_state, $form_id) {
  $elements = &amp;Drupal\webform\Utility\WebformFormHelper::flattenElements($form['elements']);

  $elements['flexbox_layout']['confirmation_id']['#access'] = FALSE;
}



To get specific form elements you can use getSubmissionForm() method:

public function buildForm(array $form, FormStateInterface $form_state, $sid = NULL) {
  $my_webform_machinename = 'request_form';
  $my_form = \Drupal\webform\Entity\Webform::load($my_webform_machinename);

  $webform = $my_form-&gt;getSubmissionForm();

  $form['my_field'] = $webform['elements']['flexbox_layout']['confirmation_id'];

  return parent::buildForm($form, $form_state);
}