diff --git a/IPython/core/inputtransformer2.py b/IPython/core/inputtransformer2.py
index 0bf22a138..04f423274 100644
--- a/IPython/core/inputtransformer2.py
+++ b/IPython/core/inputtransformer2.py
@@ -18,6 +18,19 @@
 
 _indent_re = re.compile(r'^[ \t]+')
 
+def leading_empty_lines(lines):
+    """Remove leading empty lines
+
+    If the leading lines are empty or contain only whitespace, they will be
+    removed.
+    """
+    if not lines:
+        return lines
+    for i, line in enumerate(lines):
+        if line and not line.isspace():
+            return lines[i:]
+    return lines
+
 def leading_indent(lines):
     """Remove leading indentation.
 
@@ -510,6 +523,7 @@ class TransformerManager:
     """
     def __init__(self):
         self.cleanup_transforms = [
+            leading_empty_lines,
             leading_indent,
             classic_prompt,
             ipython_prompt,

Problem with indentation in the `run_cell` method
Hi,

When using the InteractiveShell method `run_cell`, there is a problem when the string to execute begins with a line that contains only 4 spaces. It then does not handle properly  the indentations of the subsequent loops.
![image](https://user-images.githubusercontent.com/3619520/52297665-21969400-2936-11e9-800e-95262a98436d.png)


Tested on JupyterNotebook, JupyterLab and the Ipython interactive shell in the terminal.

Config:
- jupyter --version 4.4.0
- ipython --version 7.0.1
- python3 --version Python 3.6.7
- Ubuntu 18.04.1 LTS
diff --git a/IPython/core/tests/test_inputtransformer2_line.py b/IPython/core/tests/test_inputtransformer2_line.py
index 13a18d2d5..41b6ed293 100644
--- a/IPython/core/tests/test_inputtransformer2_line.py
+++ b/IPython/core/tests/test_inputtransformer2_line.py
@@ -86,3 +86,31 @@ def test_leading_indent():
     for sample, expected in [INDENT_SPACES, INDENT_TABS]:
         nt.assert_equal(ipt2.leading_indent(sample.splitlines(keepends=True)),
                         expected.splitlines(keepends=True))
+
+LEADING_EMPTY_LINES = ("""\
+    \t
+
+if True:
+    a = 3
+
+b = 4
+""", """\
+if True:
+    a = 3
+
+b = 4
+""")
+
+ONLY_EMPTY_LINES = ("""\
+    \t
+
+""", """\
+    \t
+
+""")
+
+def test_leading_empty_lines():
+    for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]:
+        nt.assert_equal(
+                ipt2.leading_empty_lines(sample.splitlines(keepends=True)),
+                expected.splitlines(keepends=True))

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest nose
apt-get update apt-get install -y gcc
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
backcall==0.2.0
decorator==5.2.1
exceptiongroup==1.2.2
iniconfig==2.1.0
-e git+https://github.com/ipython/ipython.git@380db0d7241372f9c12d5d5aaaa8e7e4c70575d5#egg=ipython
jedi==0.19.2
nose==1.3.7
packaging==24.2
parso==0.8.4
pexpect==4.9.0
pickleshare==0.7.5
pluggy==1.5.0
prompt-toolkit==2.0.10
ptyprocess==0.7.0
Pygments==2.19.1
pytest==8.3.5
six==1.17.0
tomli==2.2.1
traitlets==5.14.3
wcwidth==0.2.13

name: ipython
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - backcall==0.2.0
      - decorator==5.2.1
      - exceptiongroup==1.2.2
      - iniconfig==2.1.0
      - jedi==0.19.2
      - nose==1.3.7
      - packaging==24.2
      - parso==0.8.4
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pluggy==1.5.0
      - prompt-toolkit==2.0.10
      - ptyprocess==0.7.0
      - pygments==2.19.1
      - pytest==8.3.5
      - six==1.17.0
      - tomli==2.2.1
      - traitlets==5.14.3
      - wcwidth==0.2.13
prefix: /opt/conda/envs/ipython

IPython/core/tests/test_inputtransformer2_line.py::test_leading_empty_lines
IPython/core/tests/test_inputtransformer2_line.py::test_cell_magic IPython/core/tests/test_inputtransformer2_line.py::test_classic_prompt IPython/core/tests/test_inputtransformer2_line.py::test_ipython_prompt IPython/core/tests/test_inputtransformer2_line.py::test_leading_indent
IPython/core/inputtransformer2.py
IPython/core/inputtransformer2.py