Everstack
API ReferenceSandboxReplace File Content

Replace File Content

POST/v1/sandbox/{sandbox_id}/files/replace
POST/v1/sandbox/{'{sandbox_id}'}/files/replace

Your 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

ParameterTypeRequiredDescription
sandbox_idstringYesSandbox ID or name

Request Body

PropertyTypeRequiredDescription
pathstringYesAbsolute path to the file inside the sandbox
oldstringYesThe substring to search for and replace
newstringYesThe replacement string

Responses

200 Success

PropertyTypeDescription
statusstringAlways "replaced" on success

default An unexpected error response.

PropertyTypeDescription
codeinteger
messagestring
detailsobject[]

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"}]}