Skip to content

Store a network policy, or replace all of its rules.

shard.policies.set(name: string, rules: PolicyRule[]): Promise<Policy>

Examples

await shard.policies.set("api-only", [{ action: "allow", rule: "api.example.com" }]);
await shard.policies.set("ssh-only", [{ action: "allow", rule: "203.0.113.0/24 tcp:22" }]);

Arguments

Argument Description
name policy name; up to 64 lower-case letters, digits and hyphens, starting with a letter or a digit
rules { action, rule } in TypeScript, PolicyRule(action, rule) in Python; action is allow or deny

Rules apply in the order given. The first match decides access. Traffic that no rule allows is denied. A sandbox that holds the policy enforces the new rules.

A rule takes the form shard policy create uses: a destination with an optional protocol and ports, such as suffix:example.com tcp:443. See Rules in the CLI reference.

Return a policy and the sandboxes that use it.

shard.policies.get(name: string): Promise<Policy>

Examples

const { rules, holders } = await shard.policies.get("api-only");

A Policy holds name, rules, holders (the sandboxes it is attached to) and dns (open or closed, whether the rules let the sandbox resolve names).

List network policies.

shard.policies.list(): Promise<Policy[]>

Examples

for (const policy of await shard.policies.list()) console.log(policy.name, policy.rules.length);

A listed policy leaves holders and dns null. Use get for them.

Delete an unused network policy.

shard.policies.remove(name: string): Promise<void>

Examples

await shard.policies.remove("api-only");

Detach the policy from its sandboxes before removal.

Assign a network policy to a sandbox.

shard.policies.attach(sandbox: SandboxRef, name: string): Promise<SandboxInfo>

Examples

await web.stop();
await shard.policies.attach(web, "api-only");
await web.start();

Arguments

Argument Description
sandbox a Sandbox, or its ID, ID prefix or name
name policy name

The sandbox must be created or stopped. The policy replaces any policy already assigned to the sandbox. To assign one at create time, pass policy to shard.create.

Remove a sandbox’s network policy.

shard.policies.detach(sandbox: SandboxRef): Promise<SandboxInfo>

Examples

await shard.policies.detach(web);

The sandbox must be created or stopped. Secret access remains unchanged. Without a policy, the sandbox can access the internet but not private networks.

Return the network decisions the daemon holds for a sandbox, oldest first.

sandbox.egressLog(): Promise<EgressDecision[]>

Examples

for (const d of await sandbox.egressLog()) console.log(d.verdict, d.host, d.port, d.ruleText);

An EgressDecision holds time, source (proxy, host or dns), verdict (allow or deny), host, port, address, reason, the ID of the rule that decided it in rule (or why none did, as default), and that rule as the CLI spells it (ruleText, or rule_text in Python).

sandbox.followEgressLog / follow_egress_log

Section titled “sandbox.followEgressLog / follow_egress_log”

Stream network decisions as they happen.

sandbox.followEgressLog(options?: { signal?: AbortSignal }): AsyncGenerator<EgressDecision>

Examples

for await (const d of sandbox.followEgressLog()) console.log(d.verdict, d.host);

The stream yields the newest decisions the daemon holds, then each new one as it happens, and ends when the sandbox stops. In TypeScript, an abort ends it. In Python, closing it ends it, and AsyncShard iterates it with async for.

For the whole flow, see Credential brokering.