Skip to main content

Task Execution Environment Interface

The ITaskExecutionEnvironment interface defines the contract interface for isolated task execution environments. Each user task gets their own dedicated environment to ensure task isolation and security.

note

This is our opinionated interface for execution environments. You can customize or create your own interface - any function call that can be encoded as calldata will work with the Task Manager.

Functions

executeTask

function executeTask(
bytes calldata taskData
) external returns (bool success);

Execute a task within the isolated environment.

Parameters

NameTypeDescription
taskDatabytesThe encoded task data containing target address and calldata

Return Value

TypeDescription
boolTrue if the task execution succeeded, false otherwise

Security Notes:

  • Only callable by the TaskManager contract
  • Executes in an isolated environment

Implementation Example

Here's a basic example of how to implement the interface:

contract BasicTaskEnvironment is ITaskExecutionEnvironment {
address public immutable TASK_MANAGER;

constructor(address taskManager_) {
TASK_MANAGER = taskManager_;
}

modifier onlyTaskManager() {
require(msg.sender == TASK_MANAGER, "Only TaskManager");
_;
}

function executeTask(bytes calldata taskData)
external
onlyTaskManager
returns (bool)
{
// Decode the target and data
(address target, bytes memory data) = abi.decode(
taskData,
(address, bytes)
);

// Execute the task
(bool success,) = target.call(data);
return success;
}
}

Usage Example

When scheduling a task that uses an execution environment:

  1. Deploy the environment:
BasicTaskEnvironment env = new BasicTaskEnvironment(taskManagerAddress);
  1. Encode the task data:
// 1. Encode the target function call
bytes memory targetCalldata = abi.encodeCall(
ITarget.someFunction,
(param1, param2)
);

// 2. Pack with target address
bytes memory packedData = abi.encode(
targetAddress,
targetCalldata
);
  1. Schedule the task:
taskManager.scheduleTask(
address(env), // Environment address
100_000, // Gas limit
targetBlock, // Target block
maxPayment, // Max payment
packedData // Packed task data
);

Security Considerations

When implementing an execution environment:

  1. Input Validation

    • Validate all inputs before execution
    • Ensure target addresses are valid
    • Verify calldata format and parameters
  2. State Management

    • Avoid storing persistent state between executions
    • Clear any temporary state after execution
  3. Error Handling

    • Properly handle and propagate errors
    • Consider implementing retry logic for failed tasks
  4. Gas Management

    • Be mindful of gas usage in custom logic
    • Respect task size categories
note

While many execution environments implement the onlyTaskManager modifier, it's not strictly required. The Task Manager uses a specialized proxy pattern that automatically enforces that only the Task Manager can forward calls to the execution environment.