Terminal
Create and control terminal sessions in your compute environment.
ComputeSDK provides a powerful terminal API that lets you create and control terminal sessions programmatically.
Creating a Terminal
Create a new terminal session:
const terminal = await compute.createTerminal();
Writing Commands
Send commands to the terminal:
// Write a single command
terminal.write('ls -la\n');
// Write multiple commands
terminal.write('cd /home/project\n');
terminal.write('npm install\n');
Handling Output
Listen for terminal output:
terminal.onData((data) => {
console.log('Terminal output:', data);
});
Resizing the Terminal
Adjust the terminal dimensions:
terminal.resize(80, 24); // cols, rows
Cleanup
Always close terminal sessions when they’re no longer needed:
await terminal.close();