diff --git a/kitty_tests/shell_integration.py b/kitty_tests/shell_integration.py
index 3c4c3dd4943..b4848f1a85e 100644
--- a/kitty_tests/shell_integration.py
+++ b/kitty_tests/shell_integration.py
@@ -12,9 +12,8 @@
 from functools import lru_cache, partial
 
 from kitty.bash import decode_ansi_c_quoted_string
-from kitty.constants import kitty_base_dir, shell_integration_dir, terminfo_dir
+from kitty.constants import kitten_exe, kitty_base_dir, shell_integration_dir, terminfo_dir
 from kitty.fast_data_types import CURSOR_BEAM, CURSOR_BLOCK, CURSOR_UNDERLINE
-from kitty.shell_integration import setup_bash_env, setup_fish_env, setup_zsh_env
 
 from . import BaseTest
 
@@ -54,7 +53,6 @@ def safe_env_for_running_shell(argv, home_dir, rc='', shell='zsh'):
         argv.insert(1, '--noglobalrcs')
         with open(os.path.join(home_dir, '.zshrc'), 'w') as f:
             print(rc + '\nZLE_RPROMPT_INDENT=0', file=f)
-        setup_zsh_env(ans, argv)
     elif shell == 'fish':
         conf_dir = os.path.join(home_dir, '.config', 'fish')
         os.makedirs(conf_dir, exist_ok=True)
@@ -62,12 +60,10 @@ def safe_env_for_running_shell(argv, home_dir, rc='', shell='zsh'):
         os.makedirs(os.path.join(home_dir, '.local', 'share', 'fish', 'generated_completions'), exist_ok=True)
         with open(os.path.join(conf_dir, 'config.fish'), 'w') as f:
             print(rc + '\n', file=f)
-        setup_fish_env(ans, argv)
     elif shell == 'bash':
-        setup_bash_env(ans, argv)
-        ans['KITTY_BASH_INJECT'] += ' posix'
-        ans['KITTY_BASH_POSIX_ENV'] = os.path.join(home_dir, '.bashrc')
-        with open(ans['KITTY_BASH_POSIX_ENV'], 'w') as f:
+        bashrc = os.path.join(home_dir, '.bashrc')
+        ans['KITTY_RUNNING_BASH_INTEGRATION_TEST'] = bashrc
+        with open(bashrc, 'w') as f:
             # ensure LINES and COLUMNS are kept up to date
             print('shopt -s checkwinsize', file=f)
             if rc:
@@ -84,7 +80,7 @@ def run_shell(self, shell='zsh', rc='', cmd='', setup_env=None):
         cmd = shlex.split(cmd.format(**locals()))
         env = (setup_env or safe_env_for_running_shell)(cmd, home_dir, rc=rc, shell=shell)
         try:
-            pty = self.create_pty(cmd, cwd=home_dir, env=env)
+            pty = self.create_pty([kitten_exe(), 'run-shell', '--shell', shlex.join(cmd)], cwd=home_dir, env=env)
             i = 10
             while i > 0 and not pty.screen_contents().strip():
                 pty.process_input_from_child()
@@ -327,7 +323,6 @@ def redrawn():
 
         def setup_env(excluded, argv, home_dir, rc='', shell='bash'):
             ans = basic_shell_env(home_dir)
-            setup_bash_env(ans, argv)
             for x in {'profile', 'bash.bashrc', '.bash_profile', '.bash_login', '.profile', '.bashrc', 'rcfile'} - excluded:
                 with open(os.path.join(home_dir, x), 'w') as f:
                     if x == '.bashrc' and rc:
diff --git a/tools/tui/shell_integration/api.go b/tools/tui/shell_integration/api.go
index 9a8323db78f..df612733ee8 100644
--- a/tools/tui/shell_integration/api.go
+++ b/tools/tui/shell_integration/api.go
@@ -224,7 +224,7 @@ func bash_setup_func(shell_integration_dir string, argv []string, env map[string
 	sorted := remove_args.AsSlice()
 	slices.Sort(sorted)
 	for _, i := range utils.Reverse(sorted) {
-		slices.Delete(argv, i, i+1)
+		argv = slices.Delete(argv, i, i+1)
 	}
 	if env[`HISTFILE`] == "" && !inject.Has(`posix`) {
 		// In POSIX mode the default history file is ~/.sh_history instead of ~/.bash_history
@@ -232,6 +232,14 @@ func bash_setup_func(shell_integration_dir string, argv []string, env map[string
 		env[`KITTY_BASH_UNEXPORT_HISTFILE`] = `1`
 	}
 	argv = slices.Insert(argv, 1, `--posix`)
+
+	if bashrc := os.Getenv(`KITTY_RUNNING_BASH_INTEGRATION_TEST`); bashrc != `` {
+		// prevent bash from source /etc/profile which is not under our control
+		os.Unsetenv(`KITTY_RUNNING_BASH_INTEGRATION_TEST`)
+		env[`KITTY_BASH_INJECT`] += ` posix`
+		env[`KITTY_BASH_POSIX_ENV`] = bashrc
+	}
+
 	return argv, env, nil
 }