Sounds like you want:
find . -name filename.sh -type f -execdir sbatch run_code.sh {} ';'
-mindepth 1 is superflous. It excludes ., but . is excluded anyway by both -type f and -name filename.sh.
-execdir (from BSD), is not a standard find predicate, but chances are that if your find supports -mindepth (also non-standard though from GNU), it will also support -execdir.
-execdir is exactly for that. It's like -exec except it runs the command in the parent directory of the selected file. Here, depending on the find implementation, the command being run will be either sbatch run_code.sh ./filename.sh or sbatch run_code.sh filename.sh. Remove the {} if you don't want the filename.sh to be passed as an argument to the command.
With find implementations that don't support -execdir, you could do:
find . -name filename.sh -type f -exec sh -c '
cd "${1%/*}" && exec sbatch run_code.sh "${1##*/}"' sh {} ';'
${1%/*} is $1 but with the shortest tail matching /* removed, so it will act like "$(dirname -- "$1")" but is more efficient and more reliable¹. ${1##*/} removes the longest head matching */ giving you a basename-like result.
Or to avoid running one sh per file:
find . -name filename.sh -type f -exec sh -c '
for file do
(cd "${file%/*}" && exec sbatch run_code.sh "${file##*/}"
done' sh {} +
With the zsh shell, you could also do:
for f (./**/filename.sh(ND.)) (cd $f:h && sbatch run_code.sh $f:t)
(the exec (to save a process) is not necessary as zsh does it implicitly already for the last command run in the subshell).
$f:h expands to $f's head (dirname) and $f:t to its tail (basename).
¹ would still work for instance if the dir name ended in newline characters; there are cases where using dirname (or zsh's $var:h) gives better results though such when the path to get the dirname of doesn't have any / or ends in / characters.