{"openapi":"3.1.0","info":{"title":"Rubox API","version":"0.2.0","description":"Rubox API управляет постоянными Linux-песочницами, файлами и процессами. Все защищённые endpoints требуют заголовок `Authorization: Bearer rubox_sk_...`."},"servers":[{"url":"https://rubox.io/v1","description":"Production"},{"url":"http://127.0.0.1:8009/v1","description":"Local development"}],"security":[{"bearerAuth":[]}],"tags":[{"name":"Machines","description":"Создание и управление машинами"},{"name":"Lifecycle","description":"Запуск, остановка, перезагрузка и изменение тарифа"},{"name":"Execution","description":"Выполнение команд"},{"name":"Files","description":"Простые операции с файлами"},{"name":"Toolbox","description":"Расширенный API файлов и процессов"}],"paths":{"/machines":{"get":{"tags":["Machines"],"summary":"Список машин","operationId":"listMachines","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineListResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}},"post":{"tags":["Machines"],"summary":"Создать машину","operationId":"createMachine","requestBody":{"required":false,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateMachineRequest"}}}},"responses":{"201":{"description":"Создана","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/machines/{id}":{"get":{"tags":["Machines"],"summary":"Детали машины","operationId":"getMachine","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineDetailedResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"tags":["Machines"],"summary":"Удалить машину","operationId":"deleteMachine","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"Удалена","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeleteMachineResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/machines/{id}/status":{"get":{"tags":["Machines"],"summary":"Статус провиженинга","operationId":"getMachineStatus","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MachineStatusResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/machines/{id}/start":{"post":{"tags":["Lifecycle"],"summary":"Запустить машину","operationId":"startMachine","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"Запущена","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LifecycleResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/machines/{id}/stop":{"post":{"tags":["Lifecycle"],"summary":"Остановить машину","operationId":"stopMachine","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"Остановлена","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LifecycleResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/machines/{id}/reboot":{"post":{"tags":["Lifecycle"],"summary":"Перезагрузить машину","operationId":"rebootMachine","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"Перезагружена","content":{"application/json":{"schema":{"$ref":"#/components/schemas/LifecycleResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/machines/{id}/resize":{"post":{"tags":["Lifecycle"],"summary":"Изменить тариф машины","operationId":"resizeMachine","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResizeMachineRequest"}}}},"responses":{"200":{"description":"Тариф изменён","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResizeMachineResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/machines/{id}/exec":{"post":{"tags":["Execution"],"summary":"Выполнить shell-команду","operationId":"executeMachineCommand","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExecRequest"}}}},"responses":{"200":{"description":"Результат","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExecResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"$ref":"#/components/responses/Conflict"}}}},"/machines/{id}/files":{"get":{"tags":["Files"],"summary":"Список файлов","operationId":"listFiles","parameters":[{"$ref":"#/components/parameters/MachineId"},{"$ref":"#/components/parameters/FilePathQuery"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FileListResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/machines/{id}/files/read":{"get":{"tags":["Files"],"summary":"Прочитать файл","operationId":"readFile","parameters":[{"$ref":"#/components/parameters/MachineId"},{"$ref":"#/components/parameters/FilePathQueryRequired"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FileReadResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/machines/{id}/files/write":{"post":{"tags":["Files"],"summary":"Записать файл","operationId":"writeFile","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WriteFileRequest"}}}},"responses":{"201":{"description":"Записан","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WriteFileResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/machines/{id}/files/delete":{"delete":{"tags":["Files"],"summary":"Удалить файл","operationId":"deleteFile","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeleteFileRequest"}}}},"responses":{"200":{"description":"Удалён","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeleteFileResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/machines/{id}/toolbox/files":{"get":{"tags":["Toolbox"],"summary":"Список файлов","operationId":"toolboxListFiles","parameters":[{"$ref":"#/components/parameters/MachineId"},{"$ref":"#/components/parameters/FilePathQuery"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FileListResponse"}}}}}},"delete":{"tags":["Toolbox"],"summary":"Удалить файл или директорию","operationId":"toolboxDeleteFile","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/DeleteFile"},"responses":{"200":{"description":"Удалён"}}}},"/machines/{id}/toolbox/files/info":{"get":{"tags":["Toolbox"],"summary":"Информация о файле","operationId":"toolboxFileInfo","parameters":[{"$ref":"#/components/parameters/MachineId"},{"$ref":"#/components/parameters/FilePathQueryRequired"}],"responses":{"200":{"description":"OK"}}}},"/machines/{id}/toolbox/files/exists":{"get":{"tags":["Toolbox"],"summary":"Проверить файл","operationId":"toolboxFileExists","parameters":[{"$ref":"#/components/parameters/MachineId"},{"$ref":"#/components/parameters/FilePathQueryRequired"}],"responses":{"200":{"description":"OK"}}}},"/machines/{id}/toolbox/files/download":{"get":{"tags":["Toolbox"],"summary":"Скачать файл","operationId":"toolboxFileDownload","parameters":[{"$ref":"#/components/parameters/MachineId"},{"$ref":"#/components/parameters/FilePathQueryRequired"}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FileReadResponse"}}}}}}},"/machines/{id}/toolbox/files/upload":{"post":{"tags":["Toolbox"],"summary":"Загрузить файл","operationId":"toolboxFileUpload","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/UploadFile"},"responses":{"201":{"description":"Загружен"}}}},"/machines/{id}/toolbox/files/folder":{"post":{"tags":["Toolbox"],"summary":"Создать директорию","operationId":"toolboxMkdir","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/PathOnly"},"responses":{"201":{"description":"Создана"}}}},"/machines/{id}/toolbox/files/move":{"post":{"tags":["Toolbox"],"summary":"Переместить файл","operationId":"toolboxMove","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/MoveFile"},"responses":{"200":{"description":"Перемещён"}}}},"/machines/{id}/toolbox/files/permissions":{"post":{"tags":["Toolbox"],"summary":"Изменить права","operationId":"toolboxChmod","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/Chmod"},"responses":{"200":{"description":"Права изменены"}}}},"/machines/{id}/toolbox/files/find":{"post":{"tags":["Toolbox"],"summary":"Найти файлы","operationId":"toolboxFind","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/Find"},"responses":{"200":{"description":"OK"}}}},"/machines/{id}/toolbox/files/replace":{"post":{"tags":["Toolbox"],"summary":"Найти и заменить","operationId":"toolboxReplace","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/Replace"},"responses":{"200":{"description":"OK"}}}},"/machines/{id}/toolbox/process/execute":{"post":{"tags":["Toolbox"],"summary":"Выполнить процесс","operationId":"toolboxExec","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/Exec"},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExecResponse"}}}}}}},"/machines/{id}/toolbox/process/execute/stream":{"post":{"tags":["Toolbox"],"summary":"Выполнить процесс через SSE","operationId":"toolboxExecStream","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/Exec"},"responses":{"200":{"description":"SSE stream","content":{"text/event-stream":{"schema":{"type":"string"}}}}}}},"/machines/{id}/toolbox/process/code-run":{"post":{"tags":["Toolbox"],"summary":"Запустить код","operationId":"toolboxCodeRun","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/CodeRun"},"responses":{"200":{"description":"OK"}}}},"/machines/{id}/toolbox/process/kill":{"post":{"tags":["Toolbox"],"summary":"Остановить процесс","operationId":"toolboxKill","parameters":[{"$ref":"#/components/parameters/MachineId"}],"requestBody":{"$ref":"#/components/requestBodies/KillProcess"},"responses":{"200":{"description":"OK"}}}},"/machines/{id}/toolbox/process/list":{"get":{"tags":["Toolbox"],"summary":"Список процессов","operationId":"toolboxProcessList","parameters":[{"$ref":"#/components/parameters/MachineId"}],"responses":{"200":{"description":"OK"}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"Rubox API key: rubox_sk_..."}},"parameters":{"MachineId":{"name":"id","in":"path","required":true,"schema":{"type":"string"},"example":"550e8400-e29b-41d4-a716-446655440000"},"FilePathQuery":{"name":"path","in":"query","required":false,"schema":{"type":"string","default":"/workspace"}},"FilePathQueryRequired":{"name":"path","in":"query","required":true,"schema":{"type":"string"}}},"requestBodies":{"Exec":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExecRequest"}}}},"UploadFile":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UploadFileRequest"}}}},"DeleteFile":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeleteFileRequest"}}}},"PathOnly":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PathOnlyRequest"}}}},"MoveFile":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MoveFileRequest"}}}},"Chmod":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChmodRequest"}}}},"Find":{"required":false,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FindRequest"}}}},"Replace":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReplaceRequest"}}}},"CodeRun":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CodeRunRequest"}}}},"KillProcess":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/KillProcessRequest"}}}}},"schemas":{"TierKey":{"type":"string","enum":["starter","basic","pro","power","ultra"]},"MachineStatus":{"type":"string","enum":["provisioning","active","stopped","error","archived"]},"MachineResources":{"type":"object","properties":{"cpu":{"type":"string","example":"4 vCPU"},"memory":{"type":"string","example":"8 GB"},"disk":{"type":"string","example":"160 GB"}},"required":["cpu","memory","disk"],"additionalProperties":false},"Machine":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"provider":{"type":"string"},"status":{"$ref":"#/components/schemas/MachineStatus"},"tier":{"$ref":"#/components/schemas/TierKey"},"created_at":{"type":["string","null"],"format":"date-time"},"last_used_at":{"type":["string","null"],"format":"date-time"}},"required":["id","name","provider","status","tier","created_at","last_used_at"]},"MachineDetailed":{"allOf":[{"$ref":"#/components/schemas/Machine"},{"type":"object","properties":{"base_url":{"type":["string","null"]},"resources":{"anyOf":[{"$ref":"#/components/schemas/MachineResources"},{"type":"null"}]},"metadata":{"type":["object","null"],"additionalProperties":true}}}]},"CreateMachineRequest":{"type":"object","properties":{"name":{"type":"string","example":"production-agent"},"tier":{"$ref":"#/components/schemas/TierKey"},"server_type":{"$ref":"#/components/schemas/TierKey"}},"additionalProperties":true},"ResizeMachineRequest":{"type":"object","properties":{"tier":{"$ref":"#/components/schemas/TierKey"},"server_type":{"$ref":"#/components/schemas/TierKey"}},"additionalProperties":false},"ExecRequest":{"type":"object","required":["command"],"properties":{"command":{"type":"string","example":"python --version"},"timeout_ms":{"type":"integer","maximum":120000,"default":30000},"timeout":{"type":"integer","maximum":120000}},"additionalProperties":false},"ExecResult":{"type":"object","properties":{"stdout":{"type":"string"},"stderr":{"type":"string"},"exit_code":{"type":"integer"}},"required":["stdout","stderr","exit_code"]},"MachineListResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Machine"}}},"required":["data"]},"MachineResponse":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/Machine"}},"required":["data"]},"MachineDetailedResponse":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/MachineDetailed"}},"required":["data"]},"MachineStatusResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"id":{"type":"string"},"status":{"$ref":"#/components/schemas/MachineStatus"},"stage":{"type":["string","null"]},"stage_progress":{"type":["number","null"]},"stage_message":{"type":["string","null"]}},"required":["id","status","stage","stage_progress","stage_message"]}},"required":["data"]},"DeleteMachineResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"id":{"type":"string"},"deleted":{"type":"boolean"}},"required":["id","deleted"]}},"required":["data"]},"LifecycleResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"id":{"type":"string"},"status":{"$ref":"#/components/schemas/MachineStatus"},"rebooted":{"type":"boolean"}},"required":["id","status"]}},"required":["data"]},"ResizeMachineResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"id":{"type":"string"},"previous_tier":{"type":"string"},"new_tier":{"$ref":"#/components/schemas/TierKey"},"resources":{"$ref":"#/components/schemas/MachineResources"}},"required":["id","previous_tier","new_tier","resources"]}},"required":["data"]},"ExecResponse":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/ExecResult"}},"required":["data"]},"FileEntry":{"type":"object","properties":{"name":{"type":"string"},"size":{"type":"integer"},"is_dir":{"type":"boolean"},"modified":{"type":["string","null"]},"permissions":{"type":"string"}},"required":["name","size","is_dir","modified","permissions"]},"FileListResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"path":{"type":"string"},"entries":{"type":"array","items":{"$ref":"#/components/schemas/FileEntry"}}},"required":["path","entries"]}},"required":["data"]},"FileReadResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"path":{"type":"string"},"content":{"type":"string"},"encoding":{"type":"string"},"binary":{"type":"boolean"},"size":{"type":"integer"}},"required":["path","content","encoding"]}},"required":["data"]},"WriteFileRequest":{"type":"object","required":["path","content"],"properties":{"path":{"type":"string"},"content":{"type":"string"},"encoding":{"type":"string","default":"utf-8"}},"additionalProperties":false},"WriteFileResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"path":{"type":"string"},"written":{"type":"boolean"}},"required":["path","written"]}},"required":["data"]},"DeleteFileRequest":{"type":"object","required":["path"],"properties":{"path":{"type":"string"},"recursive":{"type":"boolean","default":true}},"additionalProperties":false},"DeleteFileResponse":{"type":"object","properties":{"data":{"type":"object","properties":{"path":{"type":"string"},"deleted":{"type":"boolean"}},"required":["path","deleted"]}},"required":["data"]},"UploadFileRequest":{"type":"object","required":["path","content"],"properties":{"path":{"type":"string"},"content":{"type":"string"},"encoding":{"type":"string","enum":["utf-8","base64"],"default":"utf-8"}},"additionalProperties":false},"PathOnlyRequest":{"type":"object","required":["path"],"properties":{"path":{"type":"string"}},"additionalProperties":false},"MoveFileRequest":{"type":"object","required":["from","to"],"properties":{"from":{"type":"string"},"to":{"type":"string"}},"additionalProperties":false},"ChmodRequest":{"type":"object","required":["path","mode"],"properties":{"path":{"type":"string"},"mode":{"type":"string","example":"755"}},"additionalProperties":false},"FindRequest":{"type":"object","properties":{"directory":{"type":"string","default":"/workspace"},"pattern":{"type":"string","default":"*"}},"additionalProperties":false},"ReplaceRequest":{"type":"object","required":["path","find"],"properties":{"path":{"type":"string"},"find":{"type":"string"},"replace":{"type":"string","default":""}},"additionalProperties":false},"CodeRunRequest":{"type":"object","required":["code"],"properties":{"code":{"type":"string"},"language":{"type":"string","default":"bash","examples":["bash","python","node"]}},"additionalProperties":false},"KillProcessRequest":{"type":"object","required":["pid"],"properties":{"pid":{"type":"integer"}},"additionalProperties":false},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"]}},"responses":{"Unauthorized":{"description":"API-ключ отсутствует или недействителен","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"BadRequest":{"description":"Некорректный запрос","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Не найдено","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Conflict":{"description":"Машина не готова для операции","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}