Machine API Reference
Complete API reference for the Machine class.
Constructor
TypeScriptnew Machine(config: MachineConfig) Python Machine(config: MachineConfig) Static Methods
create()
Create and start a machine in one call.
TypeScriptstatic 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.
TypeScriptasync start(): Promise<void> Python async def start(self) -> None stop()
Stop the machine.
TypeScriptasync stop(): Promise<void> Python async def stop(self) -> None delete()
Delete the machine permanently.
TypeScriptasync delete(): Promise<void> Python async def delete(self) -> None status()
Get current machine information.
TypeScriptasync 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.
TIP
`exec` calls — running commands inside a machine — are never charged and never rate-limited. Run as many as you want.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],
env: Optional[Dict[str, str]] = None,
workdir: Optional[str] = None,
timeout: Optional[int] = None # seconds
) -> ExecResult run()
Run a command in a container image.
TypeScriptasync run(
image: string,
command: string[],
options?: ExecOptions
): Promise<ExecResult> Python async def run(
self,
image: str,
command: List[str],
env: Optional[Dict[str, str]] = None,
workdir: Optional[str] = None,
timeout: Optional[int] = None
) -> ExecResult createContainer()
Create a managed container.
TypeScriptasync 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
) -> Container listContainers()
List all containers in the machine.
TypeScriptasync listContainers(): Promise<ContainerInfo[]> Python async def list_containers(self) -> List[ContainerInfo] getContainer()
Get a container by ID.
TypeScriptasync getContainer(id: string): Promise<Container> Python async def get_container(self, id: str) -> Container pullImage()
Pull a container image.
TypeScriptasync pullImage(image: string): Promise<void> Python async def pull_image(self, image: str) -> None listImages()
List available images.
TypeScriptasync listImages(): Promise<ImageInfo[]> Python async def list_images(self) -> List[ImageInfo] Types
MachineConfig
TypeScriptinterface 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] = None ExecResult
TypeScriptinterface 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 != 0 MountSpec
TypeScriptinterface MountSpec {
source: string;
target: string;
readonly?: boolean;
} Python @dataclass
class MountSpec:
source: str
target: str
readonly: bool = False ResourceSpec
TypeScriptinterface ResourceSpec {
cpus?: number;
memoryMb?: number;
} Python @dataclass
class ResourceSpec:
cpus: Optional[int] = None
memory_mb: Optional[int] = None MachineState
TypeScripttype MachineState =
| 'created'
| 'running'
| 'stopped'; Python class MachineState(Enum):
CREATED = "created"
RUNNING = "running"
STOPPED = "stopped"