You can access JMeter API classes from within the WebDriver Sampler, it's implemented as JSR 223 standard for instance you can refer JMeter Variables (aka vars
as follows)
In the WebDriver Sampler:
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();
vars.put('foo','bar')
Now you have ${foo}
variable with the value of bar
See The WebDriver Sampler: Your Top 10 Questions Answered guide for more WDS sampler tips and tricks.