Replace File Content
POST
/v1/sandbox/{sandbox_id}/files/replacePOST
/v1/sandbox/{'{sandbox_id}'}/files/replaceYour instance endpoint, shown on the instance page in the dashboard. Each instance has its own host; there is no shared API host.
Description
Finds all occurrences of a substring within a file inside the sandbox and replaces them with a new value. The operation is performed in-place on the file at the given path.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sandbox_id | string | Yes | Sandbox ID or name |
Request Body
| Property | Type | Required | Description |
|---|---|---|---|
path | string | Yes | Absolute path to the file inside the sandbox |
old | string | Yes | The substring to search for and replace |
new | string | Yes | The replacement string |
Responses
200 Success
| Property | Type | Description |
|---|---|---|
status | string | Always "replaced" on success |
default An unexpected error response.
| Property | Type | Description |
|---|---|---|
code | integer | |
message | string | |
details | object[] |
Request
curl -X POST "https://your-instance.example.com/v1/sandbox/sb_abc123/files/replace" \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"path":"/repo/config.json","old":"localhost","new":"0.0.0.0"}'const response = await fetch(
"https://your-instance.example.com/v1/sandbox/sb_abc123/files/replace",
{
method: "POST",
headers: {
Authorization: "Bearer <token>",
"Content-Type": "application/json",
},
body: JSON.stringify({
path: "/repo/config.json",
old: "localhost",
new: "0.0.0.0",
}),
}
);
const data = await response.json();
console.log(data); // { status: "replaced" }import requests
response = requests.post(
"https://your-instance.example.com/v1/sandbox/sb_abc123/files/replace",
headers={"Authorization": "Bearer <token>"},
json={
"path": "/repo/config.json",
"old": "localhost",
"new": "0.0.0.0",
},
)
print(response.json()) # {"status": "replaced"}Response
{"status": "replaced"}{"code": 0, "message": "string", "details": [{"@type": "string"}]}
