Machine API Reference โ
Complete API reference for the Machine class.
Constructor โ
typescript
new Machine(config: MachineConfig)python
Machine(config: MachineConfig)Static Methods โ
create() โ
Create and start a machine in one call.
typescript
static async create(config: MachineConfig): Promise<Machine>
// Usage
const machine = await Machine.create({ name: 'my-machine' });python
@classmethod
async def create(cls, config: MachineConfig) -> Machine
# Usage
machine = await Machine.create(MachineConfig(name="my-machine"))Instance Methods โ
start() โ
Create and start the machine.
typescript
async start(): Promise<void>python
async def start(self) -> Nonestop() โ
Stop the machine.
typescript
async stop(): Promise<void>python
async def stop(self) -> Nonedelete() โ
Delete the machine permanently.
typescript
async delete(): Promise<void>python
async def delete(self) -> Nonestatus() โ
Get current machine information.
typescript
async status(): Promise<MachineInfo>
interface MachineInfo {
name: string;
state: MachineState;
created_at?: string;
started_at?: string;
}python
async def status(self) -> MachineInfo
@dataclass
class MachineInfo:
name: str
state: MachineState
created_at: Optional[str]
started_at: Optional[str]exec() โ
Execute a command in the microVM.
typescript
async exec(
command: string[],
options?: ExecOptions
): Promise<ExecResult>
interface ExecOptions {
timeout?: number; // milliseconds
env?: Record<string, string>;
workdir?: string;
}python
async def exec(
self,
command: List[str],
*,
timeout: Optional[float] = None, # seconds
env: Optional[Dict[str, str]] = None,
workdir: Optional[str] = None
) -> ExecResultrun() โ
Run a command in a container image.
typescript
async run(
image: string,
command: string[],
options?: ExecOptions
): Promise<ExecResult>python
async def run(
self,
image: str,
command: List[str],
*,
timeout: Optional[float] = None,
env: Optional[Dict[str, str]] = None,
workdir: Optional[str] = None
) -> ExecResultcreateContainer() โ
Create a managed container.
typescript
async createContainer(options: ContainerCreateOptions): Promise<Container>
interface ContainerCreateOptions {
image: string;
command?: string[];
env?: Record<string, string>;
workdir?: string;
mounts?: ContainerMount[];
}python
async def create_container(
self,
image: str,
*,
command: Optional[List[str]] = None,
env: Optional[Dict[str, str]] = None,
workdir: Optional[str] = None,
mounts: Optional[List[ContainerMount]] = None
) -> ContainerlistContainers() โ
List all containers in the machine.
typescript
async listContainers(): Promise<ContainerInfo[]>python
async def list_containers(self) -> List[ContainerInfo]getContainer() โ
Get a container by ID.
typescript
async getContainer(id: string): Promise<Container>python
async def get_container(self, id: str) -> ContainerpullImage() โ
Pull a container image.
typescript
async pullImage(image: string): Promise<void>python
async def pull_image(self, image: str) -> NonelistImages() โ
List available images.
typescript
async listImages(): Promise<ImageInfo[]>python
async def list_images(self) -> List[ImageInfo]Types โ
MachineConfig โ
typescript
interface MachineConfig {
name: string;
serverUrl?: string;
mounts?: MountSpec[];
ports?: PortSpec[];
resources?: ResourceSpec;
}python
@dataclass
class MachineConfig:
name: str
server_url: str = "http://127.0.0.1:8080"
mounts: List[MountSpec] = field(default_factory=list)
ports: List[PortSpec] = field(default_factory=list)
resources: Optional[ResourceSpec] = NoneExecResult โ
typescript
interface ExecResult {
exitCode: number;
stdout: string;
stderr: string;
success: boolean;
output: string;
assertSuccess(): void; // throws if exitCode !== 0
}python
@dataclass
class ExecResult:
exit_code: int
stdout: str
stderr: str
@property
def success(self) -> bool: ...
@property
def output(self) -> str: ...
def assert_success(self) -> None: ... # raises if exit_code != 0MountSpec โ
typescript
interface MountSpec {
source: string;
target: string;
readonly?: boolean;
}python
@dataclass
class MountSpec:
source: str
target: str
readonly: bool = FalseResourceSpec โ
typescript
interface ResourceSpec {
cpus?: number;
memoryMb?: number;
}python
@dataclass
class ResourceSpec:
cpus: Optional[int] = None
memory_mb: Optional[int] = NoneMachineState โ
typescript
type MachineState =
| 'pending'
| 'starting'
| 'running'
| 'stopping'
| 'stopped'
| 'failed';python
class MachineState(Enum):
PENDING = "pending"
STARTING = "starting"
RUNNING = "running"
STOPPING = "stopping"
STOPPED = "stopped"
FAILED = "failed"