Running code through functions
EDIT due to misunderstanding the question.

If you want to be able to pass instructions into a function, you will have to have a function for each set of instructions (that is, you cannot pass arbitrary statements as a function parameter), and then you adjust your runfor() function to accept a pointer-to-a-function parameter.

typedef void (*callback_function)(void);  // defining the type here makes the code easier to read when used in other places.

void runfor(uint32_t duration, callback_function patternCode){
  uint32_t timer = millis();
  while ((millis()-timer)&lt;=duration) {
    //get these commands from caller function
    patternCode();
  }
}

void pattern1() {
  // Light pattern #1
}

void pattern2() {
  // Light pattern #2
}

void setup() {
  // Setup code
}

void loop() {
  runfor(1000, pattern1);
  runfor(2000, pattern2);
}




ORIGINAL ANSWER

Your starting pseudo-code is nearly there.

void runfor(uint32_t duration){
  uint32_t timer = millis();
  while ((millis()-timer)&lt;=duration) {
    //get these commands from caller function
  }
}


Changes I made:


change int to uint32_t to accommodate all possible values of millis().
change for keyword to while, which is the correct keyword for the loop type you want.
added semicolon after your timer assignment, per C syntax.